added the capability to remove subtasks/dependencies .
--- a/taskapp/events/task.py Thu Feb 25 04:01:11 2010 +0530
+++ b/taskapp/events/task.py Thu Feb 25 04:38:50 2010 +0530
@@ -167,3 +167,11 @@
if tags_field:task.tags_field = tags_field
task.save()
return task
+
+def removeTask(main_task, sub_task):
+ """ get the corresponding map object and remove the sub_task.
+ """
+
+ mapobj = Map.objects.get(main=main_task)
+ mapobj.subs.remove(sub_task)
+ mapobj.save()
--- a/taskapp/forms/task.py Thu Feb 25 04:01:11 2010 +0530
+++ b/taskapp/forms/task.py Thu Feb 25 04:38:50 2010 +0530
@@ -20,11 +20,11 @@
model = Claim
fields = ['message']
-def ChoiceForm(choices, instance=None):
+def ChoiceForm(choices):
""" return a form object with appropriate choices """
class myform(forms.Form):
- user = forms.ChoiceField(choices=choices, required=True)
+ choice = forms.ChoiceField(choices=choices, required=True)
form = myform()
return form
--- a/taskapp/views/task.py Thu Feb 25 04:01:11 2010 +0530
+++ b/taskapp/views/task.py Thu Feb 25 04:38:50 2010 +0530
@@ -4,8 +4,8 @@
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, AddTaskForm
-from pytask.taskapp.events.task import createTask, addMentor, publishTask, addSubTask, addDep, addClaim, assignTask, getTask, updateTask
+from pytask.taskapp.forms.task import TaskCreateForm, AddMentorForm, AddTaskForm, ChoiceForm
+from pytask.taskapp.events.task import createTask, addMentor, publishTask, addSubTask, addDep, addClaim, assignTask, getTask, updateTask, removeTask
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
@@ -217,7 +217,40 @@
""" display a list of tasks and remove the selectes ones.
"""
- pass
+ task_url = "/task/view/tid=%s"%tid
+
+ user = request.user
+ task = getTask(tid)
+
+ is_guest = True if not user.is_authenticated() else False
+ if (not is_guest) and user in task.mentors.all():
+
+ deps, subs = task.deps, task.subs
+ task_list = deps if task.sub_type == "D" else subs
+
+ if task_list:
+ choices = [(_.id,_.title) for _ in task_list ]
+ form = ChoiceForm(choices)
+
+ errors = []
+
+ if request.method == "POST":
+ data = request.POST
+ if not data.get('choice', None): errors.append("Please choose a task to remove.")
+ if not errors:
+ tid = data['choice']
+ sub_task = getTask(tid)
+ removeTask(task, sub_task)
+ return redirect(task_url)
+ else:
+ return render_to_response('task/removetask.html', {'user':user, 'form':form, 'errors':errors})
+ else:
+ return render_to_response('task/removetask.html', {'user':user, 'form':form, 'errors':errors})
+ else:
+ return show_msg("The task has no subtasks/dependencies to be removed", task_url, "view the task")
+ else:
+ return show_msg("You are not authorised to do this", task_url, "view the task")
+
def claim_task(request, tid):
""" display a list of claims for get and display submit only if claimable """
@@ -293,7 +326,7 @@
form = ChoiceForm(user_list)
if request.method == "POST":
- uid = request.POST['user']
+ uid = request.POST['choice']
assigned_user = User.objects.get(id=uid)
assignTask(task, assigned_user)
return redirect(task_url)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/templates/task/removetask.html Thu Feb 25 04:38:50 2010 +0530
@@ -0,0 +1,16 @@
+{% extends 'base.html' %}
+{% block title %}
+ Remove tasks for {{task.title}}
+{% endblock %}
+{% block content %}
+ {% if errors %}
+ Please correct the following errors.<br />
+ {% for err in errors %}
+ {{err}}<br />
+ {% endfor %}
+ {% endif %}
+ <form action="" method="post">
+ {{form.as_p}}
+ <input value="Submit" type="submit">
+ </form>
+{% endblock %}
--- a/urls.py Thu Feb 25 04:01:11 2010 +0530
+++ b/urls.py Thu Feb 25 04:38:50 2010 +0530
@@ -32,6 +32,7 @@
(r'^task/claim/tid=(\d+)$', taskViews.claim_task),
(r'^task/assign/tid=(\d+)$', taskViews.assign_task),
(r'^task/addtask/tid=(\d+)$', taskViews.add_tasks),
+ (r'^task/remtask/tid=(\d+)$', taskViews.remove_task),
(r'^admin/', include(admin.site.urls)),