diff options
author | nishanth | 2010-02-23 12:16:28 +0530 |
---|---|---|
committer | nishanth | 2010-02-23 12:16:28 +0530 |
commit | a8b11aa379c71501bac9e9d1de62b65b99948d2f (patch) | |
tree | 6460bed0035a41d22b9449fe6bdea2dfade717e4 /taskapp | |
parent | a9077beaa081e3b23af310b757cd8f8d84455799 (diff) | |
download | pytask-a8b11aa379c71501bac9e9d1de62b65b99948d2f.tar.gz pytask-a8b11aa379c71501bac9e9d1de62b65b99948d2f.tar.bz2 pytask-a8b11aa379c71501bac9e9d1de62b65b99948d2f.zip |
added a utility called getTask in task events and made changes in task views accordingly
Diffstat (limited to 'taskapp')
-rw-r--r-- | taskapp/events/task.py | 17 | ||||
-rw-r--r-- | taskapp/views/task.py | 14 |
2 files changed, 24 insertions, 7 deletions
diff --git a/taskapp/events/task.py b/taskapp/events/task.py index 4f76f8e..4fcf90f 100644 --- a/taskapp/events/task.py +++ b/taskapp/events/task.py @@ -99,3 +99,20 @@ def assignTask(task, user): 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 diff --git a/taskapp/views/task.py b/taskapp/views/task.py index 8a91ed9..5a7c8e3 100644 --- a/taskapp/views/task.py +++ b/taskapp/views/task.py @@ -5,7 +5,7 @@ from django.shortcuts import render_to_response, redirect 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 @@ def view_task(request, tid): 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 @@ def view_task(request, tid): 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 @@ def add_mentor(request, tid): 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 @@ def add_tasks(request, tid): 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 @@ def claim_task(request, tid): 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 @@ def assign_task(request, tid): 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 |