diff --git a/mayan/apps/appearance/templates/navigation/generic_link_instance.html b/mayan/apps/appearance/templates/navigation/generic_link_instance.html
index ae37c959ee..23c3cc88ab 100644
--- a/mayan/apps/appearance/templates/navigation/generic_link_instance.html
+++ b/mayan/apps/appearance/templates/navigation/generic_link_instance.html
@@ -13,6 +13,12 @@
{% endfor %}
href="{{ link.url }}"
- >{% if link.icon %}{% if not hide_icon %}{% endif %}{% endif %}{% if link.icon_class and not hide_icon %}{{ link.icon_class.render }}{% endif %} {{ link.text }}{% if link.error %} - {{ link.error }}{% endif %}{% if horizontal %}{% if not forloop.last %} {% endif %}{% endif %}
+ >{% if link.icon %}{% if not hide_icon %}
+
+ {% endif %}{% endif %}
+ {% if link.icon_class and not hide_icon %}{{ link.icon_class.render }}{% endif %}
+ {{ link.text|default:'' }}{% if link.badge_text %} {{ link.badge_text }}
+ {% endif %}{% if link.error %} - {{ link.error }}{% endif %}
+ {% if horizontal %}{% if not forloop.last %} {% endif %}{% endif %}
{% endif %}
{% endif %}
diff --git a/mayan/apps/events/links.py b/mayan/apps/events/links.py
index 7e069cd1ba..cbd29f22e6 100644
--- a/mayan/apps/events/links.py
+++ b/mayan/apps/events/links.py
@@ -32,8 +32,13 @@ def get_kwargs_factory(variable_name):
return get_kwargs
-def get_notification_count(context):
- return context['request'].user.notifications.filter(read=False).count()
+def get_unread_notification_count(context):
+ Notification = apps.get_model(
+ app_label='events', model_name='Notification'
+ )
+ return Notification.objects.filter(
+ user=context.request.user
+ ).filter(read=False).count()
link_events_list = Link(
@@ -72,6 +77,7 @@ link_user_events = Link(
view='events:user_events'
)
link_user_notifications_list = Link(
+ badge_text=get_unread_notification_count,
icon_class=icon_user_notifications_list, text='',
view='events:user_notifications_list'
)
diff --git a/mayan/apps/navigation/classes.py b/mayan/apps/navigation/classes.py
index 905b4bc652..d035aee7e7 100644
--- a/mayan/apps/navigation/classes.py
+++ b/mayan/apps/navigation/classes.py
@@ -34,6 +34,11 @@ class ResolvedLink(object):
def active(self):
return self.link.view == self.current_view
+ @property
+ def badge_text(self):
+ if self.link.badge_text:
+ return self.link.badge_text(context=self.context)
+
@property
def description(self):
return self.link.description
@@ -303,7 +308,7 @@ class Link(object):
def remove(cls, name):
del cls._registry[name]
- def __init__(self, text, view=None, args=None, condition=None,
+ def __init__(self, badge_text=None, text=None, view=None, args=None, condition=None,
conditional_disable=None, description=None, html_data=None,
html_extra_classes=None, icon=None, icon_class=None,
keep_query=False, kwargs=None, name=None, permissions=None,
@@ -311,6 +316,7 @@ class Link(object):
url=None):
self.args = args or []
+ self.badge_text = badge_text
self.condition = condition
self.conditional_disable = conditional_disable
self.description = description