taskapp/views/task.py
changeset 138 c452c699a8af
parent 136 8632a44b743d
child 141 2489392ffb56
equal deleted inserted replaced
137:e56b95298254 138:c452c699a8af
     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, closeTask
     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 from pytask.taskapp.utilities.user import get_user
    11 
    12 
    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 ## 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
    14 ## do not create su user thro syncdb
    14 
    15 
    15 def browse_tasks(request):
    16 def browse_tasks(request):
    16     """ display all the tasks """
    17     """ display all the tasks """
    17     
    18     
    18     user = request.user
    19     user = get_user(request.user)
    19     task_list = Task.objects.exclude(status="UP").exclude(status="DL").order_by('published_datetime').reverse()
    20     task_list = Task.objects.exclude(status="UP").exclude(status="DL").order_by('published_datetime').reverse()
    20     
    21     
    21     context = {'user':user,
    22     context = {'user':user,
    22                'task_list':task_list,
    23                'task_list':task_list,
    23                }
    24                }
    27     """ check if user is the mentor and also if the task status is UP.
    28     """ check if user is the mentor and also if the task status is UP.
    28     """
    29     """
    29 
    30 
    30     task_url = "/task/view/tid=%s"%tid
    31     task_url = "/task/view/tid=%s"%tid
    31     
    32     
    32     user = request.user
    33     user = get_user(request.user)
    33     task = getTask(tid)
    34     task = getTask(tid)
    34 
    35 
    35     is_guest = True if not user.is_authenticated() else False
    36     is_guest = True if not user.is_authenticated() else False
    36     is_mentor = True if user in task.mentors.all() else False
    37     is_mentor = True if user in task.mentors.all() else False
    37 
    38 
    55     check for authentication and add a comment if it is a post request.
    56     check for authentication and add a comment if it is a post request.
    56     """
    57     """
    57     
    58     
    58     task_url = "/task/view/tid=%s"%tid
    59     task_url = "/task/view/tid=%s"%tid
    59     
    60     
    60     user = request.user
    61     user = get_user(request.user)
    61     task = getTask(tid)
    62     task = getTask(tid)
    62 
    63 
    63     if task.status == "DL":
    64     if task.status == "DL":
    64         return show_msg(user, 'This task no longer exists', '/task/browse/','browse the tasks')
    65         return show_msg(user, 'This task no longer exists', '/task/browse/','browse the tasks')
    65     comments = task.comment_set.filter(is_deleted=False)
    66     comments = task.comment_set.filter(is_deleted=False)
   107 def create_task(request):
   108 def create_task(request):
   108     """ check for rights and create a task if applicable.
   109     """ check for rights and create a task if applicable.
   109     if user cannot create a task, redirect to homepage.
   110     if user cannot create a task, redirect to homepage.
   110     """
   111     """
   111     
   112     
   112     user = request.user
   113     user = get_user(request.user)
   113     is_guest = True if not user.is_authenticated() else False
   114     is_guest = True if not user.is_authenticated() else False
   114     
   115     
   115     if not is_guest:
   116     if not is_guest:
   116         user_profile = user.get_profile()
   117         user_profile = user.get_profile()
   117         can_create_task = False if user_profile.rights == "CT" else True
   118         can_create_task = False if user_profile.rights == "CT" else True
   149     """ check if the current user has the rights to edit the task and add him.
   150     """ check if the current user has the rights to edit the task and add him.
   150     if user is not authenticated, redirect him to concerned page. """
   151     if user is not authenticated, redirect him to concerned page. """
   151     
   152     
   152     task_url = "/task/view/tid=%s"%tid
   153     task_url = "/task/view/tid=%s"%tid
   153     
   154     
   154     user = request.user
   155     user = get_user(request.user)
   155     task = getTask(tid)
   156     task = getTask(tid)
   156     errors = []
   157     errors = []
   157     
   158     
   158     is_guest = True if not user.is_authenticated() else False
   159     is_guest = True if not user.is_authenticated() else False
   159     
   160     
   189     """ first display tasks which can be subtasks for the task and do the rest.
   190     """ first display tasks which can be subtasks for the task and do the rest.
   190     """
   191     """
   191     
   192     
   192     task_url = "/task/view/tid=%s"%tid
   193     task_url = "/task/view/tid=%s"%tid
   193     
   194     
   194     user = request.user
   195     user = get_user(request.user)
   195     task = getTask(tid)
   196     task = getTask(tid)
   196 
   197 
   197     deps, subs = task.deps, task.subs
   198     deps, subs = task.deps, task.subs
   198     is_plain = False if deps or subs else True
   199     is_plain = False if deps or subs else True
   199 
   200 
   249     """ display a list of tasks and remove the selectes ones.
   250     """ display a list of tasks and remove the selectes ones.
   250     """
   251     """
   251 
   252 
   252     task_url = "/task/view/tid=%s"%tid
   253     task_url = "/task/view/tid=%s"%tid
   253     
   254     
   254     user = request.user
   255     user = get_user(request.user)
   255     task = getTask(tid)
   256     task = getTask(tid)
   256 
   257 
   257     is_guest = True if not user.is_authenticated() else False
   258     is_guest = True if not user.is_authenticated() else False
   258     if (not is_guest) and user in task.mentors.all():
   259     if (not is_guest) and user in task.mentors.all():
   259 
   260 
   292     task_url = "/task/view/tid=%s"%tid
   293     task_url = "/task/view/tid=%s"%tid
   293     claim_url = "/task/claim/tid=%s"%tid
   294     claim_url = "/task/claim/tid=%s"%tid
   294     
   295     
   295     errors = []
   296     errors = []
   296     
   297     
   297     user = request.user
   298     user = get_user(request.user)
   298     task = getTask(tid)
   299     task = getTask(tid)
   299     claims = Claim.objects.filter(task=task)
   300     claims = Claim.objects.filter(task=task)
   300 
   301 
   301     mentors = task.mentors.all()
   302     mentors = task.mentors.all()
   302     claimed_users = task.claimed_users.all()
   303     claimed_users = task.claimed_users.all()
   336     """ show a list of working users and ask for a message/reason for removing user.
   337     """ show a list of working users and ask for a message/reason for removing user.
   337     """
   338     """
   338     
   339     
   339     task_url = "/task/view/tid=%s"%tid
   340     task_url = "/task/view/tid=%s"%tid
   340     
   341     
   341     user = request.user
   342     user = get_user(request.user)
   342     task = getTask(tid)
   343     task = getTask(tid)
   343     
   344     
   344     is_guest = True if not user.is_authenticated() else False
   345     is_guest = True if not user.is_authenticated() else False
   345     is_mentor = True if user in task.mentors.all() else False
   346     is_mentor = True if user in task.mentors.all() else False
   346 
   347 
   381     generate list of claimed users by passing it as an argument to a function.
   382     generate list of claimed users by passing it as an argument to a function.
   382     """
   383     """
   383     
   384     
   384     task_url = "/task/view/tid=%s"%tid
   385     task_url = "/task/view/tid=%s"%tid
   385     
   386     
   386     user = request.user
   387     user = get_user(request.user)
   387     task = getTask(tid)
   388     task = getTask(tid)
   388     
   389     
   389     is_guest = True if not user.is_authenticated() else False
   390     is_guest = True if not user.is_authenticated() else False
   390     is_mentor = True if user in task.mentors.all() else False
   391     is_mentor = True if user in task.mentors.all() else False
   391 
   392 
   420     Then put up a form for mentor to assign credits accordingly.
   421     Then put up a form for mentor to assign credits accordingly.
   421     """
   422     """
   422     
   423     
   423     task_url = "/task/view/tid=%s"%tid
   424     task_url = "/task/view/tid=%s"%tid
   424     
   425     
   425     user = request.user
   426     user = get_user(request.user)
   426     task = getTask(tid)
   427     task = getTask(tid)
   427 
   428 
   428     is_guest = True if not user.is_authenticated() else False
   429     is_guest = True if not user.is_authenticated() else False
   429     is_mentor = True if (not is_guest) and user in task.mentors.all() else False
   430     is_mentor = True if (not is_guest) and user in task.mentors.all() else False
   430 
   431 
   478     and also pass it the current user to know who marked it as complete. 
   479     and also pass it the current user to know who marked it as complete. 
   479     """
   480     """
   480 
   481 
   481     task_url = "/task/view/tid=%s"%tid
   482     task_url = "/task/view/tid=%s"%tid
   482     
   483     
   483     user = request.user
   484     user = get_user(request.user)
   484     task = getTask(tid)
   485     task = getTask(tid)
   485     
   486     
   486     is_guest = True if not user.is_authenticated() else False
   487     is_guest = True if not user.is_authenticated() else False
   487     is_mentor = True if user in task.mentors.all() else False
   488     is_mentor = True if user in task.mentors.all() else False
   488 
   489 
   519     call the event close task if everything is fine.
   520     call the event close task if everything is fine.
   520     """
   521     """
   521 
   522 
   522     task_url = "/task/view/tid=%s"%tid
   523     task_url = "/task/view/tid=%s"%tid
   523     
   524     
   524     user = request.user
   525     user = get_user(request.user)
   525     task = getTask(tid)
   526     task = getTask(tid)
   526     
   527     
   527     is_guest = True if not user.is_authenticated() else False
   528     is_guest = True if not user.is_authenticated() else False
   528     is_mentor = True if user in task.mentors.all() else False
   529     is_mentor = True if user in task.mentors.all() else False
   529 
   530