From 4c65644291d7f3414cce1362b654de5b2e57dd07 Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Tue, 10 Jul 2018 10:58:43 +0200 Subject: [PATCH] Make it possible to accept invites --- calsocial/__init__.py | 33 ++++++++++++++++++++++++++ calsocial/templates/event-details.html | 7 +++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/calsocial/__init__.py b/calsocial/__init__.py index d6f6c02..189e436 100644 --- a/calsocial/__init__.py +++ b/calsocial/__init__.py @@ -328,4 +328,37 @@ class CalendarSocialApp(Flask): return render_template('notifications.html', notifs=notifs) + @staticmethod + @route('/accept/') + def accept_invite(invite_id): + """View to accept an invitation + """ + + from flask import redirect, url_for + + from .models import db, Invitation, Response, ResponseType + + invitation = Invitation.query.get_or_404(invite_id) + + if invitation.invitee != current_user.profile: + abort(403) + + try: + Response.query \ + .filter(Response.event == invitation.event) \ + .filter(Response.profile == current_user.profile) \ + .one() + except NoResultFound: + response = Response(profile=current_user.profile, + event=invitation.event, + invitation=invitation, + response=ResponseType.going) + db.session.add(response) + db.session.commit() + except MultipleResultsFound: + pass + + return redirect(url_for('event_details', event_uuid=invitation.event.event_uuid)) + + app = CalendarSocialApp(__name__) diff --git a/calsocial/templates/event-details.html b/calsocial/templates/event-details.html index b445f5a..26dff7b 100644 --- a/calsocial/templates/event-details.html +++ b/calsocial/templates/event-details.html @@ -15,7 +15,12 @@

{% trans %}Invited users{% endtrans %}