From 45eb411eb2de1287c832c92a7062d3944f8a9c1e Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Sun, 8 Jul 2018 18:52:35 +0200 Subject: [PATCH] WIP: Event availability, User availability, notification eq str --- calsocial/models.py | 53 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) 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 """