taskapp/views/task.py
changeset 89 1cc03941ed5d
parent 76 00a41fbf4958
child 90 b2426897ff18
equal deleted inserted replaced
88:0b6d251d3c30 89:1cc03941ed5d
     2 
     2 
     3 from django.http import HttpResponse
     3 from django.http import HttpResponse
     4 from django.shortcuts import render_to_response, redirect
     4 from django.shortcuts import render_to_response, redirect
     5 
     5 
     6 from pytask.taskapp.models import User, Task, Comment, Claim
     6 from pytask.taskapp.models import User, Task, Comment, Claim
     7 from pytask.taskapp.forms.task import TaskCreateForm, AddMentorForm, AssignTaskForm
     7 from pytask.taskapp.forms.task import TaskCreateForm, AddMentorForm, AssignTaskForm, AddTaskForm 
     8 from pytask.taskapp.events.task import createTask, addMentor, publishTask, addSubTask, addClaim, assignTask, getTask, updateTask
     8 from pytask.taskapp.events.task import createTask, addMentor, publishTask, addSubTask, addDep, addClaim, assignTask, getTask, updateTask
     9 from pytask.taskapp.views.user import show_msg
     9 from pytask.taskapp.views.user import show_msg
    10 
    10 
    11 ## everywhere if there is no task, django should display 500 message.. but take care of that in sensitive views like add mentor and all
    11 ## everywhere if there is no task, django should display 500 message.. but take care of that in sensitive views like add mentor and all
    12 ## do not create su user thro syncdb
    12 ## do not create su user thro syncdb
    13 
    13 
   159     
   159     
   160     task_url = "/task/view/tid=%s"%tid
   160     task_url = "/task/view/tid=%s"%tid
   161     
   161     
   162     user = request.user
   162     user = request.user
   163     task = getTask(tid)
   163     task = getTask(tid)
       
   164 
       
   165     deps = task.deps.all()
       
   166     subs = task.subs.all()
       
   167 
       
   168     is_plain = False if deps or subs else True
       
   169 
       
   170     ## again a brute force method
       
   171     valid_tasks = []
       
   172     for a_task in Task.objects.all():
       
   173         if not ( a_task.status in deps or a_task in subs or a_task.status=="CD" or a_task==task ):
       
   174             valid_tasks.append(a_task)
       
   175 
       
   176     task_choices = [ (_.id,_.title) for _ in valid_tasks ]
   164     errors = []
   177     errors = []
   165     
   178     
   166     is_guest = True if not user.is_authenticated() else False
   179     is_guest = True if not user.is_authenticated() else False
   167     
   180     
   168     if (not is_guest) and user in task.mentors.all():
   181     if (not is_guest) and user in task.mentors.all():
   169         if task.status in ["OP", "LO"]:
   182         if task.status in ["UP", "OP", "LO"]:
       
   183             form = AddTaskForm(task_choices, is_plain)
   170             if request.method == "POST":
   184             if request.method == "POST":
   171                 ## first decide if adding subs and deps can be in same page
   185                 ## first decide if adding subs and deps can be in same page
   172                 ## only exclude tasks with status deleted
   186                 ## only exclude tasks with status deleted
   173                 pass
   187                 data = request.POST
       
   188                 print data
       
   189                 if is_plain and not data.get('type', None): errors.append('Please choose which type of task(s) do you want to add.')
       
   190                 if not data.get('task', None): errors.append('Please choose a one task')
       
   191 
       
   192                 if not errors:
       
   193                     if is_plain:
       
   194                         update_method = addDep if data['type'] == "D" else addSubTask
       
   195                     elif deps:
       
   196                         update_method = addDep
       
   197                     elif subs:
       
   198                         update_method = addSubTask
       
   199                     else:
       
   200                         print "Screw you"
       
   201 
       
   202                     ## we might iterate over a task list later on
       
   203                     task_id = data['task']
       
   204                     sub_or_dep = getTask(task_id)
       
   205                     print task_id, sub_or_dep
       
   206                     update_method(task, sub_or_dep)
       
   207 
       
   208                     return redirect(task_url)
       
   209                 else:
       
   210                     return render_to_response('task/addtask.html', {'user':user, 'form':form, 'errors':errors})
   174             else:
   211             else:
   175                 ## write a form just like add mentor and get the form here
   212                 return render_to_response('task/addtask.html', {'user':user, 'form':form, 'errors':errors})
   176                 pass
       
   177         else:
   213         else:
   178             errors = ["The task cannot be added subtasks or dependencies in this state"]
   214             errors = ["The task cannot be added subtasks or dependencies in this state"]
   179 #            return render_to_response('task/add.html', {'form':form, 'errors':errors})
   215 #            return render_to_response('task/add.html', {'form':form, 'errors':errors})
   180             return show_msg('The task cannot be added subtasks or dependencies now', task_url, 'view the task')
   216             return show_msg('The task cannot be added subtasks or dependencies now', task_url, 'view the task')
   181     else:
   217     else:
   182         return show_msg('You are not authorised to add subtasks or dependencies for this task', task_url, 'view the task')
   218         return show_msg('You are not authorised to add subtasks or dependencies for this task', task_url, 'view the task')
   183     
   219     
       
   220 def remove_task(request, tid):
       
   221     """ display a list of tasks and remove the selectes ones.
       
   222     """
       
   223 
       
   224     pass
   184     
   225     
   185 def claim_task(request, tid):
   226 def claim_task(request, tid):
   186     """ display a list of claims for get and display submit only if claimable """
   227     """ display a list of claims for get and display submit only if claimable """
   187 
   228 
   188     ## create claims model and create a new database with required tables for it
   229     ## create claims model and create a new database with required tables for it