diff options
-rw-r--r-- | taskapp/events/task.py | 2 | ||||
-rw-r--r-- | taskapp/forms/task.py | 14 | ||||
-rw-r--r-- | taskapp/views/task.py | 53 | ||||
-rw-r--r-- | templates/task/addtask.html | 16 | ||||
-rw-r--r-- | templates/task/view.html | 27 | ||||
-rw-r--r-- | urls.py | 9 |
6 files changed, 107 insertions, 14 deletions
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.<br /> + {% for err in errors %} + {{err}}<br /> + {% endfor %} + {% endif %} + <form action="" method="post"> + {{form.as_p}} + <input value="Submit" type="submit"> + </form> +{% endblock %} diff --git a/templates/task/view.html b/templates/task/view.html index 1d9a69d..64e73c0 100644 --- a/templates/task/view.html +++ b/templates/task/view.html @@ -19,20 +19,41 @@ {% endif %} {% if deps %} - <br />The task has following dependencies + + <br />The task has following dependencies.<br /> {% for dep in deps %} <a href="/task/view/tid={{dep.id}}">{{dep.title}}</a><br /> {% endfor %} + {% if can_mod_tasks %} <a href="/task/addtask/tid={{task.id}}">add more dependencies</a> <a href="/task/remtask/tid={{task.id}}">remove an existing dependency</a> {% endif %} + {% else %} - {% if can_mod_tasks %} - <a href="/task/addtask/tid={{task.id}}">add a subtask/dependency </a> + + {% if subs %} + + <br />The task has following sub tasks.<br /> + {% for sub in subs %} + <a href="/task/view/tid={{sub.id}}">{{sub.title}}</a><br /> + {% endfor %} + + {% if can_mod_tasks %} + <a href="/task/addtask/tid={{task.id}}">add more subtasks</a> + <a href="/task/remtask/tid={{task.id}}">remove an existing subtask</a> + {% endif %} + + {% else %} + + {% if can_mod_tasks %} + <a href="/task/addtask/tid={{task.id}}">add a subtask/dependency </a> + {% endif %} + {% endif %} {% endif %} + <hr> <br />Description:<br /> <br />{{ task.desc }}<br /> @@ -26,11 +26,12 @@ urlpatterns = patterns('', (r'^task/browse/$', taskViews.browse_tasks), (r'^task/view/tid=(\d+)$', taskViews.view_task), (r'^task/create/$', taskViews.create_task), - (r'^task/addmentor/tid=(\d+)', taskViews.add_mentor), + (r'^task/addmentor/tid=(\d+)$', taskViews.add_mentor), #(r'^task/addtasks/tid=(\d+)', taskViews.add_tasks), - (r'^task/edit/tid=(\d+)', taskViews.edit_task), - (r'^task/claim/tid=(\d+)', taskViews.claim_task), - (r'^task/assign/tid=(\d+)', taskViews.assign_task), + (r'^task/edit/tid=(\d+)$', taskViews.edit_task), + (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'^admin/', include(admin.site.urls)), |