1 from datetime import datetime |
1 from datetime import datetime |
2 from pytask.taskapp.models import Profile, Task, Comment, Credit, Claim, Map |
2 from pytask.taskapp.models import Profile, Task, Comment, Credit, Claim, Map |
|
3 from pytask.taskapp.utilities.task import getTask |
3 from pytask.taskapp.utilities.request import create_request |
4 from pytask.taskapp.utilities.request import create_request |
4 from pytask.taskapp.utilities.helper import get_key |
5 from pytask.taskapp.utilities.helper import get_key |
5 |
6 |
6 def publishTask(task, rem_mentors=True, rem_comments=True): |
7 def publishTask(task, rem_mentors=True, rem_comments=True): |
7 """ set the task status to open """ |
8 """ set the task status to open """ |
148 task.assigned_users.add(user) |
149 task.assigned_users.add(user) |
149 task.claimed_users.remove(user) |
150 task.claimed_users.remove(user) |
150 task.status = "WR" |
151 task.status = "WR" |
151 task.save() |
152 task.save() |
152 |
153 |
153 def getTask(tid): |
|
154 """ retreive the task from database. |
|
155 if the task has deps or subs, update its status correspondingly. |
|
156 """ |
|
157 |
|
158 task = Task.objects.get(id=tid) |
|
159 try: |
|
160 mapobj = Map.objects.get(main=task) |
|
161 except Map.DoesNotExist: |
|
162 mapobj = Map() |
|
163 mapobj.main = task |
|
164 mapobj.save() |
|
165 |
|
166 task_subs = mapobj.subs.all() |
|
167 |
|
168 if task.sub_type == "D": |
|
169 task.deps, task.subs = task_subs, [] |
|
170 elif task.sub_type == "S": |
|
171 task.subs, task.deps = task_subs, [] |
|
172 |
|
173 deps, subs = task.deps, task.subs |
|
174 if deps and task.status in ["OP", "LO"]: |
|
175 task.status = "OP" if all(map(lambda t:t.status=="CM",deps)) else "LO" |
|
176 if subs and task.status in ["OP", "LO", "CM"]: |
|
177 task.status = "CM" if all(map(lambda t:t.status=="CM",subs)) else "LO" |
|
178 |
|
179 task.save() |
|
180 return task |
|
181 |
154 |
182 def updateTask(task, title=None, desc=None, credits=None, tags_field=None): |
155 def updateTask(task, title=None, desc=None, credits=None, tags_field=None): |
183 """ update the property accordingly. |
156 """ update the property accordingly. |
184 while updating title, check for uniqueness of title. |
157 while updating title, check for uniqueness of title. |
185 return None if any error. |
158 return None if any error. |