# HG changeset patch # User nishanth # Date 1267299915 -19800 # Node ID 34187a80d27955e6ec3dd88540c6f9e5ed6128cc # Parent ca88bf4ad362224af129dfbebdb839af2a5eca18 added next and previous capabilities to requests and notifications. diff -r ca88bf4ad362 -r 34187a80d279 taskapp/utilities/notification.py --- a/taskapp/utilities/notification.py Sat Feb 27 19:21:15 2010 +0530 +++ b/taskapp/utilities/notification.py Sun Feb 28 01:15:15 2010 +0530 @@ -71,18 +71,17 @@ elif role in ["DV", "MG", "AD"]: accepting_user = sent_from - user_url = '%s'%(accepting_user.id,accepting_user.username) ## i mean the user who has accepted it - requested_by_url = '%s'%(requested_by.id,requested_by.username) + user_url = "/user/view/uid=%s"%(accepting_user.id) ## i mean the user who has accepted it + requested_by_url = "/user/view/uid=%s"%(requested_by.id) role_rights = dict(RIGHTS_CHOICES)[role] role_learn_url = "/about/%s"%role_rights.lower() - a_or_an = "an" if role == "AD" else "a" if reply: notification.sub = "New %s for the site"%role_rights - notification.message = "%s has accepted request made by %s asking him to act as %s %s for the website.
"%(user_url, requested_by_url, a_or_an, role_rights) + notification.message = "%s has accepted request made by %s asking him to act as a %s for the website.
"(user_url, requested_by_url, role_rights) else: notification.sub = "Rejected your request to act as %s"%role_rights - notification.message = "%s has rejected your request asking him to act as %s %s for the website.
"%(user_url, a_or_an, role_rights) + notification.message = "%s has rejected your request asking him to act as a %s.
"%(new_mentor_url, task_url) if remarks: notification.message += "Remarks: %s
"%remarks @@ -110,7 +109,6 @@ notification.save() - def mark_notification_read(notification_id): """ makes a notification identified by the notification_id read. @@ -144,10 +142,28 @@ else return None. """ - try: - notify_obj = Notification.objects.get(id=nid) - except Notification.DoesNotExist: - return None + user_notifications = user.notification_sent_to.filter(is_deleted=False).order_by('sent_date') + current_notifications = user_notifications.filter(id=nid) + if user_notifications: + current_notification = current_notifications[0] + + try: + newer_notification = current_notification.get_next_by_sent_date(sent_to=user, is_deleted=False) + newest_notification = user_notifications.reverse()[0] + if newest_notification == newer_notification: + newest_notification = None + except Notification.DoesNotExist: + newest_notification, newer_notification = None, None - if notify_obj.sent_to == user and ( not notify_obj.is_deleted ): - return notify_obj + try: + older_notification = current_notification.get_previous_by_sent_date(sent_to=user, is_deleted=False) + oldest_notification = user_notifications[0] + if oldest_notification == older_notification: + oldest_notification = None + except: + oldest_notification, older_notification = None, None + + return newest_notification, newer_notification, current_notification, older_notification, oldest_notification + + else: + return None, None, None, None, None diff -r ca88bf4ad362 -r 34187a80d279 taskapp/utilities/request.py --- a/taskapp/utilities/request.py Sat Feb 27 19:21:15 2010 +0530 +++ b/taskapp/utilities/request.py Sun Feb 28 01:15:15 2010 +0530 @@ -35,16 +35,28 @@ raise 404 error. else return request. """ - try: - request_obj = Request.objects.get(id=rid) - except Request.DoesNotExist: - return None + active_requests = user.request_sent_to.filter(is_valid=True, is_replied=False).order_by('creation_date') + current_requests = active_requests.filter(id=rid) + if current_requests: + current_request = current_requests[0] + + try: + newer_request = current_request.get_next_by_creation_date(sent_to=user, is_replied=False, is_valid=True) + newest_request = active_requests.reverse()[0] + if newer_request == newest_request: + newest_request = None + except Request.DoesNotExist: + newer_request, newest_request = None, None - if request_obj.is_replied == True: - return None + try: + older_request = current_request.get_previous_by_creation_date(sent_to=user, is_replied=False, is_valid=True) + oldest_request = active_requests[0] + if oldest_request == older_request: + oldest_request = None + except Request.DoesNotExist: + older_request, oldest_request = None, None + + return newest_request, newer_request, current_request, older_request, oldest_request + else: - try: - request_obj.sent_to.get(id=user.id) - except User.DoesNotExist: - return None - return request_obj + return None, None, None, None, None diff -r ca88bf4ad362 -r 34187a80d279 taskapp/views/user.py --- a/taskapp/views/user.py Sat Feb 27 19:21:15 2010 +0530 +++ b/taskapp/views/user.py Sun Feb 28 01:15:15 2010 +0530 @@ -144,7 +144,7 @@ """ user = request.user - user_request = get_request(rid, user) + newest, newer, user_request, older, oldest = get_request(rid, user) if not user_request: raise Http404 @@ -154,7 +154,11 @@ context = { 'user':user, 'req':user_request, - 'sent_users':user_request.sent_to.all() + 'sent_users':user_request.sent_to.all(), + 'newest':newest, + 'newer':newer, + 'older':older, + 'oldest':oldest, } return render_to_response('user/view_request.html', context) @@ -167,7 +171,7 @@ user = request.user browse_request_url= '/user/requests' - req_obj = get_request(rid, user) + newest, newer, req_obj, older, oldest = get_request(rid, user) if not req_obj: return show_msg(user, "Your reply has been processed", browse_request_url, "view other requests") @@ -178,7 +182,11 @@ req_obj.save() reply_to_request(req_obj, reply, user) - + + if older: + return redirect('/user/requests/rid=%s'%older.id) + else: + return redirect(browse_request_url) return show_msg(user, "Your reply has been processed", browse_request_url, "view other requests") else: return show_msg(user, "You are not authorised to do this", browse_request_url, "view other requests") @@ -206,7 +214,7 @@ """ user = request.user - notification = get_notification(nid, user) + newest, newer, notification, older, oldest = get_notification(nid, user) if not notification: raise Http404 @@ -216,6 +224,10 @@ context = { 'user':user, 'notification':notification, + 'newest':newest, + 'newer':newer, + 'older':older, + 'oldest':oldest, } return render_to_response('user/view_notification.html', context) @@ -228,7 +240,7 @@ """ user = request.user - notification = get_notification(nid, user) + newest, newer, notification, older, oldest = get_notification(nid, user) if not notification: raise Http404 @@ -242,7 +254,10 @@ notification.is_read = False notification.save() - return redirect(notifications_url) + if older: + return redirect('/user/notifications/nid=%s'%older.id) + else: + return redirect(notifications_url) else: return show_msg(user, 'This is wrong', notification_url, "view the notification") diff -r ca88bf4ad362 -r 34187a80d279 templates/user/view_notification.html --- a/templates/user/view_notification.html Sat Feb 27 19:21:15 2010 +0530 +++ b/templates/user/view_notification.html Sun Feb 28 01:15:15 2010 +0530 @@ -1,10 +1,24 @@ {% extends 'base.html' %} {% block content %} + {% if newest %} + <<newest + {% endif %} + {% if newer %} + <newer + {% endif %} + {% if older %} + older> + {% endif %} + {% if oldest %} + oldest>> + {% endif %} +
+ +
+
+
sent at {{notification.sent_date}}
Sub: {{notification.sub}}
-
{{notification.message|safe}} -
-
{% endblock %} diff -r ca88bf4ad362 -r 34187a80d279 templates/user/view_request.html --- a/templates/user/view_request.html Sat Feb 27 19:21:15 2010 +0530 +++ b/templates/user/view_request.html Sun Feb 28 01:15:15 2010 +0530 @@ -1,11 +1,25 @@ {% extends 'base.html' %} {% block content %} + {% if newest %} + <<newest + {% endif %} + {% if newer %} + <newer + {% endif %} + {% if older %} + older> + {% endif %} + {% if oldest %} + oldest>> + {% endif %} +
From:  {{req.sent_by.username}}
To: {% for to_user in sent_users %} - {{to_user.username}},  + {{to_user.username}}  {% endfor %}
+ sent at {{req.creation_date}}
Message:
{% ifequal "PY" req.role %} {{req.sent_by.username}} assigned {{req.pynts}} pynts to