now admin can accept a request for assigning credits.
authornishanth
Thu, 25 Feb 2010 18:49:17 +0530
changeset 100 2275886511df
parent 99 64c34c1f441f
child 101 e2903a92b5e8
now admin can accept a request for assigning credits.
taskapp/events/request.py
taskapp/utilities/request.py
taskapp/views/user.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/taskapp/events/request.py	Thu Feb 25 18:49:17 2010 +0530
@@ -0,0 +1,37 @@
+from datetime import datetime
+from pytask.taskapp.events.task import addCredits
+
+def reply_to_request(request_obj, reply, replied_by):
+    """
+    makes a request replied with the given reply.
+    arguments:
+        request_obj - Request object for which change is intended
+        reply - a boolean value to be given as reply (True/False)
+        replied_by - the user object who replies to the request
+    """
+    if not request_obj.is_replied:
+        request_obj.reply = reply
+        request_obj.is_replied = True
+        request_obj.reply_date = datetime.now()
+        request_obj.replied_by = replied_by
+        request_obj.save()
+
+        if request_obj.role == "PY":
+            if reply:
+                addCredits(request_obj.task, request_obj.sent_by, request_obj.receiving_user, request_obj.pynts)
+                print "send yes notifications appropriately"
+            else:
+                print "send a no notificvaton"
+        elif request_obj.role == "MT":
+            ## add him as a mentor to the task
+            pass
+        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)
+            else:
+                ## notify request_obj.sent_by that it has been rejected
+                pass
+        return True #Reply has been added successfully
+    return False #Already replied
--- a/taskapp/utilities/request.py	Thu Feb 25 17:56:42 2010 +0530
+++ b/taskapp/utilities/request.py	Thu Feb 25 18:49:17 2010 +0530
@@ -1,6 +1,6 @@
-from pytask.taskapp.models import Request, Profile
 from datetime import datetime
 from django.contrib.auth.models import User
+from pytask.taskapp.models import Request, Profile
 
 def create_request(sent_by,role,sent_to=None,task=None,receiving_user=None,pynts=0):
     """
@@ -29,20 +29,3 @@
         req.sent_to.add(sent_to)
     req.save()
 
-def reply_to_request(request_obj, reply, replied_by):
-    """
-    makes a request replied with the given reply.
-    arguments:
-        request_obj - Request object for which change is intended
-        reply - a boolean value to be given as reply (True/False)
-        replied_by - the user object who replies to the request
-    """
-    if not request_obj.is_replied:
-        request_obj.reply = reply
-        request_obj.is_replied = True
-        request_obj.is_read = True
-        request_obj.reply_date = datetime.now()
-        request_obj.replied_by = replied_by
-        request_obj.save()
-        return True #Reply has been added successfully
-    return False #Already replied
--- a/taskapp/views/user.py	Thu Feb 25 17:56:42 2010 +0530
+++ b/taskapp/views/user.py	Thu Feb 25 18:49:17 2010 +0530
@@ -8,6 +8,7 @@
 from pytask.taskapp.models import Task, Profile, Request
 from pytask.taskapp.events.user import createUser, updateProfile
 from pytask.taskapp.forms.user import UserProfileEditForm
+from pytask.taskapp.events.request import reply_to_request
 
 def show_msg(message, redirect_url=None, url_desc=None):
     """ simply redirect to homepage """
@@ -123,6 +124,8 @@
     user = request.user
     reqs = user.request_sent_to.filter(is_replied=False).order_by('creation_date')
     user_request = reqs[int(rid)]
+    user_request.is_read = True
+    user_request.save()
 
     context = {
         'user':user,
@@ -138,11 +141,14 @@
     if it is get, display a 404 error.
     """
 
+    user = request.user
+
     if request.method=="POST":
-        user = request.user
         browse_request_url= '/user/requests'
         reqs = user.request_sent_to.filter(is_replied=False).order_by('creation_date')
-        user_request = reqs[int(rid)]
+        req_obj = reqs[int(rid)]
+        reply = True if reply == "yes" else False
+        reply_to_request(req_obj, reply, user)
         
         return show_msg("Your reply has been processed", browse_request_url, "view other requests")
     else: