diff --git a/circle/circle/settings/base.py b/circle/circle/settings/base.py index b3a12ce..bd3fd01 100644 --- a/circle/circle/settings/base.py +++ b/circle/circle/settings/base.py @@ -171,6 +171,7 @@ TEMPLATE_CONTEXT_PROCESSORS = ( 'django.core.context_processors.tz', 'django.contrib.messages.context_processors.messages', 'django.core.context_processors.request', + 'dashboard.context_processors.notifications', ) # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-loaders diff --git a/circle/dashboard/context_processors.py b/circle/dashboard/context_processors.py new file mode 100644 index 0000000..505a8d2 --- /dev/null +++ b/circle/dashboard/context_processors.py @@ -0,0 +1,6 @@ +def notifications(request): + count = (request.user.notification_set.filter(status="new").count() + if request.user.is_authenticated() else None) + return { + 'NEW_NOTIFICATIONS_COUNT': count + } diff --git a/circle/dashboard/templates/dashboard/base.html b/circle/dashboard/templates/dashboard/base.html index 1e2a3fa..9c474fa 100644 --- a/circle/dashboard/templates/dashboard/base.html +++ b/circle/dashboard/templates/dashboard/base.html @@ -33,8 +33,14 @@ </div><!-- .navbar-header --> <div class="collapse navbar-collapse"> <ul class="nav navbar-nav pull-right"> - {% block navbar-ul %} - {% endblock %} + <li class="dropdown" id="notification-button"> + <a href="{% url "dashboard.views.notifications" %}" style="color: white; font-size: 12px;" class="dropdown-toggle" data-toggle="dropdown"> + {% trans "Notifications" %}{% if NEW_NOTIFICATIONS_COUNT > 0 %} <span class="badge">{{ NEW_NOTIFICATIONS_COUNT }}</span>{% endif %} + </a> + <ul class="dropdown-menu notification-messages"> + <li>{% trans "Loading..." %}</li> + </ul> + </li> </ul> {% if user.is_authenticated %} <a class="navbar-brand pull-right" href="{% url "logout" %}?next={% url "login" %}" style="color: white; font-size: 10px;"><i class="icon-signout icon-sign-out"></i> {% trans "Log out" %}</a> diff --git a/circle/dashboard/templates/dashboard/index.html b/circle/dashboard/templates/dashboard/index.html index c4cb820..f749142 100644 --- a/circle/dashboard/templates/dashboard/index.html +++ b/circle/dashboard/templates/dashboard/index.html @@ -3,17 +3,6 @@ {% block title-page %}{% trans "Dashboard" %}{% endblock %} -{% block navbar-ul %} - <li class="dropdown" id="notification-button"> - <a href="{% url "dashboard.views.notifications" %}" style="color: white; font-size: 12px;" class="dropdown-toggle" data-toggle="dropdown"> - {% trans "Notifications" %}{% if new_notifications %} <span class="badge">{{ new_notifications }}</span>{% endif %} - </a> - <ul class="dropdown-menu notification-messages"> - <li>{% trans "Loading..." %}</li> - </ul> - </li> -{% endblock %} - {% block content %} <div class="body-content dashboard-index"> <div class="row">