Commit 0964aa9c by Őry Máté

Merge branch 'feature-dashboard-context-processor'

Feature dashboard context processor

Change company name in footer via settings file and display notifications on
all pages.

closes #50
parents 2d93fe93 9af13b05
......@@ -171,6 +171,8 @@ TEMPLATE_CONTEXT_PROCESSORS = (
'django.core.context_processors.tz',
'django.contrib.messages.context_processors.messages',
'django.core.context_processors.request',
'dashboard.context_processors.notifications',
'dashboard.context_processors.extract_settings',
)
# See: https://docs.djangoproject.com/en/dev/ref/settings/#template-loaders
......@@ -395,3 +397,4 @@ if get_env_variable('DJANGO_SAML', 'FALSE') == 'TRUE':
LOGIN_REDIRECT_URL = "/"
LOCALE_PATHS = (join(SITE_ROOT, 'locale'), )
COMPANY_NAME = "BME IK 2014"
from django.conf import settings
def notifications(request):
count = (request.user.notification_set.filter(status="new").count()
if request.user.is_authenticated() else None)
return {
'NEW_NOTIFICATIONS_COUNT': count
}
def extract_settings(request):
return {
'COMPANY_NAME': getattr(settings, "COMPANY_NAME", None),
}
......@@ -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>
......@@ -69,7 +75,7 @@
<footer>
<a href="#">{% trans "Legal notice" %}</a> | <a href="#">{% trans "Policy" %}</a> | <a href="#">{% trans "Help" %}</a> |
<a href="#">{% trans "Support" %}</a>
<span class="pull-right">&copy; BME IK 2014</span>
<span class="pull-right">&copy; {{ COMPANY_NAME }}</span>
</footer>
</body>
{% block extra_js %}
......
......@@ -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">
......
......@@ -736,3 +736,14 @@ class IndexViewTest(LoginMixin, TestCase):
response = c.get("/dashboard/")
self.assertEqual(response.status_code, 200)
self.assertTrue("nodes" in response.context)
def test_context_processor_notifications(self):
c = Client()
self.login(c, "user1")
response = c.get("/dashboard/")
self.assertEqual(response.context['NEW_NOTIFICATIONS_COUNT'], 0)
self.u1.profile.notify("urgent", "dashboard/test_message.txt", )
response = c.get("/dashboard/")
self.assertEqual(response.context['NEW_NOTIFICATIONS_COUNT'], 1)
......@@ -105,10 +105,6 @@ class IndexView(LoginRequiredMixin, TemplateView):
'stopped_vm_num': stopped.count()
})
# notifications
context['new_notifications'] = user.notification_set.filter(
status="new").count()
# nodes
if user.is_superuser:
nodes = Node.objects.all()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment