pytask/taskapp/views/task.py
changeset 15 c6038cbf8a39
parent 14 f2623fb8041a
child 18 293692eb8f06
equal deleted inserted replaced
14:f2623fb8041a 15:c6038cbf8a39
     1 from datetime import datetime
     1 from datetime import datetime
     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
     6 from pytask.taskapp.models import User, Task, Comment, Claim
     7 from pytask.taskapp.forms.task import TaskCreateForm, AddMentorForm 
     7 from pytask.taskapp.forms.task import TaskCreateForm, AddMentorForm 
     8 from pytask.taskapp.events.task import createTask, addMentor, publishTask, addSubTask
     8 from pytask.taskapp.events.task import createTask, addMentor, publishTask, addSubTask
     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
    36     errors = []
    36     errors = []
    37     
    37     
    38     is_guest = True if not user.is_authenticated() else False
    38     is_guest = True if not user.is_authenticated() else False
    39     is_mentor = True if user in task.mentors.all() else False
    39     is_mentor = True if user in task.mentors.all() else False
    40     
    40     
       
    41     task_claimable = True if task.status in ["OP", "RE"] else False
       
    42     user_can_view_claim = True if ( task_claimable and not ( is_guest or is_mentor ) ) else False
       
    43     
    41     context = {'user':user,
    44     context = {'user':user,
    42                'task':task,
    45                'task':task,
    43                'comments':comments,
    46                'comments':comments,
    44                'mentors':mentors,
    47                'mentors':mentors,
    45                'is_guest':is_guest,
    48                'is_guest':is_guest,
    46                'is_mentor':is_mentor,
    49                'is_mentor':is_mentor,
       
    50                'user_can_view_claim':user_can_view_claim,
    47                'errors':errors,
    51                'errors':errors,
    48                }
    52                }
    49     
    53     
    50     if request.method == 'POST':
    54     if request.method == 'POST':
    51         if not is_guest:
    55         if not is_guest:
   169     
   173     
   170     task_url = "/task/view/tid=%s"%tid
   174     task_url = "/task/view/tid=%s"%tid
   171     
   175     
   172     user = request.user
   176     user = request.user
   173     task = Task.objects.get(id=tid)
   177     task = Task.objects.get(id=tid)
       
   178     claims = Claim.objects.filter(task=task)
       
   179     
       
   180     is_guest = True if not user.is_authenticated() else False
       
   181 
       
   182     task_claimable = True if task.status in ["OP", "RE"] else False
       
   183     user_can_claim = True if ( task_claimable and not ( is_guest or is_mentor ) and ( user not in task.claimed_users.all() ) ) else False
       
   184     
       
   185     if not is_guest:
       
   186         if task_claimable:
       
   187             pass
       
   188         else:
       
   189             return show_msg('You are not logged in to view claims for this task', task_url, 'view the task')
       
   190     else:
       
   191         return show_msg('You are not logged in to view claims for this task', task_url, 'view the task')
   174     
   192     
   175     
   193     
   176     
   194     
   177     
   195     
   178     
   196     
   179     
       
   180