taskapp/views/task.py
changeset 126 e5377fdaf110
parent 124 6d92b7cd2a37
child 131 85276c5aee5c
equal deleted inserted replaced
125:d3cfceb8e120 126:e5377fdaf110
     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, Credit
     6 from pytask.taskapp.models import User, Task, Comment, Claim, Credit
     7 from pytask.taskapp.utilities.task import getTask
     7 from pytask.taskapp.utilities.task import getTask
     8 from pytask.taskapp.forms.task import TaskCreateForm, AddMentorForm, AddTaskForm, ChoiceForm, AssignCreditForm, RemoveUserForm
     8 from pytask.taskapp.forms.task import TaskCreateForm, AddMentorForm, AddTaskForm, ChoiceForm, AssignCreditForm, RemoveUserForm
     9 from pytask.taskapp.events.task import createTask, reqMentor, publishTask, addSubTask, addDep, addClaim, assignTask, updateTask, removeTask, removeUser, assignCredits, completeTask
     9 from pytask.taskapp.events.task import createTask, reqMentor, publishTask, addSubTask, addDep, addClaim, assignTask, updateTask, removeTask, removeUser, assignCredits, completeTask, closeTask
    10 from pytask.taskapp.views.user import show_msg
    10 from pytask.taskapp.views.user import show_msg
    11 
    11 
    12 ## 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 ## everywhere if there is no task, django should display 500 message.. but take care of that in sensitive views like add mentor and all
    13 ## do not create su user thro syncdb
    13 ## do not create su user thro syncdb
    14 
    14 
    81                'is_mentor':is_mentor,
    81                'is_mentor':is_mentor,
    82                'errors':errors,
    82                'errors':errors,
    83               }
    83               }
    84 
    84 
    85     context['can_publish'] = True if task.status == "UP" and user == task.created_by else False
    85     context['can_publish'] = True if task.status == "UP" and user == task.created_by else False
    86     context['task_viewable'] = True if ( task.status not in ["UP", "DL"] ) or is_mentor else False
    86     context['task_viewable'] = True if ( task.status != "DL" ) or is_mentor else False
    87     context['task_claimable'] = True if task.status in ["OP", "WR"] else False
    87     context['task_claimable'] = True if task.status in ["OP", "WR"] else False
    88 
    88 
    89     context['can_mod_mentors'] = True if task.status in ["UP", "OP", "LO", "WR"] and is_mentor else False
    89     context['can_mod_mentors'] = True if task.status in ["UP", "OP", "LO", "WR"] and is_mentor else False
    90     context['can_mod_tasks'] = True if task.status in ["UP", "OP", "LO"] and is_mentor else False
    90     context['can_mod_tasks'] = True if task.status in ["UP", "OP", "LO"] and is_mentor else False
    91     context['can_assign_credits'] = True if task.status in ["OP", "WR"] and is_mentor else False
    91     context['can_assign_credits'] = True if task.status in ["OP", "WR"] and is_mentor else False
   511         else:
   511         else:
   512             return show_msg(user, "The task cannot be marked as completed at this stage", task_url, "view the task")
   512             return show_msg(user, "The task cannot be marked as completed at this stage", task_url, "view the task")
   513     else:
   513     else:
   514         return show_msg(user, "You are not authorised to do this", task_url, "view the task")
   514         return show_msg(user, "You are not authorised to do this", task_url, "view the task")
   515 
   515 
       
   516 def close_task(request, tid):
       
   517     """ task can be closed only if task is published.
       
   518     call the event close task if everything is fine.
       
   519     """
       
   520 
       
   521     task_url = "/task/view/tid=%s"%tid
       
   522     
       
   523     user = request.user
       
   524     task = getTask(tid)
       
   525     
       
   526     is_guest = True if not user.is_authenticated() else False
       
   527     is_mentor = True if user in task.mentors.all() else False
       
   528 
       
   529     if is_mentor:
       
   530 
       
   531         context = {
       
   532             'user':user,
       
   533             'task':task,
       
   534         }
       
   535 
       
   536         if not task.status in ["UP", "CD", "DL", "CM"]:
       
   537             if request.method == "POST":
       
   538                 data = request.POST
       
   539                 if not data.get("reason", None):
       
   540                     context["error"] = "Please enter a reason for closing the task"
       
   541                     return render_to_response('task/close.html', context)
       
   542                 else:
       
   543                     closeTask(task, user)
       
   544                     return show_msg(user, "The task has been closed.", task_url, "view the task.")
       
   545             else:
       
   546                 return render_to_response('task/close.html', context)
       
   547         else:
       
   548             return show_msg(user, "The task is already closed or the task cannot be closed at this stage", task_url, "view the task")
       
   549     else:
       
   550         return show_msg(user, "You are not authorised to do this", task_url, "view the task")