forked from gergely/calendar-social
[Refactor] Move invitation code to the Event model
This commit is contained in:
parent
36c2f0fd77
commit
dc0b2954c1
@ -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()
|
||||
|
||||
|
@ -417,6 +417,23 @@ class Event(db.Model):
|
||||
|
||||
return url_for('event_details', event_uuid=self.event_uuid)
|
||||
|
||||
def invite(self, inviter, invited):
|
||||
"""Invite ``invited`` to the event
|
||||
|
||||
The invitation will arrive from ``inviter``.
|
||||
"""
|
||||
|
||||
invite = Invitation(event=self, sender=inviter, invitee=invited)
|
||||
db.session.add(invite)
|
||||
|
||||
notification = Notification(profile=invited,
|
||||
actor=inviter,
|
||||
item=self,
|
||||
action=NotificationAction.invite)
|
||||
db.session.add(notification)
|
||||
|
||||
return invite
|
||||
|
||||
|
||||
class UserSetting(db.Model): # pylint: disable=too-few-public-methods
|
||||
"""Database model for user settings
|
||||
|
Loading…
Reference in New Issue
Block a user