From a85542388fd652cbc08203670c4bd382036b293e Mon Sep 17 00:00:00 2001 From: Benjamin Moody Date: Fri, 28 Jul 2023 17:30:38 -0400 Subject: [PATCH] Use symbolic names for SubmissionStatus. --- physionet-django/console/forms.py | 9 +++-- .../console/submission_info_card.html | 2 +- physionet-django/console/test_views.py | 5 ++- physionet-django/console/views.py | 39 ++++++++++--------- .../management/commands/list_projects.py | 6 +-- .../project/modelcomponents/activeproject.py | 36 ++++++++--------- .../project/active_submission_timeline.html | 10 ++--- .../templates/project/project_home.html | 2 +- physionet-django/project/views.py | 15 +++---- 9 files changed, 64 insertions(+), 60 deletions(-) diff --git a/physionet-django/console/forms.py b/physionet-django/console/forms.py index 74f86d7923..b72ea0e5b9 100644 --- a/physionet-django/console/forms.py +++ b/physionet-django/console/forms.py @@ -27,6 +27,7 @@ PublishedAffiliation, PublishedAuthor, PublishedProject, + SubmissionStatus, exists_project_slug, ) from project.projectfiles import ProjectFiles @@ -93,7 +94,7 @@ def __init__(self, *args, **kwargs): def clean_project(self): pid = self.cleaned_data['project'] validate_integer(pid) - if ActiveProject.objects.get(id=pid) not in ActiveProject.objects.filter(submission_status=10): + if ActiveProject.objects.get(id=pid) not in ActiveProject.objects.filter(submission_status=SubmissionStatus.NEEDS_ASSIGNMENT): raise forms.ValidationError('Incorrect project selected.') return pid @@ -230,13 +231,13 @@ def save(self): edit_log = EditLog.objects.get(id=edit_log.id) # Resubmit with revisions elif edit_log.decision == 1: - project.submission_status = 30 + project.submission_status = SubmissionStatus.NEEDS_RESUBMISSION project.revision_request_datetime = now project.latest_reminder = now project.save() # Accept else: - project.submission_status = 40 + project.submission_status = SubmissionStatus.NEEDS_COPYEDIT project.editor_accept_datetime = now project.latest_reminder = now @@ -289,7 +290,7 @@ def save(self): project = copyedit_log.project now = timezone.now() copyedit_log.complete_datetime = now - project.submission_status = 50 + project.submission_status = SubmissionStatus.NEEDS_APPROVAL project.copyedit_completion_datetime = now project.latest_reminder = now copyedit_log.save() diff --git a/physionet-django/console/templates/console/submission_info_card.html b/physionet-django/console/templates/console/submission_info_card.html index d82dac8b2e..7ea3d0ef9e 100644 --- a/physionet-django/console/templates/console/submission_info_card.html +++ b/physionet-django/console/templates/console/submission_info_card.html @@ -22,7 +22,7 @@ Embargo {% endif %} - {% if project.submission_status >= 40 %} + {% if project.submission_status >= SubmissionStatus.NEEDS_COPYEDIT %} diff --git a/physionet-django/console/test_views.py b/physionet-django/console/test_views.py index cdbe89679c..c5be229c41 100644 --- a/physionet-django/console/test_views.py +++ b/physionet-django/console/test_views.py @@ -17,6 +17,7 @@ License, PublishedProject, StorageRequest, + SubmissionStatus, ) from user.models import User from physionet.models import FrontPageButton, StaticPage @@ -55,7 +56,7 @@ def test_assign_editor(self): 'editor':editor.id}) project = ActiveProject.objects.get(title='MIT-BIH Arrhythmia Database') self.assertTrue(project.editor, editor) - self.assertEqual(project.submission_status, 20) + self.assertEqual(project.submission_status, SubmissionStatus.NEEDS_DECISION) def test_reassign_editor(self): """ @@ -71,7 +72,7 @@ def test_reassign_editor(self): 'project': project.id, 'editor': editor.id}) project = ActiveProject.objects.get(title='MIT-BIH Arrhythmia Database') self.assertTrue(project.editor, editor) - self.assertEqual(project.submission_status, 20) + self.assertEqual(project.submission_status, SubmissionStatus.NEEDS_DECISION) # Reassign editor editor = User.objects.get(username='amitupreti') diff --git a/physionet-django/console/views.py b/physionet-django/console/views.py index c7a370354d..f0734d345f 100644 --- a/physionet-django/console/views.py +++ b/physionet-django/console/views.py @@ -52,6 +52,7 @@ PublishedProject, Reference, StorageRequest, + SubmissionStatus, Topic, exists_project_slug, ) @@ -147,21 +148,21 @@ def submitted_projects(request): messages.success(request, 'The editor has been assigned') # Submitted projects - projects = ActiveProject.objects.filter(submission_status__gt=0).order_by( + projects = ActiveProject.objects.filter(submission_status__gt=SubmissionStatus.UNSUBMITTED).order_by( 'submission_datetime') # Separate projects by submission status # Awaiting editor assignment - assignment_projects = projects.filter(submission_status=10) + assignment_projects = projects.filter(submission_status=SubmissionStatus.NEEDS_ASSIGNMENT) # Awaiting editor decision - decision_projects = projects.filter(submission_status=20) + decision_projects = projects.filter(submission_status=SubmissionStatus.NEEDS_DECISION) # Awaiting author revisions - revision_projects = projects.filter(submission_status=30) + revision_projects = projects.filter(submission_status=SubmissionStatus.NEEDS_RESUBMISSION) # Awaiting editor copyedit - copyedit_projects = projects.filter(submission_status=40) + copyedit_projects = projects.filter(submission_status=SubmissionStatus.NEEDS_COPYEDIT) # Awaiting author approval - approval_projects = projects.filter(submission_status=50) + approval_projects = projects.filter(submission_status=SubmissionStatus.NEEDS_APPROVAL) # Awaiting editor publish - publish_projects = projects.filter(submission_status=60) + publish_projects = projects.filter(submission_status=SubmissionStatus.NEEDS_PUBLICATION) assign_editor_form = forms.AssignEditorForm() @@ -209,15 +210,15 @@ def editor_home(request): 'submission_datetime') # Awaiting editor decision - decision_projects = projects.filter(submission_status=20) + decision_projects = projects.filter(submission_status=SubmissionStatus.NEEDS_DECISION) # Awaiting author revisions - revision_projects = projects.filter(submission_status=30) + revision_projects = projects.filter(submission_status=SubmissionStatus.NEEDS_RESUBMISSION) # Awaiting editor copyedit - copyedit_projects = projects.filter(submission_status=40) + copyedit_projects = projects.filter(submission_status=SubmissionStatus.NEEDS_COPYEDIT) # Awaiting author approval - approval_projects = projects.filter(submission_status=50) + approval_projects = projects.filter(submission_status=SubmissionStatus.NEEDS_APPROVAL) # Awaiting editor publish - publish_projects = projects.filter(submission_status=60) + publish_projects = projects.filter(submission_status=SubmissionStatus.NEEDS_PUBLICATION) # Time to check if the reminder email can be sent yesterday = timezone.now() + timezone.timedelta(days=-1) @@ -320,7 +321,7 @@ def edit_submission(request, project_slug, *args, **kwargs): embargo_form = forms.EmbargoFilesDaysForm() # The user must be the editor - if project.submission_status not in [20, 30]: + if project.submission_status not in [SubmissionStatus.NEEDS_DECISION, SubmissionStatus.NEEDS_RESUBMISSION]: return redirect('editor_home') if request.method == 'POST': @@ -365,7 +366,7 @@ def copyedit_submission(request, project_slug, *args, **kwargs): Page to copyedit the submission """ project = kwargs['project'] - if project.submission_status != 40: + if project.submission_status != SubmissionStatus.NEEDS_COPYEDIT: return redirect('editor_home') copyedit_log = project.copyedit_logs.get(complete_datetime=None) @@ -551,7 +552,7 @@ def awaiting_authors(request, project_slug, *args, **kwargs): """ project = kwargs['project'] - if project.submission_status != 50: + if project.submission_status != SubmissionStatus.NEEDS_APPROVAL: return redirect('editor_home') authors, author_emails, storage_info, edit_logs, copyedit_logs, latest_version = project.info_card() @@ -613,7 +614,7 @@ def publish_submission(request, project_slug, *args, **kwargs): """ project = kwargs['project'] - if project.submission_status != 60: + if project.submission_status != SubmissionStatus.NEEDS_PUBLICATION: return redirect('editor_home') if settings.SYSTEM_MAINTENANCE_NO_UPLOAD: raise ServiceUnavailable() @@ -727,7 +728,7 @@ def unsubmitted_projects(request): """ List of unsubmitted projects """ - projects = ActiveProject.objects.filter(submission_status=0).order_by( + projects = ActiveProject.objects.filter(submission_status=SubmissionStatus.UNSUBMITTED).order_by( 'creation_datetime') projects = paginate(request, projects, 50) return render(request, 'console/unsubmitted_projects.html', @@ -1102,9 +1103,9 @@ def user_management(request, username): projects = {} projects['Unsubmitted'] = ActiveProject.objects.filter(authors__user=user, - submission_status=0).order_by('-creation_datetime') + submission_status=SubmissionStatus.UNSUBMITTED).order_by('-creation_datetime') projects['Submitted'] = ActiveProject.objects.filter(authors__user=user, - submission_status__gt=0).order_by('-submission_datetime') + submission_status__gt=SubmissionStatus.UNSUBMITTED).order_by('-submission_datetime') projects['Archived'] = ArchivedProject.objects.filter(authors__user=user).order_by('-archive_datetime') projects['Published'] = PublishedProject.objects.filter(authors__user=user).order_by('-publish_datetime') diff --git a/physionet-django/project/management/commands/list_projects.py b/physionet-django/project/management/commands/list_projects.py index f229de7ec7..7bc5cfb9d3 100644 --- a/physionet-django/project/management/commands/list_projects.py +++ b/physionet-django/project/management/commands/list_projects.py @@ -8,7 +8,7 @@ from django.db.models import Q import html2text -from project.models import ActiveProject +from project.models import ActiveProject, SubmissionStatus from user.models import AssociatedEmail, User @@ -68,10 +68,10 @@ def add_arguments(self, parser): def handle(self, *args, **options): projects = ActiveProject.objects if options['unsubmitted']: - projects = projects.filter(submission_status__lt=10) + projects = projects.filter(submission_status__lt=SubmissionStatus.NEEDS_ASSIGNMENT) order = 'creation_datetime' else: - projects = projects.filter(submission_status__gte=10) + projects = projects.filter(submission_status__gte=SubmissionStatus.NEEDS_ASSIGNMENT) order = 'submission_datetime' if options['title']: diff --git a/physionet-django/project/modelcomponents/activeproject.py b/physionet-django/project/modelcomponents/activeproject.py index 3024003fe1..188c4805cb 100644 --- a/physionet-django/project/modelcomponents/activeproject.py +++ b/physionet-django/project/modelcomponents/activeproject.py @@ -193,13 +193,13 @@ class ActiveProject(Metadata, UnpublishedProject, SubmissionInfo): ) SUBMISSION_STATUS_LABELS = { - 0: 'Not submitted.', - 10: 'Awaiting editor assignment.', - 20: 'Awaiting editor decision.', - 30: 'Revisions requested.', - 40: 'Submission accepted; awaiting editor copyedits.', - 50: 'Awaiting authors to approve publication.', - 60: 'Awaiting editor to publish.', + SubmissionStatus.UNSUBMITTED: 'Not submitted.', + SubmissionStatus.NEEDS_ASSIGNMENT: 'Awaiting editor assignment.', + SubmissionStatus.NEEDS_DECISION: 'Awaiting editor decision.', + SubmissionStatus.NEEDS_RESUBMISSION: 'Revisions requested.', + SubmissionStatus.NEEDS_COPYEDIT: 'Submission accepted; awaiting editor copyedits.', + SubmissionStatus.NEEDS_APPROVAL: 'Awaiting authors to approve publication.', + SubmissionStatus.NEEDS_PUBLICATION: 'Awaiting editor to publish.', } class Meta: @@ -277,14 +277,14 @@ def author_editable(self): """ Whether the project can be edited by its authors """ - if self.submission_status in [0, 30]: + if self.submission_status in [SubmissionStatus.UNSUBMITTED, SubmissionStatus.NEEDS_RESUBMISSION]: return True def copyeditable(self): """ Whether the project can be copyedited """ - if self.submission_status == 40: + if self.submission_status == SubmissionStatus.NEEDS_COPYEDIT: return True def archive(self, archive_reason): @@ -429,7 +429,7 @@ def submit(self, author_comments): if not self.is_submittable(): raise Exception('ActiveProject is not submittable') - self.submission_status = 10 + self.submission_status = SubmissionStatus.NEEDS_ASSIGNMENT self.submission_datetime = timezone.now() self.author_comments = author_comments self.save() @@ -448,7 +448,7 @@ def assign_editor(self, editor): edit stage. """ self.editor = editor - self.submission_status = 20 + self.submission_status = SubmissionStatus.NEEDS_DECISION self.editor_assignment_datetime = timezone.now() self.save() @@ -469,7 +469,7 @@ def is_resubmittable(self): """ Submit the project for review. """ - return (self.submission_status == 30 and self.check_integrity()) + return (self.submission_status == SubmissionStatus.NEEDS_RESUBMISSION and self.check_integrity()) def resubmit(self, author_comments): """ @@ -478,7 +478,7 @@ def resubmit(self, author_comments): raise Exception('ActiveProject is not resubmittable') with transaction.atomic(): - self.submission_status = 20 + self.submission_status = SubmissionStatus.NEEDS_DECISION self.resubmission_datetime = timezone.now() self.save() # Create a new edit log @@ -489,8 +489,8 @@ def reopen_copyedit(self): """ Reopen the project for copyediting """ - if self.submission_status == 50: - self.submission_status = 40 + if self.submission_status == SubmissionStatus.NEEDS_APPROVAL: + self.submission_status = SubmissionStatus.NEEDS_COPYEDIT self.copyedit_completion_datetime = None self.save() CopyeditLog.objects.create(project=self, is_reedit=True) @@ -502,13 +502,13 @@ def approve_author(self, author): author is the final outstanding one. Return whether the process was successful. """ - if self.submission_status == 50 and not author.approval_datetime: + if self.submission_status == SubmissionStatus.NEEDS_APPROVAL and not author.approval_datetime: now = timezone.now() author.approval_datetime = now author.save() if self.all_authors_approved(): self.author_approval_datetime = now - self.submission_status = 60 + self.submission_status = SubmissionStatus.NEEDS_PUBLICATION self.save() return True @@ -524,7 +524,7 @@ def is_publishable(self): """ Check whether a project may be published """ - if self.submission_status == 60 and self.check_integrity() and self.all_authors_approved(): + if self.submission_status == SubmissionStatus.NEEDS_PUBLICATION and self.check_integrity() and self.all_authors_approved(): return True return False diff --git a/physionet-django/project/templates/project/active_submission_timeline.html b/physionet-django/project/templates/project/active_submission_timeline.html index 6d5a4e260c..9c6a09943d 100644 --- a/physionet-django/project/templates/project/active_submission_timeline.html +++ b/physionet-django/project/templates/project/active_submission_timeline.html @@ -3,7 +3,7 @@ {# Awaiting authors to approve final project #} - {% if project.submission_status == 50 %} + {% if project.submission_status == SubmissionStatus.NEEDS_APPROVAL %}
  • Currently
    @@ -44,7 +44,7 @@
  • - {% elif project.submission_status == 60 %} + {% elif project.submission_status == SubmissionStatus.NEEDS_PUBLICATION %}
  • Currently
    @@ -61,7 +61,7 @@ {# Waiting for revisions #} - {% if project.submission_status == 30 %} + {% if project.submission_status == SubmissionStatus.NEEDS_RESUBMISSION %}
  • Currently
    @@ -96,7 +96,7 @@ {% endif %}
  • - {% elif project.submission_status >= 40 %} + {% elif project.submission_status >= SubmissionStatus.NEEDS_COPYEDIT %} {# At this point, there may have been any number of copyedits #} {% for c in copyedit_logs reversed %} {% if c.is_reedit %} @@ -180,7 +180,7 @@ {# Waiting for editor #} - {% if project.submission_status == 10 %} + {% if project.submission_status == SubmissionStatus.NEEDS_ASSIGNMENT %}
  • Currently
    diff --git a/physionet-django/project/templates/project/project_home.html b/physionet-django/project/templates/project/project_home.html index 4a3fe40df8..1431f08770 100644 --- a/physionet-django/project/templates/project/project_home.html +++ b/physionet-django/project/templates/project/project_home.html @@ -174,7 +174,7 @@

    {{ project.title }}<

    Submitting Author: {{ project.submitting_author.get_full_name }}
    Created: {{ project.creation_datetime|date }}. Modified: {{ project.modified_datetime|date }}.
    - Status: {{ project.submission_status_label }} {% if project.submission_status == 0 %}Deadline: {{ project.submission_deadline|date }}.{% endif %} + Status: {{ project.submission_status_label }} {% if project.submission_status == SubmissionStatus.UNSUBMITTED %}Deadline: {{ project.submission_deadline|date }}.{% endif %}

  • {% endfor %} diff --git a/physionet-django/project/views.py b/physionet-django/project/views.py index b63ff39c1a..22a1fde4a5 100644 --- a/physionet-django/project/views.py +++ b/physionet-django/project/views.py @@ -47,6 +47,7 @@ PublishedProject, Reference, StorageRequest, + SubmissionStatus, Topic, UploadedDocument, ) @@ -248,16 +249,16 @@ def project_home(request): missing_affiliations = [] pending_revisions = [] for p in projects: - if (p.submission_status == 50 + if (p.submission_status == SubmissionStatus.NEEDS_APPROVAL and not p.all_authors_approved()): if p.authors.get(user=user).is_submitting: pending_author_approvals.append(p) elif not p.authors.get(user=user).approval_datetime: pending_author_approvals.append(p) - if (p.submission_status == 30 + if (p.submission_status == SubmissionStatus.NEEDS_RESUBMISSION and p.authors.get(user=user).is_submitting): pending_revisions.append(p) - if p.submission_status == 0 and p.authors.get(user=user).affiliations.count() == 0: + if p.submission_status == SubmissionStatus.UNSUBMITTED and p.authors.get(user=user).affiliations.count() == 0: missing_affiliations.append([p, p.authors.get(user=user).creation_date]) archived_projects = [a.project for a in archived_authors] @@ -485,7 +486,7 @@ def edit_affiliation(request, project_slug, **kwargs): project, authors = kwargs['project'], kwargs['authors'] author = authors.get(user=request.user) - if project.submission_status not in [0, 30]: + if project.submission_status not in [SubmissionStatus.UNSUBMITTED, SubmissionStatus.NEEDS_RESUBMISSION]: raise Http404() # Reload the formset with the first empty form @@ -1332,7 +1333,7 @@ def project_submission(request, project_slug, **kwargs): pass # Register the approval if valid if project.approve_author(author): - if project.submission_status == 60: + if project.submission_status == SubmissionStatus.NEEDS_PUBLICATION: messages.success(request, 'You have approved the project for publication. The editor will publish it shortly') notification.authors_approved_notify(request, project) else: @@ -1349,7 +1350,7 @@ def project_submission(request, project_slug, **kwargs): for e in edit_logs: e.set_quality_assurance_results() # Awaiting authors - if project.submission_status == 50: + if project.submission_status == SubmissionStatus.NEEDS_APPROVAL: authors = authors.order_by('approval_datetime') for a in authors: a.set_display_info() @@ -1420,7 +1421,7 @@ def project_ethics(request, project_slug, **kwargs): def edit_ethics(request, project_slug, **kwargs): project = kwargs['project'] - if project.submission_status not in [0, 30]: + if project.submission_status not in [SubmissionStatus.UNSUBMITTED, SubmissionStatus.NEEDS_RESUBMISSION]: raise Http404() # Reload the formset with the first empty form