# HG changeset patch # User nishanth # Date 1267052930 -19800 # Node ID c99f09bebe5633f7c31d929a552858fcd567c9eb # Parent 1b5ad4b7c40eb4e950b2e45a78aa9fc9237a274e added the capability to remove subtasks/dependencies . diff -r 1b5ad4b7c40e -r c99f09bebe56 taskapp/events/task.py --- 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() diff -r 1b5ad4b7c40e -r c99f09bebe56 taskapp/forms/task.py --- 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 diff -r 1b5ad4b7c40e -r c99f09bebe56 taskapp/views/task.py --- 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) diff -r 1b5ad4b7c40e -r c99f09bebe56 templates/task/removetask.html --- /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.
+ {% for err in errors %} + {{err}}
+ {% endfor %} + {% endif %} +
+ {{form.as_p}} + +
+{% endblock %} diff -r 1b5ad4b7c40e -r c99f09bebe56 urls.py --- 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)),