forked from gergely/calendar-social
Allow users to invite other users to events
This commit is contained in:
@@ -235,12 +235,13 @@ class CalendarSocialApp(Flask):
|
||||
return render_template('user-settings.html', form=form)
|
||||
|
||||
@staticmethod
|
||||
@route('/event/<string:event_uuid>')
|
||||
@route('/event/<string:event_uuid>', methods=['GET', 'POST'])
|
||||
def event_details(event_uuid):
|
||||
"""View to display event details
|
||||
"""
|
||||
|
||||
from .models import Event
|
||||
from .forms import InviteForm
|
||||
from .models import db, Event, Invitation, Notification, NotificationAction
|
||||
|
||||
try:
|
||||
event = Event.query.filter(Event.event_uuid == event_uuid).one()
|
||||
@@ -249,7 +250,24 @@ class CalendarSocialApp(Flask):
|
||||
except MultipleResultsFound:
|
||||
abort(500)
|
||||
|
||||
return render_template('event-details.html', event=event)
|
||||
form = InviteForm(event)
|
||||
|
||||
if form.validate_on_submit():
|
||||
invite = Invitation(event=event, sender=current_user.profile)
|
||||
form.populate_obj(invite)
|
||||
db.session.add(invite)
|
||||
|
||||
notification = Notification(profile=form.invitee.data,
|
||||
actor=current_user.profile,
|
||||
item=event,
|
||||
action=NotificationAction.invite)
|
||||
db.session.add(notification)
|
||||
|
||||
db.session.commit()
|
||||
|
||||
return redirect(url_for('event_details', event_uuid=event.event_uuid))
|
||||
|
||||
return render_template('event-details.html', event=event, form=form)
|
||||
|
||||
@staticmethod
|
||||
@route('/profile/@<string:username>')
|
||||
|
Reference in New Issue
Block a user