now if a user accepts to be a mentor, all his pending reqs will be made invalid.
authornishanth
Sun, 28 Feb 2010 14:44:10 +0530
changeset 143 796ff9e279a8
parent 142 bd65e2c9a7b4
child 144 581ad20b8c39
now if a user accepts to be a mentor, all his pending reqs will be made invalid.
taskapp/events/request.py
taskapp/utilities/user.py
taskapp/views/user.py
templates/base.html
templates/index.html
--- a/taskapp/events/request.py	Sun Feb 28 13:27:43 2010 +0530
+++ b/taskapp/events/request.py	Sun Feb 28 14:44:10 2010 +0530
@@ -39,6 +39,14 @@
                 ## 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)
--- a/taskapp/utilities/user.py	Sun Feb 28 13:27:43 2010 +0530
+++ b/taskapp/utilities/user.py	Sun Feb 28 14:44:10 2010 +0530
@@ -6,8 +6,8 @@
     """ 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
--- a/taskapp/views/user.py	Sun Feb 28 13:27:43 2010 +0530
+++ b/taskapp/views/user.py	Sun Feb 28 14:44:10 2010 +0530
@@ -13,7 +13,7 @@
 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 @@
         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 @@
     """
 
     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 @@
         '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 @@
 
         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")
--- a/templates/base.html	Sun Feb 28 13:27:43 2010 +0530
+++ b/templates/base.html	Sun Feb 28 14:44:10 2010 +0530
@@ -132,15 +132,15 @@
             {% if user.is_authenticated %}
                 <li><a href="/task/browse/" title="tasks">tasks</a></li>
                 <li><a href="/user/notifications/" title="notifications">
-                {% if user.unread_notifications %}
-                    notifications({{user.unread_notifications}})
+                {% if user.unread_notifications.count %}
+                    notifications({{user.unread_notifications.count}})
                 {% else %}
                     notifications
                 {% endif %}
                 </a></li>
                 <li><a href="/user/requests/" title="Requests">
-                {% if user.unread_requests %}
-                    requests({{user.unread_requests}})
+                {% if user.unread_requests.count %}
+                    requests({{user.unread_requests.count}})
                 {% else %}
                     requests
                 {% endif %}
--- a/templates/index.html	Sun Feb 28 13:27:43 2010 +0530
+++ b/templates/index.html	Sun Feb 28 14:44:10 2010 +0530
@@ -12,18 +12,18 @@
         Logged in as {{ user.username }} <br />
     {% endif %}
     
-    {% if notifications.count %}
-        You have {{ notifications.count }} <a href='/user/notifications/'>unread</a>
-        {% ifnotequal notifications.count 1 %}
+    {% if user.unread_notifications.count %}
+        You have {{ user.unread_notifications.count }} <a href='/user/notifications/'>unread</a>
+        {% ifnotequal user.unread_notifications.count 1 %}
         notifications
         {% else %}
         notification
         {% endifnotequal %}<br />
     {% endif %}
     
-    {% if requests.count %}
-        You have {{ requests.count }}  <a href='/user/requests/'>unreplied</a>
-        {% ifnotequal requests.count 1 %}
+    {% if user.unread_requests.count %}
+        You have {{ user.unread_requests.count }}  <a href='/user/requests/'>unreplied</a>
+        {% ifnotequal user.unread_requests.count 1 %}
         requests
         {% else %}
         request