Make it possible to accept invites
This commit is contained in:
parent
321f31b3c6
commit
4c65644291
@ -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__)
|
||||||
|
@ -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>
|
||||||
|
Loading…
Reference in New Issue
Block a user