From 0a1701dacdc3aab77b76659932fd1e86b0c67972 Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Tue, 10 Jul 2018 10:26:43 +0200 Subject: [PATCH] Make actors and items in notifications links --- calsocial/models.py | 34 ++++++++++++++++++++++++++ calsocial/templates/notifications.html | 2 +- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/calsocial/models.py b/calsocial/models.py index 36e7ce1..b4312fe 100644 --- a/calsocial/models.py +++ b/calsocial/models.py @@ -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'' + 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'{self.actor}' + item = f'{self.item}' + + return Markup(lazy_gettext(message, actor=actor, item=item)) + class Invitation(db.Model): # pylint: disable=too-few-public-methods """Database model for event invitations diff --git a/calsocial/templates/notifications.html b/calsocial/templates/notifications.html index 3a686b5..f767303 100644 --- a/calsocial/templates/notifications.html +++ b/calsocial/templates/notifications.html @@ -2,6 +2,6 @@ {% block content %} {% for notif in notifs %} -{{ notif.message }}
+{{ notif.html }}
{% endfor %} {% endblock content %}