From 321f31b3c6b06d5ff7013d1cacf1e2078620cb4c Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Sun, 8 Jul 2018 18:52:35 +0200 Subject: [PATCH] Add the Response model This is to store RSVPs. --- calsocial/models.py | 57 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/calsocial/models.py b/calsocial/models.py index b61d502..b7e1ebb 100644 --- a/calsocial/models.py +++ b/calsocial/models.py @@ -74,6 +74,35 @@ NOTIFICATION_ACTION_MESSAGES = { } +class ResponseType(Enum): + """Enumeration of event availabilities + """ + + #: The user is about to attend the event + going = 0 + + #: The user will probably attend the event + probably_going = 1 + + #: The user is interested in the event, but might not go + probably_not_going = 2 + + #: The user won’t attend the event + not_going = 3 + + 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 """ @@ -617,3 +646,31 @@ class Invitation(db.Model): # pylint: disable=too-few-public-methods #: The timestamp of the invitation timestamp = db.Column(db.DateTime(), default=datetime.utcnow) + + +class Response(db.Model): # pylint: disable=too-few-public-methods + """Database model for RSVPs. + """ + + __tablename__ = 'responses' + + #: The profile that’s sending the RSVP + profile_id = db.Column(db.Integer(), db.ForeignKey('profiles.id'), primary_key=True) + + profile = db.relationship('Profile') + + #: The ID of the event + event_id = db.Column(db.Integer(), db.ForeignKey('events.id'), primary_key=True) + + event = db.relationship('Event') + + #: The ID of the invitation, if the user is responding to an invitation + invitation_id = db.Column(db.Integer(), db.ForeignKey('invitations.id'), nullable=True) + + invitation = db.relationship('Invitation') + + #: The timestamp of the response + timestamp = db.Column(db.DateTime(), default=datetime.utcnow) + + #: The response itself + response = db.Column(db.Enum(ResponseType), nullable=False)