From a4dc314c81b55b37e0d7cb251890cef53d95cc80 Mon Sep 17 00:00:00 2001
From: nishanth
Date: Thu, 25 Feb 2010 02:11:49 +0530
Subject: added the capability of adding subtasks/dependencies .
---
taskapp/events/task.py | 2 +-
taskapp/forms/task.py | 14 ++++++++++++
taskapp/views/task.py | 53 ++++++++++++++++++++++++++++++++++++++++-----
templates/task/addtask.html | 16 ++++++++++++++
templates/task/view.html | 27 ++++++++++++++++++++---
urls.py | 9 ++++----
6 files changed, 107 insertions(+), 14 deletions(-)
create mode 100644 templates/task/addtask.html
diff --git a/taskapp/events/task.py b/taskapp/events/task.py
index ed56ade..335b645 100644
--- a/taskapp/events/task.py
+++ b/taskapp/events/task.py
@@ -32,7 +32,7 @@ def addSubTask(main_task, sub_task):
def addDep(main_task, dependency):
""" add the dependency task to deps attribute of the task.
update the status of main_task accordingly.
- note that deps can be added only if task is in UP/OP/LO/CD state.
+ note that deps can be added only if task is in UP/OP/LO state.
And also if the task doesn't have any subs.
"""
diff --git a/taskapp/forms/task.py b/taskapp/forms/task.py
index 1bcdc6f..d3cea32 100644
--- a/taskapp/forms/task.py
+++ b/taskapp/forms/task.py
@@ -27,3 +27,17 @@ def AssignTaskForm(choices, instance=None):
user = forms.ChoiceField(choices=choices, required=True)
form = myform()
return form
+
+def AddTaskForm(task_choices, is_plain=False):
+ """ if is_plain is true, it means the task has no subs/deps.
+ so we also give a radio button to choose between subs and dependencies.
+ else we only give choices.
+ """
+
+ class myForm(forms.Form):
+ if is_plain:
+ type_choices = [('S','Subtasks'),('D','Dependencies')]
+ type = forms.ChoiceField(type_choices, widget=forms.RadioSelect)
+
+ task = forms.MultipleChoiceField(choices=task_choices)
+ return myForm()
diff --git a/taskapp/views/task.py b/taskapp/views/task.py
index d81983a..0a36a25 100644
--- a/taskapp/views/task.py
+++ b/taskapp/views/task.py
@@ -4,8 +4,8 @@ from django.http import HttpResponse
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, getTask, updateTask
+from pytask.taskapp.forms.task import TaskCreateForm, AddMentorForm, AssignTaskForm, AddTaskForm
+from pytask.taskapp.events.task import createTask, addMentor, publishTask, addSubTask, addDep, addClaim, assignTask, getTask, updateTask
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
@@ -161,19 +161,55 @@ def add_tasks(request, tid):
user = request.user
task = getTask(tid)
+
+ deps = task.deps.all()
+ subs = task.subs.all()
+
+ is_plain = False if deps or subs else True
+
+ ## again a brute force method
+ valid_tasks = []
+ for a_task in Task.objects.all():
+ if not ( a_task.status in deps or a_task in subs or a_task.status=="CD" or a_task==task ):
+ valid_tasks.append(a_task)
+
+ task_choices = [ (_.id,_.title) for _ in valid_tasks ]
errors = []
is_guest = True if not user.is_authenticated() else False
if (not is_guest) and user in task.mentors.all():
- if task.status in ["OP", "LO"]:
+ if task.status in ["UP", "OP", "LO"]:
+ form = AddTaskForm(task_choices, is_plain)
if request.method == "POST":
## first decide if adding subs and deps can be in same page
## only exclude tasks with status deleted
- pass
+ data = request.POST
+ print data
+ if is_plain and not data.get('type', None): errors.append('Please choose which type of task(s) do you want to add.')
+ if not data.get('task', None): errors.append('Please choose a one task')
+
+ if not errors:
+ if is_plain:
+ update_method = addDep if data['type'] == "D" else addSubTask
+ elif deps:
+ update_method = addDep
+ elif subs:
+ update_method = addSubTask
+ else:
+ print "Screw you"
+
+ ## we might iterate over a task list later on
+ task_id = data['task']
+ sub_or_dep = getTask(task_id)
+ print task_id, sub_or_dep
+ update_method(task, sub_or_dep)
+
+ return redirect(task_url)
+ else:
+ return render_to_response('task/addtask.html', {'user':user, 'form':form, 'errors':errors})
else:
- ## write a form just like add mentor and get the form here
- pass
+ return render_to_response('task/addtask.html', {'user':user, 'form':form, 'errors':errors})
else:
errors = ["The task cannot be added subtasks or dependencies in this state"]
# return render_to_response('task/add.html', {'form':form, 'errors':errors})
@@ -181,6 +217,11 @@ def add_tasks(request, tid):
else:
return show_msg('You are not authorised to add subtasks or dependencies for this task', task_url, 'view the task')
+def remove_task(request, tid):
+ """ display a list of tasks and remove the selectes ones.
+ """
+
+ pass
def claim_task(request, tid):
""" display a list of claims for get and display submit only if claimable """
diff --git a/templates/task/addtask.html b/templates/task/addtask.html
new file mode 100644
index 0000000..460b449
--- /dev/null
+++ b/templates/task/addtask.html
@@ -0,0 +1,16 @@
+{% extends 'base.html' %}
+{% block title %}
+ Add tasks for {{task.title}}
+{% endblock %}
+{% block content %}
+ {% if errors %}
+ Please correct the following errors.
+ {% for err in errors %}
+ {{err}}
+ {% endfor %}
+ {% endif %}
+