forked from gergely/calendar-social
Send a notification when a follow action happens
This commit is contained in:
parent
379a5b1bb0
commit
3bd381692b
@ -272,7 +272,7 @@ class CalendarSocialApp(Flask):
|
|||||||
"""View for following a user
|
"""View for following a user
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from .models import db, Profile, User, UserFollow
|
from .models import db, Profile, User, UserFollow, Notification, NotificationAction
|
||||||
|
|
||||||
profile = current_user.profile
|
profile = current_user.profile
|
||||||
|
|
||||||
@ -284,6 +284,13 @@ class CalendarSocialApp(Flask):
|
|||||||
followed_id=profile,
|
followed_id=profile,
|
||||||
accepted_at=datetime.utcnow())
|
accepted_at=datetime.utcnow())
|
||||||
db.session.add(follow)
|
db.session.add(follow)
|
||||||
|
|
||||||
|
notification = Notification(profile=profile,
|
||||||
|
actor=current_user.profile,
|
||||||
|
item=profile,
|
||||||
|
action=NotificationAction.follow)
|
||||||
|
db.session.add(notification)
|
||||||
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
return redirect(url_for('display_profile', username=username))
|
return redirect(url_for('display_profile', username=username))
|
||||||
|
@ -24,6 +24,7 @@ from warnings import warn
|
|||||||
from flask_babelex import lazy_gettext
|
from flask_babelex import lazy_gettext
|
||||||
from flask_security import UserMixin, RoleMixin
|
from flask_security import UserMixin, RoleMixin
|
||||||
from flask_sqlalchemy import SQLAlchemy
|
from flask_sqlalchemy import SQLAlchemy
|
||||||
|
from sqlalchemy.ext.hybrid import hybrid_property
|
||||||
from sqlalchemy.orm.exc import NoResultFound
|
from sqlalchemy.orm.exc import NoResultFound
|
||||||
from sqlalchemy_utils.types.choice import ChoiceType
|
from sqlalchemy_utils.types.choice import ChoiceType
|
||||||
|
|
||||||
@ -519,6 +520,11 @@ class Notification(db.Model):
|
|||||||
|
|
||||||
return item_class.query.get(self.item_id)
|
return item_class.query.get(self.item_id)
|
||||||
|
|
||||||
|
@item.setter
|
||||||
|
def item(self, value):
|
||||||
|
self.item_type = value.__class__.__name__
|
||||||
|
self.item_id = value.id
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def message(self):
|
def message(self):
|
||||||
"""Get the translated message for ``key``
|
"""Get the translated message for ``key``
|
||||||
|
Loading…
Reference in New Issue
Block a user