now requests in sidebar shows the no.of unread notifications.
authornishanth
Sun, 28 Feb 2010 03:31:40 +0530
changeset 137 e56b95298254
parent 136 8632a44b743d
child 138 c452c699a8af
now requests in sidebar shows the no.of unread notifications.
taskapp/utilities/user.py
taskapp/views/user.py
templates/base.html
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/taskapp/utilities/user.py	Sun Feb 28 03:31:40 2010 +0530
@@ -0,0 +1,17 @@
+"""
+A collection of utility functions for user.
+"""
+
+def get_user(user):
+    """ get the no of unread requests and notifications and add them as properties for user.
+    """
+
+    unread_notifications = user.notification_sent_to.filter(is_read=False,is_deleted=False).count
+    unread_requests = user.request_sent_to.filter(is_valid=True,is_replied=False).count
+
+    user.unread_notifications = unread_notifications
+    user.unread_requests = unread_requests
+
+    return user
+
+
--- a/taskapp/views/user.py	Sun Feb 28 03:01:53 2010 +0530
+++ b/taskapp/views/user.py	Sun Feb 28 03:31:40 2010 +0530
@@ -14,6 +14,7 @@
 
 from pytask.taskapp.utilities.request import get_request
 from pytask.taskapp.utilities.notification import get_notification
+from pytask.taskapp.utilities.user import get_user
 
 about = {
     "addmentors":"about/addmentors.html",
@@ -27,8 +28,8 @@
 
 def homepage(request):
     """ check for authentication and display accordingly. """
-    
-    user = request.user
+   
+    user = get_user(request.user)
     is_guest = False
     is_mentor = False
     can_create_task = False
@@ -43,7 +44,7 @@
         else:
             task_list = Task.objects.order_by('id').reverse()[:10]
             
-        return render_to_response('index.html', {'is_guest':is_guest, 'task_list':task_list})
+        return render_to_response('index.html', {'user':user, 'is_guest':is_guest, 'task_list':task_list})
         
     else:
         user_profile = user.get_profile()
--- a/templates/base.html	Sun Feb 28 03:01:53 2010 +0530
+++ b/templates/base.html	Sun Feb 28 03:31:40 2010 +0530
@@ -131,8 +131,20 @@
             <li><a href="/" title="home">home</a></li>
             {% if user.is_authenticated %}
                 <li><a href="/task/browse/" title="tasks">tasks</a></li>
-                <li><a href="/user/notifications/" title="notifications">notifications</a></li>
-                <li><a href="/user/requests/" title="Requests">requests</a></li>
+                <li><a href="/user/notifications/" title="notifications">
+                {% if user.unread_notifications %}
+                    notifications({{user.unread_notifications}})
+                {% else %}
+                    notifications
+                {% endif %}
+                </a></li>
+                <li><a href="/user/requests/" title="Requests">
+                {% if user.unread_requests %}
+                    requests({{user.unread_requests}})
+                {% else %}
+                    requests
+                {% endif %}
+                </a></li>
                 <br>
                 <li><a href="/user/view/uid={{user.id}}">my profile</a></li>
                 <li><a href="/accounts/logout/">logout</a></li>