completed the process_request part.
authornishanth
Fri, 26 Feb 2010 01:13:14 +0530
changeset 107 4903b4973fc8
parent 106 3c3ea2a3f92a
child 108 131554cc3434
completed the process_request part.
taskapp/events/request.py
taskapp/events/user.py
taskapp/models.py
templates/user/view_request.html
--- a/taskapp/events/request.py	Fri Feb 26 00:29:04 2010 +0530
+++ b/taskapp/events/request.py	Fri Feb 26 01:13:14 2010 +0530
@@ -1,5 +1,6 @@
 from datetime import datetime
 from pytask.taskapp.events.task import addCredits, addMentor
+from pytask.taskapp.events.user import changeRole
 
 def reply_to_request(request_obj, reply, replied_by):
     """
@@ -18,6 +19,10 @@
 
         if request_obj.role == "PY":
             if reply:
+                ## note that we are not checking if he is stilla mentor
+                ## since we are not allowing removing mentors
+                ## if we allow, we have complications like removing unreplied requests made by this mentor and stuff.
+                ## but we check if this user is still an admin and put a notification if that you are no longer an admin and hence cannot do this.
                 addCredits(request_obj.task, request_obj.sent_by, request_obj.receiving_user, request_obj.pynts)
                 print "send yes notifications appropriately"
             else:
@@ -25,6 +30,8 @@
         elif request_obj.role == "MT":
             ## add him as a mentor to the task
             if reply:
+                ## check for the current rights of request_obj.sent_by
+                ## what if he is no more a mentor to the task
                 addMentor(request_obj.task, request_obj.replied_by)
                 ## pass on notification of request_obj.sent_by
             else:
@@ -33,9 +40,9 @@
 
         elif request_obj.role in ["AD", "MG", "DV"]:
             if reply:
-                pass
                 ## make him the role
-                ## changeRole(role=request_obj.role, made_by=request_obj.sent_by)
+                ## here we check for rights just in case to be fine with demoted users. we change only the user who made request has that rights.
+                changeRole(role=request_obj.role, user=request_obj.replied_by)
             else:
                 ## notify request_obj.sent_by that it has been rejected
                 pass
--- a/taskapp/events/user.py	Fri Feb 26 00:29:04 2010 +0530
+++ b/taskapp/events/user.py	Fri Feb 26 01:13:14 2010 +0530
@@ -46,3 +46,11 @@
     su_user.is_superuser = True
     su_user.save()
     return su_user
+
+def changeRole(role, user):
+    """ change the status of user to role.
+    """
+
+    user_profile = user.get_profile()
+    user_profile.rights = role
+    user_profile.save()
--- a/taskapp/models.py	Fri Feb 26 00:29:04 2010 +0530
+++ b/taskapp/models.py	Fri Feb 26 01:13:14 2010 +0530
@@ -10,7 +10,7 @@
 GENDER_CHOICES = (( 'M', 'Male'), ('F', 'Female'))
 RIGHTS_CHOICES = (
 	("AD", "Admin"),
-	("MN", "Manager"),
+	("MG", "Manager"),
 	("DV", "Developer"),
 	("CT", "Contributor"),)
 
--- a/templates/user/view_request.html	Fri Feb 26 00:29:04 2010 +0530
+++ b/templates/user/view_request.html	Fri Feb 26 01:13:14 2010 +0530
@@ -16,6 +16,18 @@
     {% ifequal "MT" req.role %}
         <a href="/user/view/uid={{req.sent_by.id}}">{{req.sent_by.username}}</a> requested you to act as a mentor for the task
         <a href="/task/view/tid={{req.task.id}}">{{req.task.title}}</a><br />
+    {% else %}
+        You have been requested to act as 
+        {% ifequal "AD" req.role %}
+            an Admin
+        {% else %}
+            {% ifequal "MG" req.role %}
+                a Manager
+            {% else %}
+                a Developer
+            {% endifequal %}
+        {% endifequal %}
+        for the website by <a href="/user/view/uid={{req.sent_by.id}}">{{req.sent_by.username}}</a>.<br />
     {% endifequal %}
     
     Please accept or reject the request.<br />