Skip to content

Commit

Permalink
project_submission: handle case of an unassigned project.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Benjamin Moody committed Jan 16, 2024
1 parent 323cdff commit 28e995a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
23 changes: 23 additions & 0 deletions physionet-django/project/modelcomponents/unpublishedproject.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
'[email protected]', 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.
Expand Down
8 changes: 1 addition & 7 deletions physionet-django/project/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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,
},
)

Expand Down

0 comments on commit 28e995a

Please sign in to comment.