From 28e995a8e9b02f0f74c2f119da0e1d0df2051f03 Mon Sep 17 00:00:00 2001 From: Benjamin Moody Date: Tue, 16 Jan 2024 15:39:35 -0500 Subject: [PATCH] project_submission: handle case of an unassigned project. On the submission page we display a contact address for the project editor, if one has been assigned. If no editor has yet been assigned, then the "contact_email" won't be shown. However, if no editor has yet been assigned (self.editor is None) and there is no PROJECT_EDITOR_EMAIL defined, the previous code would crash. Put this logic into the model class, not the view, and document it. --- .../modelcomponents/unpublishedproject.py | 23 +++++++++++++++++++ physionet-django/project/views.py | 8 +------ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/physionet-django/project/modelcomponents/unpublishedproject.py b/physionet-django/project/modelcomponents/unpublishedproject.py index a82e07caea..86233a5f54 100644 --- a/physionet-django/project/modelcomponents/unpublishedproject.py +++ b/physionet-django/project/modelcomponents/unpublishedproject.py @@ -103,6 +103,29 @@ def has_wfdb(self): """ return self.files.has_wfdb_files(self) + @property + def editor_contact_email(self): + """ + Email address for contacting the project editor. + + If a site-wide contact address is configured, that address + will be used for all projects. The string PROJECT-SLUG can be + included and will be replaced by the active project slug (for + example, PROJECT_EDITOR_EMAIL can be set to + 'editor+PROJECT-SLUG@example.org', if the mail server + understands how to handle it.) + + If there is no site-wide contact address, the primary email + address of the assigned editor is used. + """ + if not self.editor: + return None + elif settings.PROJECT_EDITOR_EMAIL: + return settings.PROJECT_EDITOR_EMAIL.replace('PROJECT-SLUG', + self.slug) + else: + return self.editor.email + def content_modified(self): """ Update the project's modification timestamp. diff --git a/physionet-django/project/views.py b/physionet-django/project/views.py index 394312046b..3dc934ed0e 100644 --- a/physionet-django/project/views.py +++ b/physionet-django/project/views.py @@ -1418,12 +1418,6 @@ def project_submission(request, project_slug, **kwargs): else: edit_logs, copyedit_logs = None, None - if settings.PROJECT_EDITOR_EMAIL: - contact_email = settings.PROJECT_EDITOR_EMAIL.replace('PROJECT-SLUG', - project.slug) - else: - contact_email = project.editor.email - return render( request, "project/project_submission.html", @@ -1435,7 +1429,7 @@ def project_submission(request, project_slug, **kwargs): "edit_logs": edit_logs, "copyedit_logs": copyedit_logs, "awaiting_user_approval": awaiting_user_approval, - "contact_email": contact_email, + "contact_email": project.editor_contact_email, }, )