[Refactor] Move invitation code to the Event model

This commit is contained in:
2018-07-12 11:08:13 +02:00
parent 36c2f0fd77
commit dc0b2954c1
2 changed files with 19 additions and 10 deletions

View File

@@ -255,7 +255,7 @@ class CalendarSocialApp(Flask):
"""
from .forms import InviteForm
from .models import db, Event, Invitation, Notification, NotificationAction
from .models import db, Event
try:
event = Event.query.filter(Event.event_uuid == event_uuid).one()
@@ -267,15 +267,7 @@ class CalendarSocialApp(Flask):
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)
event.invite(current_user.profile, invitee=form.invitee.data)
db.session.commit()