added a utility called getTask in task events and made changes in task views accordingly
authornishanth
Tue, 23 Feb 2010 12:16:28 +0530
changeset 55 ca2486e29178
parent 54 943d682aefdd
child 56 05e10eccd515
added a utility called getTask in task events and made changes in task views accordingly
taskapp/events/task.py
taskapp/views/task.py
--- a/taskapp/events/task.py	Tue Feb 23 11:52:22 2010 +0530
+++ b/taskapp/events/task.py	Tue Feb 23 12:16:28 2010 +0530
@@ -99,3 +99,20 @@
     task.assigned_users.add(user)
     task.status = "AS"
     task.save()
+
+def getTask(tid):
+    """ retreive the task from database.
+    if the task has deps or subs, update its status correspondingly.
+    """
+
+    task = Task.objects.get(id=tid)
+    deps = task.deps.all()
+    subs = task.subs.all()
+
+    if deps and task.status in ["OP", "LO"]:
+        task.status = "OP" if all(map(lambda t:t.status=="CM",deps)) else "LO"
+    if subs and task.status in ["OP", "LO", "CM"]:
+        task.status = "CM" if all(map(lambda t:t.status=="CM",subs)) else "LO"
+
+    task.save()
+    return task
--- a/taskapp/views/task.py	Tue Feb 23 11:52:22 2010 +0530
+++ b/taskapp/views/task.py	Tue Feb 23 12:16:28 2010 +0530
@@ -5,7 +5,7 @@
 
 from pytask.taskapp.models import User, Task, Comment, Claim
 from pytask.taskapp.forms.task import TaskCreateForm, AddMentorForm, AssignTaskForm
-from pytask.taskapp.events.task import createTask, addMentor, publishTask, addSubTask, addClaim, assignTask
+from pytask.taskapp.events.task import createTask, addMentor, publishTask, addSubTask, addClaim, assignTask, getTask
 from pytask.taskapp.views.user import show_msg
 
 ## everywhere if there is no task, django should display 500 message.. but take care of that in sensitive views like add mentor and all
@@ -30,7 +30,7 @@
     task_url = "/task/view/tid=%s"%tid
     
     user = request.user
-    task = Task.objects.get(id=tid)
+    task = getTask(tid)
     comments = Comment.objects.filter(task=task)
     mentors = task.mentors.all()
     errors = []
@@ -55,7 +55,7 @@
     if request.method == 'POST':
         if not is_guest:
             data = request.POST["data"]
-            task = Task.objects.get(id=tid)
+            task = getTask(tid)
             new_comment = Comment(task=task, data=data, created_by=user, creation_datetime=datetime.now())
             new_comment.save()
             return redirect(task_url)
@@ -112,7 +112,7 @@
     task_url = "/task/view/tid=%s"%tid
     
     user = request.user
-    task = Task.objects.get(id=tid)
+    task = getTask(tid)
     errors = []
     
     is_guest = True if not user.is_authenticated() else False
@@ -149,7 +149,7 @@
     task_url = "/task/view/tid=%s"%tid
     
     user = request.user
-    task = Task.objects.get(id=tid)
+    task = getTask(tid)
     errors = []
     
     is_guest = True if not user.is_authenticated() else False
@@ -183,7 +183,7 @@
     errors = []
     
     user = request.user
-    task = Task.objects.get(id=tid)
+    task = getTask(tid)
     claims = Claim.objects.filter(task=task)
     
     is_guest = True if not user.is_authenticated() else False
@@ -227,7 +227,7 @@
     task_url = "/task/view/tid=%s"%tid
     
     user = request.user
-    task = Task.objects.get(id=tid)
+    task = getTask(tid)
     
     is_guest = True if not user.is_authenticated() else False
     is_mentor = True if user in task.mentors.all() else False