diff options
author | nishanth | 2010-02-28 01:15:15 +0530 |
---|---|---|
committer | nishanth | 2010-02-28 01:15:15 +0530 |
commit | dd86c8bb2880c7ea434cc221ea1b46802300ff67 (patch) | |
tree | 46fbc59b4985192b62e97eba9bbb6038b562bac9 /taskapp/utilities | |
parent | 19c262de98b4e20dd88eb3e7692a3c2de076a838 (diff) | |
download | pytask-dd86c8bb2880c7ea434cc221ea1b46802300ff67.tar.gz pytask-dd86c8bb2880c7ea434cc221ea1b46802300ff67.tar.bz2 pytask-dd86c8bb2880c7ea434cc221ea1b46802300ff67.zip |
added next and previous capabilities to requests and notifications.
Diffstat (limited to 'taskapp/utilities')
-rw-r--r-- | taskapp/utilities/notification.py | 42 | ||||
-rw-r--r-- | taskapp/utilities/request.py | 34 |
2 files changed, 52 insertions, 24 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 |