Make actors and items in notifications links

This commit is contained in:
Gergely Polonkai 2018-07-10 10:26:43 +02:00
parent 17cca9380f
commit 0a1701dacd
2 changed files with 35 additions and 1 deletions

View File

@ -276,6 +276,15 @@ class Profile(db.Model): # pylint: disable=too-few-public-methods
.join(UserFollow.follower) \
.filter(UserFollow.followed == self)
@property
def url(self):
from flask import url_for
if self.user:
return url_for('display_profile', username=self.user.username)
return NotImplemented
class Event(db.Model):
"""Database model for events
@ -347,6 +356,15 @@ class Event(db.Model):
def __repr__(self):
return f'<Event {self.id} ({self.title}) of {self.profile}>'
def __str__(self):
return self.title
@property
def url(self):
from flask import url_for
return url_for('event_details', event_uuid=self.event_uuid)
class UserSetting(db.Model): # pylint: disable=too-few-public-methods
"""Database model for user settings
@ -557,6 +575,22 @@ class Notification(db.Model):
return lazy_gettext(message, actor=self.actor, item=self.item)
@property
def html(self):
"""Get the translated message for ``key`` in HTML format
"""
from flask import url_for, Markup
from flask_security import current_user
messages = NOTIFICATION_ACTION_MESSAGES.get(self.action)
message = messages[0 if self.item == current_user.profile else 1]
actor = f'<a href="{self.actor.url}">{self.actor}</a>'
item = f'<a href="{self.item.url}">{self.item}</a>'
return Markup(lazy_gettext(message, actor=actor, item=item))
class Invitation(db.Model): # pylint: disable=too-few-public-methods
"""Database model for event invitations

View File

@ -2,6 +2,6 @@
{% block content %}
{% for notif in notifs %}
{{ notif.message }}<br>
{{ notif.html }}<br>
{% endfor %}
{% endblock content %}