From 2d4d7d30683375420c409e53797fef2940d33005 Mon Sep 17 00:00:00 2001 From: nishanth Date: Thu, 25 Feb 2010 04:38:50 +0530 Subject: added the capability to remove subtasks/dependencies . --- taskapp/events/task.py | 8 ++++++++ taskapp/forms/task.py | 4 ++-- taskapp/views/task.py | 41 +++++++++++++++++++++++++++++++++++++---- templates/task/removetask.html | 16 ++++++++++++++++ urls.py | 1 + 5 files changed, 64 insertions(+), 6 deletions(-) create mode 100644 templates/task/removetask.html diff --git a/taskapp/events/task.py b/taskapp/events/task.py index 727b04e..a999dc7 100644 --- a/taskapp/events/task.py +++ b/taskapp/events/task.py @@ -167,3 +167,11 @@ def updateTask(task, title=None, desc=None, credits=None, tags_field=None): 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 --git a/taskapp/forms/task.py b/taskapp/forms/task.py index 6a2961a..fd1a3af 100644 --- a/taskapp/forms/task.py +++ b/taskapp/forms/task.py @@ -20,11 +20,11 @@ class ClaimTaskForm(forms.ModelForm): 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 --git a/taskapp/views/task.py b/taskapp/views/task.py index 9221b0b..fdc28ce 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, 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 @@ def remove_task(request, tid): """ 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 @@ def assign_task(request, tid): 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 --git a/templates/task/removetask.html b/templates/task/removetask.html new file mode 100644 index 0000000..47443df --- /dev/null +++ b/templates/task/removetask.html @@ -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 --git a/urls.py b/urls.py index c34415a..da60d31 100644 --- a/urls.py +++ b/urls.py @@ -32,6 +32,7 @@ urlpatterns = patterns('', (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)), -- cgit