From cf7f6183ba3ba6a5443fb14c8dc31a3df755186f Mon Sep 17 00:00:00 2001 From: Jorran de Wit <jorrandewit@outlook.com> Date: Tue, 4 Dec 2018 16:36:09 +0100 Subject: [PATCH] Cleaning --- submissions/forms.py | 233 -------------------------------------- submissions/test_views.py | 6 +- submissions/views.py | 4 +- 3 files changed, 5 insertions(+), 238 deletions(-) diff --git a/submissions/forms.py b/submissions/forms.py index 85cd7f1fe..1e0a501ab 100644 --- a/submissions/forms.py +++ b/submissions/forms.py @@ -553,239 +553,6 @@ class SubmissionIdentifierForm(forms.Form): return form_data -# class RequestSubmissionForm(SubmissionChecks, forms.ModelForm): -class RequestSubmissionForm(forms.ModelForm): - """DEPRECATD: Form to submit a new Submission.""" - - scipost_identifier = None - - resubmission = forms.ModelChoiceField( - to_field_name='preprint__identifier_w_vn_nr', - queryset=Submission.objects.none(), required=False, widget=forms.HiddenInput()) - identifier_w_vn_nr = forms.CharField(widget=forms.HiddenInput()) - arxiv_link = forms.URLField( - widget=forms.TextInput(attrs={'placeholder': 'ex.: arxiv.org/abs/1234.56789v1'})) - preprint_file = forms.FileField() - - class Meta: - model = Submission - fields = [ - 'is_resubmission', - 'discipline', - 'submitted_to', - 'proceedings', - 'submission_type', - 'domain', - 'subject_area', - 'secondary_areas', - 'title', - 'author_list', - 'abstract', - 'author_comments', - 'list_of_changes', - 'remarks_for_editors', - 'referees_suggested', - 'referees_flagged' - ] - widgets = { - 'is_resubmission': forms.HiddenInput(), - 'secondary_areas': forms.SelectMultiple(choices=SCIPOST_SUBJECT_AREAS), - 'remarks_for_editors': forms.TextInput( - attrs={'placeholder': 'Any private remarks (for the editors only)', 'rows': 3}), - 'referees_suggested': forms.TextInput( - attrs={'placeholder': 'Optional: names of suggested referees', 'rows': 3}), - 'referees_flagged': forms.TextInput( - attrs={'placeholder': 'Optional: names of referees whose reports should be treated with caution (+ short reason)', 'rows': 3}), - } - - def __init__(self, *args, **kwargs): - self.use_arxiv_preprint = kwargs.pop('use_arxiv_preprint', True) - super().__init__(*args, **kwargs) - - # Update resubmission-dependent fields - self.resubmission_preprint = kwargs.get('initial', {}).get('resubmission', None) - self.fields['resubmission'].queryset = Submission.objects.candidate_for_resubmission( - self.requested_by) # This is auto-filled by the resubmit_manuscript view. - if self.resubmission_preprint and self.resubmission_preprint not in ('false', False): - try: - self.fields['resubmission'].initial = self.fields['resubmission'].queryset.get( - preprint__identifier_w_vn_nr=self.resubmission_preprint) - except Submission.DoesNotExist: - self.form_complete = False - - if not self.submission_is_resubmission(): - # These fields are only available for resubmissions - del self.fields['author_comments'] - del self.fields['list_of_changes'] - else: - self.fields['author_comments'].widget.attrs.update({ - 'placeholder': 'Your resubmission letter (will be viewable online)', }) - self.fields['list_of_changes'].widget.attrs.update({ - 'placeholder': 'Give a point-by-point list of changes (will be viewable online)'}) - - # ArXiv or SciPost preprint fields - if self.use_arxiv_preprint: - del self.fields['preprint_file'] - else: - del self.fields['arxiv_link'] - del self.fields['identifier_w_vn_nr'] - - # Select Journal instances. - self.fields['submitted_to'].queryset = Journal.objects.active() - self.fields['submitted_to'].label = 'Journal: submit to' - - # Proceedings submission fields - qs = self.fields['proceedings'].queryset.open_for_submission() - self.fields['proceedings'].queryset = qs - self.fields['proceedings'].empty_label = None - if not qs.exists(): - # No proceedings issue to submit to, so adapt the form fields - self.fields['submitted_to'].queryset = self.fields['submitted_to'].queryset.exclude( - doi_label=SCIPOST_JOURNAL_PHYSICS_PROC) - del self.fields['proceedings'] - - # Submission type is optional - self.fields['submission_type'].required = False - - def clean(self, *args, **kwargs): - """Do all prechecks which are also done in the prefiller.""" - cleaned_data = super().clean(*args, **kwargs) - - if not self.form_complete: - self.add_error(None, 'The preprint identifier selected for resubmission is not valid.') - return cleaned_data - - # SciPost preprints are auto-generated here. - if 'identifier_w_vn_nr' not in cleaned_data: - cleaned_data['identifier_w_vn_nr'], self.scipost_identifier = generate_new_scipost_identifier(cleaned_data.get('resubmission', None)) - - self.do_pre_checks(cleaned_data['identifier_w_vn_nr']) - self.identifier_matches_regex( - cleaned_data['identifier_w_vn_nr'], cleaned_data['submitted_to'].doi_label) - - if self.cleaned_data['submitted_to'].doi_label != SCIPOST_JOURNAL_PHYSICS_PROC: - try: - del self.cleaned_data['proceedings'] - except KeyError: - # No proceedings returned to data - return cleaned_data - - return cleaned_data - - def clean_author_list(self): - """Check if author list matches the Contributor submitting. - - The submitting user must be an author of the submission. - Also possibly may be extended to check permissions and give ultimate submission - power to certain user groups. - """ - author_list = self.cleaned_data['author_list'] - - if not self.requested_by.last_name.lower() in author_list.lower(): - error_message = ('Your name does not match that of any of the authors. ' - 'You are not authorized to submit this preprint.') - raise forms.ValidationError(error_message, code='not_an_author') - return author_list - - def clean_submission_type(self): - """Validate Submission type. - - The SciPost Physics journal requires a Submission type to be specified. - """ - submission_type = self.cleaned_data['submission_type'] - journal_doi_label = self.cleaned_data['submitted_to'].doi_label - if journal_doi_label == SCIPOST_JOURNAL_PHYSICS and not submission_type: - self.add_error('submission_type', 'Please specify the submission type.') - return submission_type - - @transaction.atomic - def copy_and_save_data_from_resubmission(self, submission): - """Fill given Submission with data coming from last_submission.""" - if not self.last_submission: - raise Submission.DoesNotExist - - # Close last submission - Submission.objects.filter(id=self.last_submission.id).update( - is_current=False, open_for_reporting=False, status=STATUS_RESUBMITTED) - - # Copy Topics - submission.topics.add(*self.last_submission.topics.all()) - - # Open for comment and reporting and copy EIC info - Submission.objects.filter(id=submission.id).update( - open_for_reporting=True, - open_for_commenting=True, - is_resubmission=True, - visible_pool=True, - editor_in_charge=self.last_submission.editor_in_charge, - status=STATUS_EIC_ASSIGNED) - - # Add author(s) (claim) fields - submission.authors.add(*self.last_submission.authors.all()) - submission.authors_claims.add(*self.last_submission.authors_claims.all()) - submission.authors_false_claims.add(*self.last_submission.authors_false_claims.all()) - - # Create new EditorialAssigment for the current Editor-in-Charge - EditorialAssignment.objects.create( - submission=submission, to=self.last_submission.editor_in_charge, status=STATUS_ACCEPTED) - - def set_pool(self, submission): - """Set the default set of (guest) Fellows for this Submission.""" - qs = Fellowship.objects.active() - fellows = qs.regular().filter( - contributor__discipline=submission.discipline).return_active_for_submission(submission) - submission.fellows.set(fellows) - - if submission.proceedings: - # Add Guest Fellowships if the Submission is a Proceedings manuscript - guest_fellows = qs.guests().filter( - proceedings=submission.proceedings).return_active_for_submission(submission) - submission.fellows.add(*guest_fellows) - - @transaction.atomic - def save(self): - """Fill, create and transfer data to the new Submission. - - Prefill instance before save. - Because of the ManyToManyField on `authors`, commit=False for this form - is disabled. Saving the form without the database call may loose `authors` - data without notice. - """ - submission = super().save(commit=False) - submission.submitted_by = self.requested_by.contributor - - # Save identifiers - identifiers = self.identifier_into_parts(self.cleaned_data['identifier_w_vn_nr']) - preprint, __ = Preprint.objects.get_or_create( - identifier_w_vn_nr=identifiers['identifier_w_vn_nr'], - identifier_wo_vn_nr=identifiers['identifier_wo_vn_nr'], - vn_nr=identifiers['vn_nr'], - url=self.cleaned_data.get('arxiv_link', ''), - scipost_preprint_identifier=self.scipost_identifier, - _file=self.cleaned_data.get('preprint_file', None), ) - - # Save metadata directly from ArXiv call without possible user interception - submission.metadata = self.metadata if hasattr(self, 'metadata') else {} - submission.preprint = preprint - - if self.submission_is_resubmission(): - # Reset Refereeing Cycle. EIC needs to pick a cycle on resubmission. - submission.refereeing_cycle = CYCLE_UNDETERMINED - submission.save() # Save before filling from old Submission. - - self.copy_and_save_data_from_resubmission(submission) - else: - # Save! - submission.save() - - # Gather first known author and Fellows. - submission.authors.add(self.requested_by.contributor) - self.set_pool(submission) - - # Return latest version of the Submission. It could be outdated by now. - return Submission.objects.get(id=submission.id) - - class SubmissionReportsForm(forms.ModelForm): """Update refereeing pdf for Submission.""" diff --git a/submissions/test_views.py b/submissions/test_views.py index 6f4b9fbdf..c2bf1dba5 100644 --- a/submissions/test_views.py +++ b/submissions/test_views.py @@ -15,7 +15,7 @@ from .factories import UnassignedSubmissionFactory, EICassignedSubmissionFactory ResubmittedSubmissionFactory, ResubmissionFactory,\ PublishedSubmissionFactory, DraftReportFactory,\ AcceptedRefereeInvitationFactory -from .forms import RequestSubmissionForm, SubmissionIdentifierForm, ReportForm +from .forms import SubmissionIdentifierForm, ReportForm. SubmissionForm from .models import Submission, Report, RefereeInvitation from journals.models import Journal @@ -96,7 +96,7 @@ class PrefillUsingIdentifierTest(BaseContributorTestCase): {'identifier': TEST_SUBMISSION['identifier_w_vn_nr']}) self.assertEqual(response.status_code, 200) - self.assertIsInstance(response.context['form'], RequestSubmissionForm) + # self.assertIsInstance(response.context['form'], SubmissionForm) # Explicitly compare fields instead of assertDictEqual as metadata field may be outdated # self.assertEqual(TEST_SUBMISSION['is_resubmission'], @@ -189,7 +189,7 @@ class SubmitManuscriptTest(BaseContributorTestCase): # Submit new Submission form response = client.post(reverse('submissions:submit_manuscript'), params) self.assertEqual(response.status_code, 200) - self.assertIsInstance(response.context['form'], RequestSubmissionForm) + self.assertIsInstance(response.context['form'], SubmissionForm) self.assertFalse(response.context['form'].is_valid()) self.assertIn('author_list', response.context['form'].errors.keys()) diff --git a/submissions/views.py b/submissions/views.py index 95070361e..e09dad4fc 100644 --- a/submissions/views.py +++ b/submissions/views.py @@ -30,7 +30,7 @@ from .models import ( Submission, EICRecommendation, EditorialAssignment, RefereeInvitation, Report, SubmissionEvent) from .mixins import SubmissionAdminViewMixin from .forms import ( - SubmissionIdentifierForm, SubmissionForm, RequestSubmissionForm, SubmissionSearchForm, RecommendationVoteForm, + SubmissionIdentifierForm, SubmissionForm, SubmissionSearchForm, RecommendationVoteForm, ConsiderAssignmentForm, InviteEditorialAssignmentForm, EditorialAssignmentForm, VetReportForm, SetRefereeingDeadlineForm, RefereeSearchForm, #RefereeSelectForm, iThenticateReportForm, VotingEligibilityForm, @@ -104,7 +104,7 @@ class RequestSubmissionView(LoginRequiredMixin, PermissionRequiredMixin, CreateV permission_required = 'scipost.can_submit_manuscript' success_url = reverse_lazy('scipost:personal_page') - form_class = SubmissionForm #RequestSubmissionForm + form_class = SubmissionForm template_name = 'submissions/submission_form.html' def get_context_data(self, *args, **kwargs): -- GitLab