diff options
-rw-r--r-- | taskapp/utilities/user.py | 17 | ||||
-rw-r--r-- | taskapp/views/user.py | 7 | ||||
-rw-r--r-- | templates/base.html | 16 |
3 files changed, 35 insertions, 5 deletions
diff --git a/taskapp/utilities/user.py b/taskapp/utilities/user.py new file mode 100644 index 0000000..bafac0b --- /dev/null +++ b/taskapp/utilities/user.py @@ -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 --git a/taskapp/views/user.py b/taskapp/views/user.py index bc578a7..95448fa 100644 --- a/taskapp/views/user.py +++ b/taskapp/views/user.py @@ -14,6 +14,7 @@ from pytask.taskapp.forms.user import UserProfileEditForm 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 show_msg(user, message, redirect_url=None, url_desc=None): 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 @@ def homepage(request): 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 --git a/templates/base.html b/templates/base.html index c6a92c7..4998bb4 100644 --- a/templates/base.html +++ b/templates/base.html @@ -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> |