diff options
author | nishanth | 2010-02-28 14:44:10 +0530 |
---|---|---|
committer | nishanth | 2010-02-28 14:44:10 +0530 |
commit | 4c7b03f6ca38e30b5394456ea9792e5cd6b4bfde (patch) | |
tree | c328c9b37f356c08c6a472923f78c8a3b88802ec /taskapp | |
parent | 33857f7042c0e72b29a8963b2ee3fe3c9696197b (diff) | |
download | pytask-4c7b03f6ca38e30b5394456ea9792e5cd6b4bfde.tar.gz pytask-4c7b03f6ca38e30b5394456ea9792e5cd6b4bfde.tar.bz2 pytask-4c7b03f6ca38e30b5394456ea9792e5cd6b4bfde.zip |
now if a user accepts to be a mentor, all his pending reqs will be made invalid.
Diffstat (limited to 'taskapp')
-rw-r--r-- | taskapp/events/request.py | 8 | ||||
-rw-r--r-- | taskapp/utilities/user.py | 4 | ||||
-rw-r--r-- | taskapp/views/user.py | 20 |
3 files changed, 21 insertions, 11 deletions
diff --git a/taskapp/events/request.py b/taskapp/events/request.py index 508bc7b..2ad066b 100644 --- a/taskapp/events/request.py +++ b/taskapp/events/request.py @@ -39,6 +39,14 @@ def reply_to_request(request_obj, reply, replied_by): ## tell the replied user that he is mentor for this task and give him learn more link create_notification("NT", request_obj.replied_by, task=task) + ## now check if there are such similar requests and mark them as invalid + ## they cannot be of type PY and so we can use the replied_by to get requests + pending_requests = replied_by.request_sent_to.filter(is_valid=True, is_replied=False, role="MT",task=task) + for req in pending_requests: + create_notification("MT", req.sent_by, replied_by, False, task=req.task, remarks = "User has already accepted one such request and is a mentor.", requested_by = req.sent_by) + req.is_valid = False + req.save() + ## alert all the mentors including who made request and all assigned users for a_mentor in task.mentors.all(): create_notification(request_obj.role, a_mentor, replied_by, True, task, request_obj.remarks, requested_by) diff --git a/taskapp/utilities/user.py b/taskapp/utilities/user.py index bafac0b..79dc22f 100644 --- a/taskapp/utilities/user.py +++ b/taskapp/utilities/user.py @@ -6,8 +6,8 @@ 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 + unread_notifications = user.notification_sent_to.filter(is_read=False,is_deleted=False) + unread_requests = user.request_sent_to.filter(is_valid=True,is_replied=False) user.unread_notifications = unread_notifications user.unread_requests = unread_requests diff --git a/taskapp/views/user.py b/taskapp/views/user.py index dddd2b2..9ccdcaf 100644 --- a/taskapp/views/user.py +++ b/taskapp/views/user.py @@ -13,7 +13,7 @@ from pytask.taskapp.events.request import reply_to_request from pytask.taskapp.forms.user import UserProfileEditForm, UserChoiceForm from pytask.taskapp.utilities.request import get_request, create_request -from pytask.taskapp.utilities.notification import get_notification +from pytask.taskapp.utilities.notification import get_notification, create_notification from pytask.taskapp.utilities.user import get_user about = { @@ -51,16 +51,12 @@ def homepage(request): user_profile = user.get_profile() is_mentor = True if user.task_mentors.all() else False can_create_task = False if user_profile.rights == u"CT" else True - notifications = user.notification_sent_to.filter(is_deleted=False,is_read=False) - requests = user.request_sent_to.filter(is_replied=False) context = {'user':user, 'is_guest':is_guest, 'is_mentor':is_mentor, 'task_list':task_list, 'can_create_task':can_create_task, - 'notifications':notifications, - 'requests':requests, } context["unpublished_tasks"] = user.task_mentors.filter(status="UP") @@ -150,6 +146,7 @@ def view_request(request, rid): """ user = get_user(request.user) + user_rights = user.get_profile().rights newest, newer, user_request, older, oldest = get_request(rid, user) if not user_request: raise Http404 @@ -167,6 +164,15 @@ def view_request(request, rid): 'oldest':oldest, } + ## see if user has already accepted such request and is a high previleged user + ## made_invalid = if ( user_request.role == "DV" and user_rights in ["DV", "MG", "AD"] ) or \ + ## ( user_request.role == "MG" and user_rights in ["MG", "AD"] ) or \ + ## ( user_request.role == "AD" and user_rights == "AD" ) or \ + ## ( user_request.role == "MT" and user.task_mentors.filter(task=request.task) else False + + ## create_notification(user_request.role, user_request.sent_by, user, False, remarks = "User has accepted a similar request and is same or higher privileged than the request", requested_by = user_request.sent_by ) +##def create_notification(role, sent_to, sent_from=None, reply=None, task=None, remarks=None, requested_by=None, receiving_user=None, pynts=None): + return render_to_response('user/view_request.html', context) @login_required @@ -189,10 +195,6 @@ def process_request(request, rid, reply): 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") |