in pontoon/base/models/user.py [0:0]
def serialized_notifications(self):
"""Serialized list of notifications to display in the notifications menu."""
unread_count = self.notifications.unread().count()
count = settings.NOTIFICATIONS_MAX_COUNT
notifications = []
if unread_count > count:
count = unread_count
for notification in self.notifications.prefetch_related(
"actor", "target", "action_object"
)[:count]:
actor = None
is_comment = False
if hasattr(notification.actor, "slug"):
if "new string" in notification.verb:
actor = {
"anchor": notification.actor.name,
"url": reverse(
"pontoon.translate.locale.agnostic",
kwargs={
"slug": notification.actor.slug,
"part": "all-resources",
},
)
+ "?status=missing,pretranslated",
}
else:
actor = {
"anchor": notification.actor.name,
"url": reverse(
"pontoon.projects.project",
kwargs={"slug": notification.actor.slug},
),
}
elif hasattr(notification.actor, "email"):
actor = {
"anchor": notification.actor.name_or_email,
"url": reverse(
"pontoon.contributors.contributor.username",
kwargs={"username": notification.actor.username},
),
}
target = None
if notification.target:
t = notification.target
# New string or Manual notification
if hasattr(t, "slug"):
target = {
"anchor": t.name,
"url": reverse(
"pontoon.projects.project",
kwargs={"slug": t.slug},
),
}
# Comment notifications
elif hasattr(t, "resource"):
is_comment = True
target = {
"anchor": t.resource.project.name,
"url": reverse(
"pontoon.translate",
kwargs={
"locale": notification.action_object.code,
"project": t.resource.project.slug,
"resource": t.resource.path,
},
)
+ f"?string={t.pk}",
}
notifications.append(
{
"id": notification.id,
"level": notification.level,
"unread": notification.unread,
"description": {
"content": notification.description,
"is_comment": is_comment,
},
"verb": notification.verb,
"date": notification.timestamp.strftime("%b %d, %Y %H:%M"),
"date_iso": notification.timestamp.isoformat(),
"actor": actor,
"target": target,
}
)
return {
"has_unread": unread_count > 0,
"notifications": notifications,
"unread_count": str(self.unread_notifications_display(unread_count)),
}