added the capability of adding subtasks/dependencies .
authornishanth
Thu, 25 Feb 2010 02:11:49 +0530
changeset 89 1cc03941ed5d
parent 88 0b6d251d3c30
child 90 b2426897ff18
added the capability of adding subtasks/dependencies .
taskapp/events/task.py
taskapp/forms/task.py
taskapp/views/task.py
templates/task/addtask.html
templates/task/view.html
urls.py
--- a/taskapp/events/task.py	Wed Feb 24 20:33:45 2010 +0530
+++ b/taskapp/events/task.py	Thu Feb 25 02:11:49 2010 +0530
@@ -32,7 +32,7 @@
 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.
     """
 
--- a/taskapp/forms/task.py	Wed Feb 24 20:33:45 2010 +0530
+++ b/taskapp/forms/task.py	Thu Feb 25 02:11:49 2010 +0530
@@ -27,3 +27,17 @@
         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()
--- a/taskapp/views/task.py	Wed Feb 24 20:33:45 2010 +0530
+++ b/taskapp/views/task.py	Thu Feb 25 02:11:49 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, 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 @@
     
     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 @@
     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 """
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/templates/task/addtask.html	Thu Feb 25 02:11:49 2010 +0530
@@ -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 %}
--- a/templates/task/view.html	Wed Feb 24 20:33:45 2010 +0530
+++ b/templates/task/view.html	Thu Feb 25 02:11:49 2010 +0530
@@ -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 />
--- a/urls.py	Wed Feb 24 20:33:45 2010 +0530
+++ b/urls.py	Thu Feb 25 02:11:49 2010 +0530
@@ -26,11 +26,12 @@
     (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)),