# HG changeset patch # User nishanth # Date 1267308100 -19800 # Node ID e56b952982541e30feb56839a14fb06eae8ab64b # Parent 8632a44b743def8097c2d800f07af4caab6037f9 now requests in sidebar shows the no.of unread notifications. diff -r 8632a44b743d -r e56b95298254 taskapp/utilities/user.py --- /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 + + diff -r 8632a44b743d -r e56b95298254 taskapp/views/user.py --- 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() diff -r 8632a44b743d -r e56b95298254 templates/base.html --- 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 @@
  • home
  • {% if user.is_authenticated %}
  • tasks
  • -
  • notifications
  • -
  • requests
  • +
  • + {% if user.unread_notifications %} + notifications({{user.unread_notifications}}) + {% else %} + notifications + {% endif %} +
  • +
  • + {% if user.unread_requests %} + requests({{user.unread_requests}}) + {% else %} + requests + {% endif %} +

  • my profile
  • logout