diff --git a/calsocial/models.py b/calsocial/models.py index 75e4c8c..e36ce0f 100644 --- a/calsocial/models.py +++ b/calsocial/models.py @@ -70,6 +70,18 @@ class NotificationAction(Enum): #: A user has been invited to an event invite = 2 + def __hash__(self): + return Enum.__hash__(self) + + def __eq__(self, other): + if isinstance(other, str): + return self.name.lower() == other.lower() # pylint: disable=no-member + + if isinstance(other, (int, float)): + return self.value == other + + return Enum.__eq__(self, other) + NOTIFICATION_ACTION_MESSAGES = { NotificationAction.follow: (_('%(actor)s followed you'), _('%(actor)s followed %(item)s')), @@ -156,6 +168,47 @@ RESPONSE_VISIBILITY_TRANSLATIONS = { } +class EventAvailability(Enum): + """Enumeration of event availabilities + """ + + free = 0 + busy = 1 + + def __hash__(self): + return Enum.__hash__(self) + + def __eq__(self, other): + if isinstance(other, str): + return self.name.lower() == other.lower() # pylint: disable=no-member + + if isinstance(other, (int, float)): + return self.value == other + + return Enum.__eq__(self, other) + + +class UserAvailability(Enum): + """Enumeration of user availabilities + """ + + free = 0 + busy = 1 + tentative = 2 + + def __hash__(self): + return Enum.__hash__(self) + + def __eq__(self, other): + if isinstance(other, str): + return self.name.lower() == other.lower() # pylint: disable=no-member + + if isinstance(other, (int, float)): + return self.value == other + + return Enum.__eq__(self, other) + + class SettingsProxy: """Proxy object to get settings for a user """