From fde938bb05d0444568b044487d6865b2dfc7608c Mon Sep 17 00:00:00 2001
From: nishanth
Date: Wed, 24 Feb 2010 10:42:46 +0530
Subject: added events in task.py for adding subtask and dependencies

---
 taskapp/events/task.py | 35 +++++++++++++++++++++++------------
 taskapp/models.py      |  4 +---
 2 files changed, 24 insertions(+), 15 deletions(-)

diff --git a/taskapp/events/task.py b/taskapp/events/task.py
index 4fcf90f..3712dbd 100644
--- a/taskapp/events/task.py
+++ b/taskapp/events/task.py
@@ -15,7 +15,7 @@ def publishTask(task):
 
 def addSubTask(main_task, sub_task):
     """ add the task to subs attribute of the task and update its status.
-    sub task can be added only if a task is in UP/OP/LO/Cd state.
+    sub task can be added only if a task is in UP/OP/LO state.
     """
 
     ## Shall modify after talking to pr about subtasks
@@ -70,21 +70,12 @@ def createTask(title,desc,created_by,credits):
     task.save()
     return task
 
-def addSubTask(main_task, sub_task):
-    """ add sub_task to subs list of main_task """
-    
-    main_task.subs.add(sub_task)
-    main_task.status = "LO"
-    main_task.save()
-    return main_task
-
 def addClaim(task, message, user):
     """ add claim data to the database if it does not exist 
     and also update the claimed users field of the task.
     """
     
     task.claimed_users.add(user)
-    task.status = "CL"
     task.save()
     claim = Claim()
     claim.message = message
@@ -96,8 +87,10 @@ def addClaim(task, message, user):
 def assignTask(task, user):
     """ check for the status of task and assign it to the particular user """
     
-    task.assigned_users.add(user)
-    task.status = "AS"
+    if task.status in ['OP', 'WR']:
+        task.assigned_users.add(user)
+        task.claimed_users.remove(user)
+        task.status = "WR"
     task.save()
 
 def getTask(tid):
@@ -116,3 +109,21 @@ def getTask(tid):
 
     task.save()
     return task
+
+def updateTask(task, title=None, desc=None, credits=None, tags_field=None):
+    """ update the property accordingly.
+    while updating title, check for uniqueness of title.
+    return None if any error. 
+    """
+    
+    if title:
+        try:
+            task.title = title
+            task.save()
+        except IntegrityError:
+            return None
+    if desc:task.desc = desc
+    if credits:task.credits = credits
+    if tags_field:task.tags_field = tags_field
+    task.save()
+    return task
diff --git a/taskapp/models.py b/taskapp/models.py
index eb5130a..62458ac 100644
--- a/taskapp/models.py
+++ b/taskapp/models.py
@@ -18,9 +18,7 @@ STATUS_CHOICES = (
     ("UP", "Unpublished"),
     ("OP", "Open"),
     ("LO", "Locked"),
-    ("CL", "Claimed"),
-    ("AS", "Assigned"),
-    ("RE", "Reopened"),
+    ("WR", "Working"),
     ("CD", "Closed"),
     ("DL", "Deleted"),
     ("CM", "Completed"))
-- 
cgit