Skip to content
Snippets Groups Projects
Commit 11a0b0a0 authored by Tanner Prestegard's avatar Tanner Prestegard Committed by GraceDB
Browse files

Bugfix for removing an event from a superevent

Prevent users from removing a superevent's preferred event.
They will have to update the superevent to set a new preferred
event instead, then remove the event.
parent 78d94899
No related branches found
No related tags found
No related merge requests found
......@@ -307,6 +307,9 @@ class Superevent(CleanSaveModel, ModelToDictMixin, AutoIncrementModel):
def __unicode__(self):
return self.superevent_id
class PreferredEventRemovalError(Exception):
# To be raised when an attempt is made to remove the preferred event.
pass
class Log(CleanSaveModel, LogBase, AutoIncrementModel):
"""
......
......@@ -281,16 +281,18 @@ def add_event_to_superevent(superevent, event, user, add_event_log=True,
def remove_event_from_superevent(superevent, event, user, add_event_log=True,
add_superevent_log=True, issue_event_alert=True,
issue_superevent_alert=True):
"""
This function should be within a try-except block to catch exceptions and
convert them to the appropriate response.
"""
# Throw error if this is the preferred event
if event == superevent.preferred_event:
raise Superevent.PreferredEventRemovalError("Can't remove a "
"superevent's preferred event without setting a new one.")
# Remove event from superevent
superevent.events.remove(event)
# Handle case where the event is also the preferred event for the
# superevent
if (hasattr(event, 'superevent_preferred_for') and
event.superevent_preferred_for == superevent):
superevent.preferred_event = None
# Create superevent log message to record event removal?
if add_superevent_log:
# Record event removal in superevent logs
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment