Make it possible to accept invites

This commit is contained in:
2018-07-10 10:58:43 +02:00
parent 321f31b3c6
commit 4c65644291
2 changed files with 39 additions and 1 deletions

View File

@@ -328,4 +328,37 @@ class CalendarSocialApp(Flask):
return render_template('notifications.html', notifs=notifs)
@staticmethod
@route('/accept/<int:invite_id>')
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__)