taskapp/views/task.py
changeset 205 0c317f68df49
parent 204 fa1da06d25c9
child 215 84ec0ca5bc68
equal deleted inserted replaced
204:fa1da06d25c9 205:0c317f68df49
     1 from datetime import datetime
     1 from datetime import datetime
     2 
     2 
     3 from django.http import HttpResponse, Http404
     3 from django.http import HttpResponse, Http404
     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, Request, Notification
     6 from pytask.taskapp.models import User, Task, Comment, Request, Notification
     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, EditTaskForm
     8 from pytask.taskapp.forms.task import TaskCreateForm, AddMentorForm, AddTaskForm, ChoiceForm, AssignCreditForm, RemoveUserForm, EditTaskForm, ClaimTaskForm
     9 from pytask.taskapp.events.task import createTask, reqMentor, publishTask, addSubTask, addDep, addClaim, assignTask, updateTask, removeTask, removeUser, assignCredits, completeTask, closeTask, addMentor, deleteTask
     9 from pytask.taskapp.events.task import createTask, reqMentor, publishTask, addSubTask, addDep, addClaim, assignTask, updateTask, removeTask, removeUser, assignCredits, completeTask, closeTask, addMentor, deleteTask
    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 from pytask.taskapp.utilities.user import get_user
    12 
    12 
    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 ## everywhere if there is no task, django should display 500 message.. but take care of that in sensitive views like add mentor and all
   340     
   340     
   341     errors = []
   341     errors = []
   342     
   342     
   343     user = get_user(request.user) if request.user.is_authenticated() else request.user
   343     user = get_user(request.user) if request.user.is_authenticated() else request.user
   344     task = getTask(tid)
   344     task = getTask(tid)
   345     #claims = Claim.objects.filter(task=task)
   345     
   346     #claims = task.notifications_task.filter(role="CL",sent_to=task.created_by) 
   346     #claims = task.notifications_task.filter(role="CL",sent_to=task.created_by) 
   347     # this is what the next line should be when i re sync the db
   347     # this is what the next line should be when i re sync the db
   348     claims = Notification.objects.filter(task=task, sent_to=task.created_by, role="CL")
   348     claims = Notification.objects.filter(task=task, sent_to=task.created_by, role="CL")
   349 
   349 
   350     mentors = task.mentors.all()
   350     mentors = task.mentors.all()
   366                'task_claimable':task_claimable,
   366                'task_claimable':task_claimable,
   367                'task_claimed':task_claimed,
   367                'task_claimed':task_claimed,
   368                'errors':errors}
   368                'errors':errors}
   369     
   369     
   370     if not is_guest:
   370     if not is_guest:
       
   371         form = ClaimTaskForm()
       
   372         context['form'] = form
   371         if request.method == "POST":
   373         if request.method == "POST":
   372             claim_proposal = request.POST['message']
   374             form = ClaimTaskForm(request.POST)
   373             if claim_proposal:
   375             context['form'] = form
       
   376             if form.is_valid():
       
   377                 claim_proposal = form.cleaned_data['message']
   374                 addClaim(task, claim_proposal, user)
   378                 addClaim(task, claim_proposal, user)
   375                 return redirect(claim_url)
   379                 return redirect(claim_url)
   376             else:
   380             else:
   377                 errors.append('Please fill up proposal in the field below')
       
   378                 return render_to_response('task/claim.html', context)
   381                 return render_to_response('task/claim.html', context)
   379         else:
   382         else:
   380             return render_to_response('task/claim.html', context)
   383             return render_to_response('task/claim.html', context)
   381     else:
   384     else:
   382         return show_msg(user, 'You are not logged in to view claims for this task', task_url, 'view the task')
   385         return show_msg(user, 'You are not logged in to view claims for this task', task_url, 'view the task')