moved the getTask method to task_utilities.
authornishanth
Fri, 26 Feb 2010 16:15:58 +0530
changeset 120 aad4e6065d85
parent 119 39ab7c460143
child 121 0c568378a4bc
moved the getTask method to task_utilities.
taskapp/events/task.py
taskapp/utilities/task.py
taskapp/views/task.py
urls.py
--- a/taskapp/events/task.py	Fri Feb 26 16:02:32 2010 +0530
+++ b/taskapp/events/task.py	Fri Feb 26 16:15:58 2010 +0530
@@ -1,5 +1,6 @@
 from datetime import datetime
 from pytask.taskapp.models import Profile, Task, Comment, Credit, Claim, Map
+from pytask.taskapp.utilities.task import getTask
 from pytask.taskapp.utilities.request import create_request
 from pytask.taskapp.utilities.helper import get_key
 
@@ -150,34 +151,6 @@
         task.status = "WR"
     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)
-    try:
-        mapobj = Map.objects.get(main=task)
-    except Map.DoesNotExist:
-        mapobj = Map()
-        mapobj.main = task
-        mapobj.save()
-        
-    task_subs = mapobj.subs.all()
-
-    if task.sub_type == "D":
-        task.deps, task.subs = task_subs, []
-    elif task.sub_type == "S":
-        task.subs, task.deps = task_subs, []
-
-    deps, subs = task.deps, task.subs
-    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
 
 def updateTask(task, title=None, desc=None, credits=None, tags_field=None):
     """ update the property accordingly.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/taskapp/utilities/task.py	Fri Feb 26 16:15:58 2010 +0530
@@ -0,0 +1,35 @@
+from django.http import Http404
+from pytask.taskapp.models import Task, Map
+
+def getTask(tid):
+    """ retreive the task from database.
+    if the task has deps or subs, update its status correspondingly.
+    """
+
+    try:
+        task = Task.objects.get(id=tid)
+    except Task.DoesNotExist:
+        raise Http404
+    try:
+        mapobj = Map.objects.get(main=task)
+    except Map.DoesNotExist:
+        mapobj = Map()
+        mapobj.main = task
+        mapobj.save()
+        
+    task_subs = mapobj.subs.all()
+
+    if task.sub_type == "D":
+        task.deps, task.subs = task_subs, []
+    elif task.sub_type == "S":
+        task.subs, task.deps = task_subs, []
+
+    deps, subs = task.deps, task.subs
+    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	Fri Feb 26 16:02:32 2010 +0530
+++ b/taskapp/views/task.py	Fri Feb 26 16:15:58 2010 +0530
@@ -4,8 +4,9 @@
 from django.shortcuts import render_to_response, redirect
 
 from pytask.taskapp.models import User, Task, Comment, Claim, Credit
+from pytask.taskapp.utilities.task import getTask
 from pytask.taskapp.forms.task import TaskCreateForm, AddMentorForm, AddTaskForm, ChoiceForm, AssignCreditForm, RemoveUserForm
-from pytask.taskapp.events.task import createTask, reqMentor, publishTask, addSubTask, addDep, addClaim, assignTask, getTask, updateTask, removeTask, removeUser, assignCredits, completeTask
+from pytask.taskapp.events.task import createTask, reqMentor, publishTask, addSubTask, addDep, addClaim, assignTask, updateTask, removeTask, removeUser, assignCredits, completeTask
 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
--- a/urls.py	Fri Feb 26 16:02:32 2010 +0530
+++ b/urls.py	Fri Feb 26 16:15:58 2010 +0530
@@ -24,19 +24,19 @@
     (r'^$', userViews.homepage),
     
     (r'^task/browse/$', taskViews.browse_tasks),
-    (r'^task/view/tid=(\d+)$', taskViews.view_task),
+    (r'^task/view/tid=(\w+)$', taskViews.view_task),
     (r'^task/create/$', taskViews.create_task),
-    (r'task/publish/tid=(\d+)/$', taskViews.publish_task),
-    (r'^task/addmentor/tid=(\d+)$', taskViews.add_mentor),
-    #(r'^task/addtasks/tid=(\d+)', taskViews.add_tasks),
-    (r'^task/edit/tid=(\d+)$', taskViews.edit_task),
-    (r'^task/claim/tid=(\d+)$', taskViews.claim_task),
-    (r'^task/assign/tid=(\d+)$', taskViews.assign_task),
-    (r'^task/remuser/tid=(\d+)$', taskViews.rem_user),
-    (r'^task/addtask/tid=(\d+)$', taskViews.add_tasks),
-    (r'^task/remtask/tid=(\d+)$', taskViews.remove_task),
-    (r'^task/assigncredits/tid=(\d+)$', taskViews.assign_credits),
-    (r'^task/complete/tid=(\d+)$', taskViews.complete_task),
+    (r'task/publish/tid=(\w+)/$', taskViews.publish_task),
+    (r'^task/addmentor/tid=(\w+)$', taskViews.add_mentor),
+    #(r'^task/addtasks/tid=(\w+)', taskViews.add_tasks),
+    (r'^task/edit/tid=(\w+)$', taskViews.edit_task),
+    (r'^task/claim/tid=(\w+)$', taskViews.claim_task),
+    (r'^task/assign/tid=(\w+)$', taskViews.assign_task),
+    (r'^task/remuser/tid=(\w+)$', taskViews.rem_user),
+    (r'^task/addtask/tid=(\w+)$', taskViews.add_tasks),
+    (r'^task/remtask/tid=(\w+)$', taskViews.remove_task),
+    (r'^task/assigncredits/tid=(\w+)$', taskViews.assign_credits),
+    (r'^task/complete/tid=(\w+)$', taskViews.complete_task),
     
     (r'^admin/', include(admin.site.urls)),