taskapp/views/task.py
changeset 111 c272d4c601cd
parent 110 3685c2333448
child 112 eadff01e395e
equal deleted inserted replaced
110:3685c2333448 111:c272d4c601cd
    19     
    19     
    20     context = {'user':user,
    20     context = {'user':user,
    21                'task_list':task_list,
    21                'task_list':task_list,
    22                }
    22                }
    23     return render_to_response('task/browse.html', context)
    23     return render_to_response('task/browse.html', context)
       
    24 
       
    25 def publish_task(request, tid):
       
    26     """ check if user is the mentor and also if the task status is UP.
       
    27     """
       
    28 
       
    29     task_url = "/task/view/tid=%s"%tid
       
    30     
       
    31     user = request.user
       
    32     task = getTask(tid)
       
    33 
       
    34     is_guest = True if not user.is_authenticated() else False
       
    35     is_mentor = True if user in task.mentors.all() else False
       
    36 
       
    37     if user==task.created_by:
       
    38         context = {
       
    39             'user':user,
       
    40         }
       
    41 
       
    42         if request.method == "POST":
       
    43             publishTask(task)
       
    44             return show_msg(user, "The task has been published", task_url, "view the task")
       
    45         else:
       
    46             return render_to_response('task/publish.html', context)
       
    47     else:
       
    48         return show_msg(user, "You are not authorised to do this", '/task/browse/', "browse tasks")
       
    49 
       
    50 
    24 
    51 
    25 def view_task(request, tid):
    52 def view_task(request, tid):
    26     """ get the task depending on its tid and display accordingly if it is a get.
    53     """ get the task depending on its tid and display accordingly if it is a get.
    27     check for authentication and add a comment if it is a post request.
    54     check for authentication and add a comment if it is a post request.
    28     """
    55     """
    52                'is_guest':is_guest,
    79                'is_guest':is_guest,
    53                'is_mentor':is_mentor,
    80                'is_mentor':is_mentor,
    54                'errors':errors,
    81                'errors':errors,
    55               }
    82               }
    56 
    83 
       
    84     context['can_publish'] = True if task.status == "UP" and user == task.created_by else False
    57     context['task_viewable'] = True if ( task.status not in ["UP", "DL"] ) or is_mentor else False
    85     context['task_viewable'] = True if ( task.status not in ["UP", "DL"] ) or is_mentor else False
    58     context['task_claimable'] = True if task.status in ["OP", "WR"] else False
    86     context['task_claimable'] = True if task.status in ["OP", "WR"] else False
    59 
    87 
    60     context['can_mod_mentors'] = True if task.status in ["UP", "OP", "LO", "WR"] and is_mentor else False
    88     context['can_mod_mentors'] = True if task.status in ["UP", "OP", "LO", "WR"] and is_mentor else False
    61     context['can_mod_tasks'] = True if task.status in ["UP", "OP", "LO"] and is_mentor else False
    89     context['can_mod_tasks'] = True if task.status in ["UP", "OP", "LO"] and is_mentor else False