Make it possible to accept invites

This commit is contained in:
Gergely Polonkai 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) 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__) app = CalendarSocialApp(__name__)

View File

@ -15,7 +15,12 @@
<h2>{% trans %}Invited users{% endtrans %}</h2> <h2>{% trans %}Invited users{% endtrans %}</h2>
<ul> <ul>
{% for invitation in event.invitations %} {% for invitation in event.invitations %}
<li>{{ invitation.invitee }}</li> <li>
{{ invitation.invitee }}
{% if invitation.invitee == current_user.profile %}
<a href="{{ url_for('accept_invite', invite_id=invitation.id) }}">Accept</a>
{% endif %}
</li>
{% endfor %} {% endfor %}
</ul> </ul>
<hr> <hr>