1 from __future__
import unicode_literals
2 from pyramid.threadlocal
import get_current_request
3 from sqlalchemy.ext.declarative
import declared_attr
4 from sqlalchemy.orm
import backref, relationship
5 from sqlalchemy.schema
import Column, ForeignKey
6 from sqlalchemy.types
import DateTime, Integer
7 from webhelpers.html.tags
import link_to
15 __tablename__ =
'notifications'
16 __mapper_args__ = {
'polymorphic_on':
'notification_type_id'}
17 id = Column(Integer(unsigned=
True), primary_key=
True)
18 notification_type_id = Column(
19 Integer(unsigned=
True), ForeignKey(
'notification_types.id', ondelete=
'cascade'),
21 created_at = Column(DateTime, nullable=
False, default=current_timestamp)
24 'User', backref=backref(
'notifications', lazy=
'dynamic'),
25 secondary=
'users_notifications')
32 if user
not in self.
users:
33 self.users.append(user)
41 Integer(unsigned=
True), ForeignKey(
'notifications.id', ondelete=
'cascade'),
47 __tablename__ =
'requested_challenge_notifications'
48 __mapper_args__ = {
'polymorphic_identity': NotificationType.lookup_data.index(
'requested_challenge') + 1}
49 user_id = Column(Integer(unsigned=
True), ForeignKey(
'users.id', ondelete=
'cascade'), nullable=
False)
50 challenge_id = Column(Integer(unsigned=
True), ForeignKey(
'challenges.id', ondelete=
'cascade'), nullable=
False)
52 user = relationship(
'User', lazy=
'joined')
53 challenge = relationship(
'Challenge', lazy=
'joined')
57 request = get_current_request()
58 user = link_to(self.
user,
59 url=request.route_url(
'user.view.challenges', id=self.user.id))
61 url=request.route_url(
'challenge.view', id=self.challenge.id))
62 return '%(user)s has challenged you to a %(challenge)s.' % dict(user=user, challenge=challenge)
67 __tablename__ =
'accepted_challenge_notifications'
68 __mapper_args__ = {
'polymorphic_identity': NotificationType.lookup_data.index(
'accepted_challenge') + 1}
69 user_id = Column(Integer(unsigned=
True), ForeignKey(
'users.id', ondelete=
'cascade'), nullable=
False)
70 challenge_id = Column(Integer(unsigned=
True), ForeignKey(
'challenges.id', ondelete=
'cascade'), nullable=
False)
72 user = relationship(
'User', lazy=
'joined')
73 challenge = relationship(
'Challenge', lazy=
'joined')
77 request = get_current_request()
78 user = link_to(self.
user,
79 url=request.route_url(
'user.view.challenges', id=self.user.id))
81 url=request.route_url(
'challenge.view', id=self.challenge.id))
82 return '%(user)s has accepted your %(challenge)s.' % dict(user=user, challenge=challenge)
87 __tablename__ =
'denied_challenge_notifications'
88 __mapper_args__ = {
'polymorphic_identity': NotificationType.lookup_data.index(
'denied_challenge') + 1}
89 user_id = Column(Integer(unsigned=
True), ForeignKey(
'users.id', ondelete=
'cascade'), nullable=
False)
90 challenge_id = Column(Integer(unsigned=
True), ForeignKey(
'challenges.id', ondelete=
'cascade'), nullable=
False)
92 user = relationship(
'User', lazy=
'joined')
93 challenge = relationship(
'Challenge', lazy=
'joined')
97 request = get_current_request()
98 user = link_to(self.
user,
99 url=request.route_url(
'user.view.challenges', id=self.user.id))
101 url=request.route_url(
'challenge.view', id=self.challenge.id))
102 return '%(user)s has denied your %(challenge)s.' % dict(user=user, challenge=challenge)
106 __tablename__ =
'new_buddy_notifications'
107 __mapper_args__ = {
'polymorphic_identity': NotificationType.lookup_data.index(
'new_buddy') + 1}
108 user_id = Column(Integer(unsigned=
True), ForeignKey(
'users.id', ondelete=
'cascade'), nullable=
False)
110 user = relationship(
'User', lazy=
'joined')
114 request = get_current_request()
115 user = link_to(self.
user,
116 url=request.route_url(
'user.view.challenges', id=self.user.id))
117 return '%(user)s has added you as a buddy.' % dict(user=user)
122 __tablename__ =
'uploaded_workout_notifications'
123 __mapper_args__ = {
'polymorphic_identity': NotificationType.lookup_data.index(
'uploaded_workout') + 1}
124 user_id = Column(Integer(unsigned=
True), ForeignKey(
'users.id', ondelete=
'cascade'), nullable=
False)
125 challenge_id = Column(Integer(unsigned=
True), ForeignKey(
'challenges.id', ondelete=
'cascade'), nullable=
False)
127 user = relationship(
'User', lazy=
'joined')
128 challenge = relationship(
'Challenge', lazy=
'joined')
132 request = get_current_request()
133 user = link_to(self.
user,
134 url=request.route_url(
'user.view.challenges', id=self.user.id))
136 url=request.route_url(
'challenge.view', id=self.challenge.id))
137 return '%(user)s has completed the %(challenge)s.' % dict(user=user, challenge=challenge)