changeset 114 | 38793914921b |
parent 112 | eadff01e395e |
child 120 | aad4e6065d85 |
113:ea962d5fe99e | 114:38793914921b |
---|---|
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, Claim, Credit |
6 from pytask.taskapp.models import User, Task, Comment, Claim, Credit |
7 from pytask.taskapp.forms.task import TaskCreateForm, AddMentorForm, AddTaskForm, ChoiceForm, AssignCreditForm, RemoveUserForm |
7 from pytask.taskapp.forms.task import TaskCreateForm, AddMentorForm, AddTaskForm, ChoiceForm, AssignCreditForm, RemoveUserForm |
8 from pytask.taskapp.events.task import createTask, reqMentor, publishTask, addSubTask, addDep, addClaim, assignTask, getTask, updateTask, removeTask, removeUser, assignCredits |
8 from pytask.taskapp.events.task import createTask, reqMentor, publishTask, addSubTask, addDep, addClaim, assignTask, getTask, updateTask, removeTask, removeUser, assignCredits, completeTask |
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 |
12 ## do not create su user thro syncdb |
12 ## do not create su user thro syncdb |
13 |
13 |
468 """ see what are the attributes that can be edited depending on the current status |
468 """ see what are the attributes that can be edited depending on the current status |
469 and then give the user fields accordingly. |
469 and then give the user fields accordingly. |
470 """ |
470 """ |
471 |
471 |
472 task = Task.objects.get(id=tid) |
472 task = Task.objects.get(id=tid) |
473 |
|
474 def complete_task(request, tid): |
|
475 |
|
476 """ call the event called complete task. |
|
477 and also pass it the current user to know who marked it as complete. |
|
478 """ |
|
479 |
|
480 task_url = "/task/view/tid=%s"%tid |
|
481 |
|
482 user = request.user |
|
483 task = getTask(tid) |
|
484 |
|
485 is_guest = True if not user.is_authenticated() else False |
|
486 is_mentor = True if user in task.mentors.all() else False |
|
487 |
|
488 claimed_users = task.claimed_users.all() |
|
489 assigned_users = task.assigned_users.all() |
|
490 |
|
491 assign_credits_url = '/task/assigncredits/tid=%s'%task.id |
|
492 task_assigned_credits = task.credit_set.all() |
|
493 |
|
494 |
|
495 if is_mentor: |
|
496 if task.status in ["OP", "WR"]: |
|
497 |
|
498 context = { |
|
499 'user':user, |
|
500 'task':task, |
|
501 } |
|
502 |
|
503 if task_assigned_credits: |
|
504 if request.method=="POST": |
|
505 completeTask(task, user) |
|
506 return redirect(task_url) |
|
507 else: |
|
508 return render_to_response('task/complete.html', context) |
|
509 else: |
|
510 return show_msg(user, "Nobody has been credited for doing this task.", assign_credits_url, "assign credits") |
|
511 else: |
|
512 return show_msg(user, "The task cannot be marked as completed at this stage", task_url, "view the task") |
|
513 else: |
|
514 return show_msg(user, "You are not authorised to do this", task_url, "view the task") |
|
515 |