From e62e637c92d1043044d4a26fb8127479bc39e910 Mon Sep 17 00:00:00 2001 From: "J.-S. Caux" <J.S.Caux@uva.nl> Date: Sat, 18 Jul 2020 22:05:20 +0200 Subject: [PATCH] Partial work (experimenting) --- submissions/forms.py | 288 +++++++++++++----- .../submissions/submit_choose_journal.html | 8 +- .../submit_choose_preprint_server.html | 33 +- .../submissions/submit_manuscript.html | 2 +- submissions/urls.py | 33 +- submissions/views.py | 107 ++++--- 6 files changed, 306 insertions(+), 165 deletions(-) diff --git a/submissions/forms.py b/submissions/forms.py index efa75356d..742330373 100644 --- a/submissions/forms.py +++ b/submissions/forms.py @@ -29,7 +29,8 @@ from .constants import ( from . import exceptions, helpers from .helpers import to_ascii_only from .models import ( - Submission, RefereeInvitation, Report, EICRecommendation, EditorialAssignment, + Submission, PreprintServer, + RefereeInvitation, Report, EICRecommendation, EditorialAssignment, SubmissionTiering, EditorialDecision, iThenticateReport, EditorialCommunication) @@ -124,29 +125,6 @@ class SubmissionService: else: self.latest_submission = None - # @property - # def latest_submission(self): - # """ - # Return latest version of preprint series or None. - # """ - # if hasattr(self, '_latest_submission'): - # return self._latest_submission - - # # if self.identifier: - # # # Check if is resubmission when identifier data is submitted. - # # identifier = self.identifier.rpartition('v')[0] - # # self._latest_submission = Submission.objects.filter( - # # preprint__identifier_wo_vn_nr=identifier).order_by( - # # '-preprint__vn_nr').first() - # if self.thread_hash: - # # Resubmission - # self._latest_submission = Submission.objects.filter( - # thread_hash=self.thread_hash).order_by( - # '-submission_date', '-preprint__vn_nr').first() - # else: - # self._latest_submission = None - # return self._latest_submission - @property def arxiv_data(self): if self._arxiv_data is None: @@ -201,7 +179,7 @@ class SubmissionService: 'referees_suggested': self.latest_submission.referees_suggested, 'secondary_areas': self.latest_submission.secondary_areas, 'subject_area': self.latest_submission.subject_area, - 'submitted_to': self.latest_submission.submitted_to, + 'submitted_to': self.latest_submission.submitted_to, # TODO: change to thread_hash 'submission_type': self.latest_submission.submission_type, 'thread_hash': self.latest_submission.thread_hash, } @@ -234,7 +212,7 @@ class SubmissionService: ' any further questions.') raise forms.ValidationError(error_message, code='submitted_to') - def process_resubmission_procedure(self, submission): + def process_resubmission_procedure(self, submission): # Belongs to SubmissionForm """ Update all fields for new and old Submission and EditorialAssignments to comply with the resubmission procedures. @@ -330,11 +308,211 @@ class SubmissionService: params={'published_id': published_id}) +# class SubmissionPrefillForm(forms.Form): # Does not work: cannot display differently +# """ +# Provide initial data for SubmissionForm. +# """ +# journal = forms.ModelChoiceField( +# queryset=Journal.objects.submission_allowed(), +# widget=forms.HiddenInput() +# ) +# thread_hash = forms.UUIDField( +# required=False, +# widget=forms.HiddenInput() +# ) +# preprint_server = forms.ModelChoiceField( +# queryset=PreprintServer.objects.all(), +# widget=forms.HiddenInput() +# ) +# identifier_w_vn_nr = forms.CharField( +# required=False +# ) + + + + +###################################################################### +# +# SubmissionForm prefill facilities. One class per integrated server. +# +###################################################################### + + +class SubmissionPrefillForm(forms.Form): + """ + Base class for all SubmissionPrefillForms (one per integrated preprint servers). + + Based on kwargs `requested_by`, `journal_doi_label` and `thread_hash`, + this prepares initial data for SubmissionForm. + """ + def __init__(self, *args, **kwargs): + self.preprint_server = None + self.requested_by = kwargs.pop('requested_by') + self.journal = Journal.objects.get(doi_label=kwargs.pop('journal_doi_label')) + self.thread_hash = kwargs.pop('thread_hash') + + if self.thread_hash: + # Resubmission + self.latest_submission = Submission.objects.filter( + thread_hash=self.thread_hash).order_by( + '-submission_date', '-preprint__vn_nr').first() + else: + self.latest_submission = None + super().__init__(*args, **kwargs) + + def is_resubmission(self): + return self.latest_submission is not None + + def run_checks(self): + """ + Consistency checks on the prefill data. + """ + self._check_resubmission_readiness() + + def _check_resubmission_readiness(self): + """ + Check if previous submitted versions (if any) can be resubmitted. + """ + if self.latest_submission: + if self.latest_submission.status == STATUS_REJECTED: + # Explicitly give rejected status warning. + error_message = ('This preprint has previously undergone refereeing ' + 'and has been rejected. Resubmission is only possible ' + 'if the manuscript has been substantially reworked into ' + 'a new submission with distinct identifier.') + raise forms.ValidationError(error_message) + elif self.latest_submission.open_for_resubmission: + # Check if verified author list contains current user. + if self.requested_by.contributor not in self.latest_submission.authors.all(): + error_message = ('There exists a preprint with this identifier ' + 'but an earlier version number. Resubmission is only possible' + ' if you are a registered author of this manuscript.') + raise forms.ValidationError(error_message) + else: + # Submission has not an appropriate status for resubmission. + error_message = ('There exists a preprint with this identifier ' + 'but an earlier version number, which is still undergoing ' + 'peer refereeing. ' + 'A resubmission can only be performed after request ' + 'from the Editor-in-charge. Please wait until the ' + 'closing of the previous refereeing round and ' + 'formulation of the Editorial Recommendation ' + 'before proceeding with a resubmission.') + raise forms.ValidationError(error_message) + + def get_prefill_data(self): + return {} + + +class SciPostPrefillForm(SubmissionPrefillForm): + """ + Provide initial data for SubmissionForm (SciPost preprint server route). + """ + + def __init__(self, *args, **kwargs): + self.preprint_server = 'SciPost' + super().__init__(*args, **kwargs) + + def is_valid(self): + """ + Accept an empty form as valid. Override Django BaseForm.is_valid + + Django BaseForm method requires is_bound == True and not self.errors. + is_bound requires data is not None. + We thus override is_valid by cutting the is_bound == True out. + """ + return not self.errors + + def get_prefill_data(self): + """ + Return initial form data originating from earlier Submission. + """ + if self.is_resubmission(): + return { + 'title': self.latest_submission.title, + 'abstract': self.latest_submission.abstract, + 'author_list': self.latest_submission.author_list, + 'discipline': self.latest_submission.discipline, + 'approaches': self.latest_submission.approaches, + 'referees_flagged': self.latest_submission.referees_flagged, + 'referees_suggested': self.latest_submission.referees_suggested, + 'secondary_areas': self.latest_submission.secondary_areas, + 'subject_area': self.latest_submission.subject_area, + 'submitted_to': self.journal, + 'submission_type': self.latest_submission.submission_type, + 'thread_hash': self.latest_submission.thread_hash, + } + return {} + + +class ArXivPrefillForm(SubmissionPrefillForm): + """ + Provide initial data for SubmissionForm (arXiv preprint server route). + + This adds the `arxiv_identifier_w_vn_nr` kwarg to those from `SubmissionPrefillForm` base class. + """ + arxiv_identifier_w_vn_nr = forms.RegexField( + label='', + regex=ARXIV_IDENTIFIER_PATTERN_NEW, strip=True, + error_messages={'invalid': strings.arxiv_query_invalid}, + widget=forms.TextInput() + ) + + def __init__(self, *args, **kwargs): + self.preprint_server = 'arXiv' + super().__init__(*args, **kwargs) + + def run_checks(self): + super().run_checks() + # TODO: add others here like self._check_if_already_published() + + def clean_arxiv_identifier_w_vn_nr(self): + """ + Do basic prechecks based on the arXiv ID only. + """ + identifier = self.cleaned_data.get('arxiv_identifier_w_vn_nr', None) + + self.service = SubmissionService( + self.requested_by, 'arxiv', + identifier=identifier, thread_hash=self.thread_hash) + self.service.run_checks() + return identifier + + def get_prefill_data(self): + """ + Return dictionary to prefill `SubmissionForm`. + """ + form_data = self.service.arxiv_data + form_data['identifier_w_vn_nr'] = self.cleaned_data['identifier_w_vn_nr'] + if self.service.is_resubmission(): + form_data.update({ + 'discipline': self.service.latest_submission.discipline, + 'approaches': self.service.latest_submission.approaches, + 'referees_flagged': self.service.latest_submission.referees_flagged, + 'referees_suggested': self.service.latest_submission.referees_suggested, + 'secondary_areas': self.service.latest_submission.secondary_areas, + 'subject_area': self.service.latest_submission.subject_area, + 'submitted_to': self.journal, + 'submission_type': self.service.latest_submission.submission_type, + 'thread_hash': self.service.latest_submission.thread_hash + }) + return form_data + + +################## +# +# Submission form +# +################## + class SubmissionForm(forms.ModelForm): """ Form to submit a new (re)Submission. """ - thread_hash = forms.UUIDField(required=False) + thread_hash = forms.UUIDField( + required=False, + widget=forms.HiddenInput() + ) identifier_w_vn_nr = forms.CharField(widget=forms.HiddenInput()) preprint_file = forms.FileField( help_text=('Please submit the processed .pdf (not the source files; ' @@ -382,6 +560,7 @@ class SubmissionForm(forms.ModelForm): } def __init__(self, *args, **kwargs): + print("form kwargs['initial']: %s" % kwargs['initial']) self.requested_by = kwargs.pop('requested_by') self.preprint_server = kwargs.pop('preprint_server', 'arxiv') @@ -393,8 +572,8 @@ class SubmissionForm(forms.ModelForm): self.requested_by, self.preprint_server, identifier=identifier, thread_hash=thread_hash) - if self.preprint_server == 'scipost': - kwargs['initial'] = self.service.get_latest_submission_data() + # if self.preprint_server == 'scipost': + # kwargs['initial'] = self.service.get_latest_submission_data() super().__init__(*args, **kwargs) @@ -545,57 +724,6 @@ class SubmissionForm(forms.ModelForm): return submission -class ArXivPrefillForm(forms.Form): - """ - Prefill SubmissionForm using an arXiv identifier with version nr. - """ - - identifier_w_vn_nr = forms.RegexField( - label='', - regex=ARXIV_IDENTIFIER_PATTERN_NEW, strip=True, - error_messages={'invalid': strings.arxiv_query_invalid}, - widget=forms.TextInput() - ) - - def __init__(self, *args, **kwargs): - self.requested_by = kwargs.pop('requested_by') - self.thread_hash = kwargs.pop('thread_hash') - self.journal = Journal.objects.get(doi_label=kwargs.pop('journal_doi_label')) - return super().__init__(*args, **kwargs) - - def clean_identifier_w_vn_nr(self): - """ - Do basic prechecks based on the arXiv ID only. - """ - identifier = self.cleaned_data.get('identifier_w_vn_nr', None) - - self.service = SubmissionService( - self.requested_by, 'arxiv', - identifier=identifier, thread_hash=self.thread_hash) - self.service.run_checks() - return identifier - - def get_initial_submission_data(self): - """ - Return dictionary to prefill `SubmissionForm`. - """ - form_data = self.service.arxiv_data - form_data['identifier_w_vn_nr'] = self.cleaned_data['identifier_w_vn_nr'] - if self.service.is_resubmission(): - form_data.update({ - 'discipline': self.service.latest_submission.discipline, - 'approaches': self.service.latest_submission.approaches, - 'referees_flagged': self.service.latest_submission.referees_flagged, - 'referees_suggested': self.service.latest_submission.referees_suggested, - 'secondary_areas': self.service.latest_submission.secondary_areas, - 'subject_area': self.service.latest_submission.subject_area, - 'submitted_to': self.journal, - 'submission_type': self.service.latest_submission.submission_type, - 'thread_hash': self.service.latest_submission.thread_hash - }) - return form_data - - class SubmissionReportsForm(forms.ModelForm): """Update refereeing pdf for Submission.""" diff --git a/submissions/templates/submissions/submit_choose_journal.html b/submissions/templates/submissions/submit_choose_journal.html index de75e388c..d61f23dfc 100644 --- a/submissions/templates/submissions/submit_choose_journal.html +++ b/submissions/templates/submissions/submit_choose_journal.html @@ -39,7 +39,7 @@ {% if perms.scipost.can_submit_manuscript %} - <h2>Which Journal do you wish to submit to?</h2> + <h2>Which Journal do you wish to {% if thread_hash %}send your resubmission{% else %}submit{% endif %} to?</h2> <br> <div class="card-columns"> {% for journal in journals %} @@ -53,11 +53,7 @@ </div> <div class="card-body"> <a class="btn btn-outline-primary m-2" role="button" href="{{ journal.get_absolute_url }}/about" target="_blank"><em>View Description, Scope, Content and Acceptance Criteria</em></a> - {% if thread_hash %} - <a class="btn btn-primary m-2" role="button" href="{% url 'submissions:submit_choose_preprint_server' journal_doi_label=journal.doi_label thread_hash=thread_hash %}"><i class="fa fa-arrow-right"></i> Submit to {{ journal.name }}</a> - {% else %} - <a class="btn btn-primary m-2" role="button" href="{% url 'submissions:submit_choose_preprint_server' journal_doi_label=journal.doi_label %}"><i class="fa fa-arrow-right"></i> Submit to {{ journal.name }}</a> - {% endif %} + <a class="btn btn-primary m-2" role="button" href="{% url 'submissions:submit_choose_preprint_server' journal_doi_label=journal.doi_label %}{% if thread_hash %}?thread_hash={{ thread_hash }}{% endif %}"><i class="fa fa-arrow-right"></i> Submit to {{ journal.name }}</a> </div> </div> {% endfor %} diff --git a/submissions/templates/submissions/submit_choose_preprint_server.html b/submissions/templates/submissions/submit_choose_preprint_server.html index 1e558a37b..2c3a16c21 100644 --- a/submissions/templates/submissions/submit_choose_preprint_server.html +++ b/submissions/templates/submissions/submit_choose_preprint_server.html @@ -36,34 +36,37 @@ {% if perms.scipost.can_submit_manuscript %} {% if preprint_servers|length > 1 %} - <h2>Which preprint server do you wish to use?</h2> + <h2>Which preprint server do you wish to use for your {% if thread_hash %}re{% endif %}submission?</h2> {% else %} - <h2>TODO: proceed directly, only SciPost server is available</h2> + <h2>Please proceed with the SciPost preprint server (others are not available)</h2> {% endif %} <br> <div class="card-columns"> {% for server in preprint_servers %} <div class="card"> <div class="card-header"> - <h3>Submit via {{ server }}</h3> + <h3>{% if thread_hash %}Resubmit{% else %}Submit{% endif %} via {{ server }}</h3> </div> <div class="card-body"> {% if server.name == 'SciPost' %} - {% if thread_hash %} - <a class="btn btn-success text-white" role="button" href="{% url 'submissions:submit_manuscript_scipost' journal_doi_label=journal.doi_label thread_hash=thread_hash %}"><i class="fa fa-arrow-right"></i> Go to the SciPost submission form</a> - {% else %} - <a class="btn btn-success text-white" role="button" href="{% url 'submissions:submit_manuscript_scipost' journal_doi_label=journal.doi_label %}"><i class="fa fa-arrow-right"></i> Go to the SciPost submission form</a> - {% endif %} + <a class="btn btn-success text-white" role="button" href="{% url 'submissions:submit_manuscript_scipost' journal_doi_label=journal.doi_label %}{% if thread_hash %}?thread_hash={{ thread_hash }}{% endif %}"><i class="fa fa-arrow-right"></i> Go to the SciPost submission form</a> + <form action="{% url 'submissions:submit_manuscript_scipost' journal_doi_label=journal.doi_label %}" method="get"> + {{ scipost_prefill_form }} + {% if thread_hash %} + <input type="hidden" name="thread_hash" value="{{ thread_hash }}"/> + {% endif %} + <i class="fa fa-arrow-right"></i> + <input type="submit" class="btn btn-success text-white" value="Go to the SciPost submission form"/> + </form> {% elif server.name == 'arXiv' %} <h3>arXiv identifier for your Submission</h3> <p><em>Give the identifier without prefix but with version number, ####.####(#)v#(#)</em></p> - {% if thread_hash %} - <form action="{% url 'submissions:submit_manuscript_arxiv' journal_doi_label=journal.doi_label thread_hash=thread_hash %}" method="get"> - {% else %} - <form action="{% url 'submissions:submit_manuscript_arxiv' journal_doi_label=journal.doi_label %}" method="get"> - {% endif %} - {{ arxiv_query_form }} - <i class="fa fa-arrow-right"></i> + <form action="{% url 'submissions:submit_manuscript_arxiv' journal_doi_label=journal.doi_label %}" method="get"> + {{ arxiv_prefill_form }} + {% if thread_hash %} + <input type="hidden" name="thread_hash" value="{{ thread_hash }}"/> + {% endif %} + <i class="fa fa-arrow-right"></i> <input type="submit" class="btn btn-success text-white" value="Query arXiv"/> </form> {% endif %} diff --git a/submissions/templates/submissions/submit_manuscript.html b/submissions/templates/submissions/submit_manuscript.html index d4c1a8959..9e19d9f5e 100644 --- a/submissions/templates/submissions/submit_manuscript.html +++ b/submissions/templates/submissions/submit_manuscript.html @@ -55,7 +55,7 @@ {% if not submission.open_for_resubmission %} <strong class="text-warning">This submission is still undergoing peer refereeing. Please wait until the closing of the previous refereeing round and formulation of the Editorial Recommendation before proceeding with a resubmission.</strong> {% else %} - <a class="btn btn-outline-primary p-1 mt-0" role="button" href="{% url 'submissions:submit_choose_journal' discipline=submission.discipline thread_hash=submission.thread_hash %}"><i class="fa fa-arrow-right"></i> Resubmit</a> + <a class="btn btn-outline-primary p-1 mt-0" role="button" href="{% url 'submissions:submit_choose_journal' discipline=submission.discipline %}?thread_hash={{ submission.thread_hash }}"><i class="fa fa-arrow-right"></i> Resubmit</a> {% endif %} </li> {% endfor %} diff --git a/submissions/urls.py b/submissions/urls.py index d6f13fdd3..1a1faeec1 100644 --- a/submissions/urls.py +++ b/submissions/urls.py @@ -128,53 +128,36 @@ urlpatterns = [ url(r'^admin/reports/(?P<report_id>[0-9]+)/compile$', views.report_pdf_compile, name='report_pdf_compile'), + # Submission, resubmission, withdrawal - path( # Start a new submission process; choose between resubmission or new submission + + path( # Start a new submission process; choose resub or new sub (with field choice) 'submit_manuscript', views.submit_manuscript, name='submit_manuscript' ), - path( # Choose journal + path( # Choose journal (thread_hash as GET param if resubmission) 'submit/<discipline:discipline>', views.submit_choose_journal, name='submit_choose_journal' ), - path( # Choose journal (resubmission) - 'submit/<discipline:discipline>/<uuid:thread_hash>', - views.submit_choose_journal, - name='submit_choose_journal' - ), - path( # Choose preprint server + path( # Choose preprint server (thread_hash as GET param if resubmission) 'submit/<journal_doi_label:journal_doi_label>', views.submit_choose_preprint_server, name='submit_choose_preprint_server' ), - path( # Choose preprint server (resubmission) - 'submit/<journal_doi_label:journal_doi_label>/<uuid:thread_hash>', - views.submit_choose_preprint_server, - name='submit_choose_preprint_server' - ), - path( # Submit using the SciPost preprint server (new submission) + path( # Submit using the SciPost preprint server (thread_hash as GET param if resubmission) 'submit_manuscript/<journal_doi_label:journal_doi_label>/scipost', views.RequestSubmissionUsingSciPostView.as_view(), name='submit_manuscript_scipost' ), - path( # Submit using the SciPost preprint server (resubmission) - 'submit_manuscript/<journal_doi_label:journal_doi_label>/scipost/<uuid:thread_hash>', - views.RequestSubmissionUsingSciPostView.as_view(), - name='submit_manuscript_scipost' - ), - path( # Submit or resubmit using arXiv + path( # Submit using arXiv (thread_hash as GET param if resubmission) 'submit_manuscript/<journal_doi_label:journal_doi_label>/arxiv', views.RequestSubmissionUsingArXivView.as_view(), name='submit_manuscript_arxiv' ), - path( # Submit or resubmit using arXiv (resubmission) - 'submit_manuscript/<journal_doi_label:journal_doi_label>/arxiv/<uuid:thread_hash>', - views.RequestSubmissionUsingArXivView.as_view(), - name='submit_manuscript_arxiv' - ), + url( # Redirects to the appropriate Submit page, prefilling form r'^resubmit_manuscript/{regex}$'.format(regex=SUBMISSIONS_COMPLETE_REGEX), views.resubmit_manuscript, diff --git a/submissions/views.py b/submissions/views.py index c9098fb8a..61d5d9ac3 100644 --- a/submissions/views.py +++ b/submissions/views.py @@ -40,7 +40,8 @@ from .models import ( EditorialAssignment, RefereeInvitation, Report, SubmissionEvent) from .mixins import SubmissionMixin, SubmissionAdminViewMixin from .forms import ( - ArXivPrefillForm, SubmissionForm, SubmissionSearchForm, RecommendationVoteForm, + ArXivPrefillForm, SciPostPrefillForm, + SubmissionForm, SubmissionSearchForm, RecommendationVoteForm, ConsiderAssignmentForm, InviteEditorialAssignmentForm, EditorialAssignmentForm, VetReportForm, SetRefereeingDeadlineForm, RefereeSearchForm, iThenticateReportForm, VotingEligibilityForm, WithdrawSubmissionForm, @@ -134,32 +135,42 @@ def submit_manuscript(request): @login_required @permission_required('scipost.can_submit_manuscript', raise_exception=True) -def submit_choose_journal(request, discipline=None, thread_hash=None): +def submit_choose_journal(request, discipline=None): + """ + Choose a Journal. If `thread_hash` is given as GET parameter, this is a resubmission. + """ journals = Journal.objects.submission_allowed() if discipline: journals = journals.filter(discipline=discipline) context = { 'journals': journals, } - if thread_hash: - context['thread_hash'] = thread_hash + if request.GET.get('thread_hash'): + context['thread_hash'] = request.GET.get('thread_hash') return render(request, 'submissions/submit_choose_journal.html', context) @login_required @permission_required('scipost.can_submit_manuscript', raise_exception=True) -def submit_choose_preprint_server(request, journal_doi_label, thread_hash=None): +def submit_choose_preprint_server(request, journal_doi_label): + """ + Choose a preprint server. If `thread_hash` is given as a GET parameter, this is a resubmission. + """ journal = get_object_or_404(Journal, doi_label=journal_doi_label) preprint_servers = PreprintServer.objects.filter(disciplines__contains=[journal.discipline]) - arxiv_query_form = ArXivPrefillForm( - requested_by=request.user, thread_hash=thread_hash, journal_doi_label=journal_doi_label) + thread_hash = request.GET.get('thread_hash') or None + # Each integrated preprint server has a prefill form: + scipost_prefill_form = SciPostPrefillForm( + requested_by=request.user, journal_doi_label=journal_doi_label, thread_hash=thread_hash) + arxiv_prefill_form = ArXivPrefillForm( + requested_by=request.user, journal_doi_label=journal_doi_label, thread_hash=thread_hash) context = { 'journal': journal, + 'thread_hash': thread_hash, 'preprint_servers': preprint_servers, - 'arxiv_query_form': arxiv_query_form, + 'scipost_prefill_form': scipost_prefill_form, + 'arxiv_prefill_form': arxiv_prefill_form, } - if thread_hash: - context['thread_hash'] = thread_hash return render(request, 'submissions/submit_choose_preprint_server.html', context) @@ -204,6 +215,42 @@ class RequestSubmissionView(LoginRequiredMixin, PermissionRequiredMixin, CreateV form_class = SubmissionForm template_name = 'submissions/submission_form.html' + def __init__(self, **kwargs): + self.prefill_form = None + self.initial_data = {} + super().__init__(**kwargs) + + def get(self, request, journal_doi_label): + """ + Redirect to `submit_choose_preprint_server` if arXiv identifier is not known. + """ + if self.prefill_form.is_valid(): + if self.prefill_form.is_resubmission(): + resubmessage = ('An earlier preprint was found within this submission thread.' + '\nYour Submission will thus be handled as a resubmission.' + '\nWe have pre-filled the form where possible. ' + 'Please check everything carefully!') + messages.success(request, resubmessage, fail_silently=True) + else: + if self.prefill_form.preprint_server == 'arXiv': + readymessage = ('We have pre-filled the form where possible. ' + 'Please check everything carefully!') + else: + readymessage = 'Your submission form is now ready to be filled in.' + messages.success(request, readymessage, fail_silently=True) + # Gather data from ArXiv API if prefill form is valid + self.initial_data = self.prefill_form.get_prefill_data() + print("initial data: %s" % self.initial_data) + return super().get(request) + else: + for code, err in self.prefill_form.errors.items(): + messages.warning(request, err[0]) + kwargs = { 'journal_doi_label': journal_doi_label } + redirect_url = reverse('submissions:submit_choose_preprint_server', kwargs=kwargs) + if request.GET.get('thread_hash'): + redirect_url += '?thread_hash=%s' % request.GET.get('thread_hash') + return redirect(redirect_url) + def get_context_data(self, *args, **kwargs): context = super().get_context_data(*args, **kwargs) context['id_SciPostPhys'] = get_object_or_404(Journal, doi_label='SciPostPhys').id @@ -251,35 +298,15 @@ class RequestSubmissionView(LoginRequiredMixin, PermissionRequiredMixin, CreateV class RequestSubmissionUsingArXivView(RequestSubmissionView): """Formview to submit a new Submission using arXiv.""" - def get(self, request, journal_doi_label, thread_hash=None): + def get(self, request, journal_doi_label): """ - Redirect to the arXiv prefill form if arXiv ID is not known. + Redirect to `submit_choose_preprint_server` if arXiv identifier is not known. """ - form = ArXivPrefillForm( - request.GET or None, + self.prefill_form = ArXivPrefillForm( + request.GET or None, # identifier_w_vn_nr, [thread_hash] requested_by=self.request.user, - journal_doi_label=journal_doi_label, - thread_hash=thread_hash) - if form.is_valid(): - if form.service.is_resubmission(): - resubmessage = ('An earlier preprint was found within this submission thread.' - '\nYour Submission will be handled as a resubmission.') - messages.success(request, resubmessage, fail_silently=True) - else: - messages.success(request, strings.acknowledge_arxiv_query, fail_silently=True) - # Gather data from ArXiv API if prefill form is valid - self.initial_data = form.get_initial_submission_data() - return super().get(request) - else: - for code, err in form.errors.items(): - messages.warning(request, err[0]) - kwargs = { 'journal_doi_label': journal_doi_label } - if thread_hash: - kwargs['thread_hash'] = thread_hash - return redirect( - 'submissions:submit_choose_preprint_server', - **kwargs - ) + journal_doi_label=journal_doi_label) + return super().get(request, journal_doi_label) def get_form_kwargs(self): """Form requires extra kwargs.""" @@ -291,8 +318,12 @@ class RequestSubmissionUsingArXivView(RequestSubmissionView): class RequestSubmissionUsingSciPostView(RequestSubmissionView): """Formview to submit a new Submission using SciPost's preprint server.""" - def get(self, request, journal_doi_label, thread_hash=None): - return super().get(request) + def get(self, request, journal_doi_label): + self.prefill_form = SciPostPrefillForm( + requested_by=self.request.user, + journal_doi_label=journal_doi_label, + thread_hash=request.GET.get('thread_hash')) + return super().get(request, journal_doi_label) def get_form_kwargs(self): """Form requires extra kwargs.""" -- GitLab