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

Adding category utilities

Adding utils to Superevent and Event models for comparing
categories and deciding if an Event is the correct category to be
part of a superevent.
parent 334d1809
No related branches found
No related tags found
No related merge requests found
...@@ -193,6 +193,24 @@ class Event(models.Model): ...@@ -193,6 +193,24 @@ class Event(models.Model):
nodes.append(hdf.read()) nodes.append(hdf.read())
return os.path.join(settings.GRACEDB_DATA_DIR, *nodes) return os.path.join(settings.GRACEDB_DATA_DIR, *nodes)
def is_test(self):
return self.group.name == 'Test'
def is_mdc(self):
return (self.search and self.search.name == 'MDC' and
self.group.name != 'Test')
def is_production(self):
return not (self.is_test() or self.is_mdc())
def get_event_category(self):
if self.is_test():
return 'Test'
elif self.is_mdc():
return 'MDC'
else:
return 'Production'
def ligoApproved(self): def ligoApproved(self):
return self.approval_set.filter(approvingCollaboration='L').count() return self.approval_set.filter(approvingCollaboration='L').count()
......
...@@ -208,6 +208,40 @@ class Superevent(CleanSaveModel, ModelToDictMixin, AutoIncrementModel): ...@@ -208,6 +208,40 @@ class Superevent(CleanSaveModel, ModelToDictMixin, AutoIncrementModel):
# Call base class delete # Call base class delete
super(Superevent, self).delete(*args, **kwargs) super(Superevent, self).delete(*args, **kwargs)
def event_compatible(self, event):
"""
Check whether an event is of the correct type to be part of this
superevent
"""
return self.__class__.event_category_check(event, self.category)
@classmethod
def event_category_check(cls, event, superevent_category):
"""
Given a superevent type, check whether an event could be added to such
a superevent
"""
if (superevent_category == cls.SUPEREVENT_CATEGORY_TEST and
not event.is_test()):
return False
elif (superevent_category == cls.SUPEREVENT_CATEGORY_MDC and
not event.is_mdc()):
return False
elif (superevent_category == cls.SUPEREVENT_CATEGORY_PRODUCTION and
(event.is_test() or event.is_mdc())):
return False
else:
return True
def is_production(self):
return self.category == self.SUPEREVENT_CATEGORY_PRODUCTION
def is_test(self):
return self.category == self.SUPEREVENT_CATEGORY_TEST
def is_mdc(self):
return self.category == self.SUPEREVENT_CATEGORY_MDC
def confirm_as_gw(self): def confirm_as_gw(self):
""" """
Sets is_gw to True, calculates the gw_date_number in the database, and Sets is_gw to True, calculates the gw_date_number in the database, and
...@@ -415,6 +449,11 @@ class Superevent(CleanSaveModel, ModelToDictMixin, AutoIncrementModel): ...@@ -415,6 +449,11 @@ class Superevent(CleanSaveModel, ModelToDictMixin, AutoIncrementModel):
# one that datetime can't parse or that the regex won't match # one that datetime can't parse or that the regex won't match
pass pass
class EventTypeMismatchError(Exception):
# To be raised when an attempt is made to add an event with an
# incompatible type
pass
class Log(CleanSaveModel, LogBase, AutoIncrementModel): class Log(CleanSaveModel, LogBase, AutoIncrementModel):
""" """
......
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