summaryrefslogtreecommitdiff
path: root/taskapp
diff options
context:
space:
mode:
authornishanth2010-02-28 01:15:15 +0530
committernishanth2010-02-28 01:15:15 +0530
commitdd86c8bb2880c7ea434cc221ea1b46802300ff67 (patch)
tree46fbc59b4985192b62e97eba9bbb6038b562bac9 /taskapp
parent19c262de98b4e20dd88eb3e7692a3c2de076a838 (diff)
downloadpytask-dd86c8bb2880c7ea434cc221ea1b46802300ff67.tar.gz
pytask-dd86c8bb2880c7ea434cc221ea1b46802300ff67.tar.bz2
pytask-dd86c8bb2880c7ea434cc221ea1b46802300ff67.zip
added next and previous capabilities to requests and notifications.
Diffstat (limited to 'taskapp')
-rw-r--r--taskapp/utilities/notification.py42
-rw-r--r--taskapp/utilities/request.py34
-rw-r--r--taskapp/views/user.py29
3 files changed, 74 insertions, 31 deletions
diff --git a/taskapp/utilities/notification.py b/taskapp/utilities/notification.py
index 881f1b1..4e7396d 100644
--- a/taskapp/utilities/notification.py
+++ b/taskapp/utilities/notification.py
@@ -71,18 +71,17 @@ def create_notification(role, sent_to, sent_from=None, reply=None, task=None, re
elif role in ["DV", "MG", "AD"]:
accepting_user = sent_from
- user_url = '<a href="/user/view/uid=%s">%s</a>'%(accepting_user.id,accepting_user.username) ## i mean the user who has accepted it
- requested_by_url = '<a href="/user/view/uid=%s">%s</a>'%(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.<br />"%(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.<br />"(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.<br />"%(user_url, a_or_an, role_rights)
+ notification.message = "%s has rejected your request asking him to act as a %s.<br />"%(new_mentor_url, task_url)
if remarks:
notification.message += "Remarks: %s<br />"%remarks
@@ -110,7 +109,6 @@ def create_notification(role, sent_to, sent_from=None, reply=None, task=None, re
notification.save()
-
def mark_notification_read(notification_id):
"""
makes a notification identified by the notification_id read.
@@ -144,10 +142,28 @@ def get_notification(nid, user):
else return None.
"""
- try:
- notify_obj = Notification.objects.get(id=nid)
- except Notification.DoesNotExist:
- return None
-
- if notify_obj.sent_to == user and ( not notify_obj.is_deleted ):
- return notify_obj
+ 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
+
+ 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 --git a/taskapp/utilities/request.py b/taskapp/utilities/request.py
index 6b43596..9a61291 100644
--- a/taskapp/utilities/request.py
+++ b/taskapp/utilities/request.py
@@ -35,16 +35,28 @@ def get_request(rid, user):
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
- else:
try:
- request_obj.sent_to.get(id=user.id)
- except User.DoesNotExist:
- return None
- return request_obj
+ 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:
+ return None, None, None, None, None
diff --git a/taskapp/views/user.py b/taskapp/views/user.py
index 91334ad..bc578a7 100644
--- a/taskapp/views/user.py
+++ b/taskapp/views/user.py
@@ -144,7 +144,7 @@ def view_request(request, rid):
"""
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 @@ def view_request(request, rid):
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 @@ def process_request(request, rid, reply):
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 @@ def process_request(request, rid, reply):
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 @@ def view_notification(request, nid):
"""
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 @@ def view_notification(request, nid):
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 @@ def edit_notification(request, nid, action):
"""
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 @@ def edit_notification(request, nid, action):
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")