created a tag and used it in the template
authorNishanth Amuluru <nishanth@fossee.in>
Fri, 07 Jan 2011 15:16:29 +0530
changeset 298 696309b5ad59
parent 297 1d04840fdcb8
child 299 8f50caa63cd1
created a tag and used it in the template
profile/templatetags/user_tags.py
templates/base.html
--- a/profile/templatetags/user_tags.py	Fri Jan 07 14:57:52 2011 +0530
+++ b/profile/templatetags/user_tags.py	Fri Jan 07 15:16:29 2011 +0530
@@ -0,0 +1,12 @@
+from django import template
+
+register = template.Library()
+
+@register.filter
+def notf_dsp(user):
+
+    notf_cnt = user.notification_sent_to.filter(is_deleted=False,
+                                                is_read=False).count()
+
+    return u'notifications(%s)'%notf_cnt if notf_cnt else u'notifications'
+
--- a/templates/base.html	Fri Jan 07 14:57:52 2011 +0530
+++ b/templates/base.html	Fri Jan 07 15:16:29 2011 +0530
@@ -4,6 +4,7 @@
     {% block js_script %} {% endblock %}
     <link rel=stylesheet href="/static/css/base.css" type="text/css" >
 </head>
+{% load user_tags %}
 <body>
 <div id="wrapper">
     <div id="header">
@@ -17,19 +18,8 @@
                 <li><a href="/task/browse/" title="tasks">tasks</a></li>
                 <li><a href="/textbook/" title="textbook">textbooks</a></li>
                 <br />
-                <li><a href="/user/notifications/" title="notifications">
-                {% if user.unread_notifications.count %}
-                    notifications({{user.unread_notifications.count}})
-                {% else %}
-                    notifications
-                {% endif %}
-                </a></li>
-                <li><a href="/user/requests/" title="Requests">
-                {% if user.unread_requests.count %}
-                    requests({{user.unread_requests.count}})
-                {% else %}
-                    requests
-                {% endif %}
+                <li><a href="/profile/notf/browse/" title="notifications">
+			{{ user|notf_dsp }}
                 </a></li>
                 <br>
                 <li><a href="/profile/view">profile</a></li>