From 0083606c3f83b8e8726f2794531d5f34b8ec8965 Mon Sep 17 00:00:00 2001 From: George Katsikas <giorgakis.katsikas@gmail.com> Date: Fri, 26 Jan 2024 18:08:32 +0100 Subject: [PATCH] log nomination start event only if one exists --- scipost_django/colleges/views.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/scipost_django/colleges/views.py b/scipost_django/colleges/views.py index 084b09801..8e48fdd42 100644 --- a/scipost_django/colleges/views.py +++ b/scipost_django/colleges/views.py @@ -295,12 +295,19 @@ class FellowshipStartEmailView(PermissionsMixin, MailView): def form_valid(self, form): """Create an event associated to this outgoing email.""" - event = FellowshipNominationEvent( - nomination=self.object.nomination, - description="Fellowship start email sent", - by=self.request.user.contributor, - ) - event.save() + try: + event = FellowshipNominationEvent( + nomination=self.object.nomination, + description="Fellowship start email sent", + by=self.request.user.contributor, + ) + event.save() + except Fellowship.nomination.RelatedObjectDoesNotExist: + messages.warning( + self.request, + "No Nomination was found for this Fellowship, " + "so no event about sending a start email was created.", + ) return super().form_valid(form) -- GitLab