changeset 167 | b61e45074ba1 |
parent 166 | ac72d641046e |
child 176 | 13ceb76fd0a3 |
166:ac72d641046e | 167:b61e45074ba1 |
---|---|
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, Claim, 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 |
9 from pytask.taskapp.events.task import createTask, reqMentor, publishTask, addSubTask, addDep, addClaim, assignTask, updateTask, removeTask, removeUser, assignCredits, completeTask, closeTask, addMentor |
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 |
14 ## do not create su user thro syncdb |
14 ## do not create su user thro syncdb |
83 claimed_users = task.claimed_users.all() |
83 claimed_users = task.claimed_users.all() |
84 |
84 |
85 context['task_viewable'] = True if ( task.status != "UP" ) or is_mentor else False |
85 context['task_viewable'] = True if ( task.status != "UP" ) or is_mentor else False |
86 |
86 |
87 context['can_publish'] = True if task.status == "UP" and user == task.created_by else False |
87 context['can_publish'] = True if task.status == "UP" and user == task.created_by else False |
88 context['can_edit'] = True if ( not claimed_users ) and task.status in ["UP", "LO", "OP"] and is_mentor else False |
88 context['can_edit'] = True if task.status == "UP" and is_mentor else False |
89 context['can_close'] = True if task.status not in ["UP", "CD", "CM"] and is_mentor else False |
89 context['can_close'] = True if task.status not in ["UP", "CD", "CM"] and is_mentor else False |
90 context['can_delete'] = True if task.status == "UP" and user == task.created_by else False |
|
90 |
91 |
91 context['can_mod_mentors'] = True if task.status in ["UP", "OP", "LO", "WR"] and is_mentor else False |
92 context['can_mod_mentors'] = True if task.status in ["UP", "OP", "LO", "WR"] and is_mentor else False |
92 context['can_mod_tasks'] = True if task.status in ["UP", "OP", "LO"] and is_mentor else False |
93 context['can_mod_tasks'] = True if task.status in ["UP", "OP", "LO"] and is_mentor else False |
93 |
94 |
94 context['can_assign_credits'] = True if task.status in ["OP", "WR"] and is_mentor else False |
95 context['can_assign_credits'] = True if task.status in ["OP", "WR"] and is_mentor else False |
630 return render_to_response('task/close.html', context) |
631 return render_to_response('task/close.html', context) |
631 else: |
632 else: |
632 return show_msg(user, "The task is either already closed or cannot be closed at this stage", task_url, "view the task") |
633 return show_msg(user, "The task is either already closed or cannot be closed at this stage", task_url, "view the task") |
633 else: |
634 else: |
634 return show_msg(user, "You are not authorised to do this", task_url, "view the task") |
635 return show_msg(user, "You are not authorised to do this", task_url, "view the task") |
636 |
|
637 |
|
638 def delete_task(request, tid): |
|
639 """ mark the task status as DL. |
|
640 take a reason from the user and pass on to all the other mentors. |
|
641 """ |
|
642 |
|
643 task_url = "/task/view/tid=%s"%tid |
|
644 |
|
645 task = getTask(tid) |
|
646 user = get_user(request.user) if request.user.is_authenticated() else request.user |
|
647 |
|
648 if task.status == "DL": |
|
649 return show_msg(user, "This task no longer exists", '/task/browse/', "to browse other tasks") |
|
650 |
|
651 can_delete = True if task.status == "UP" and task.created_by == user else False |
|
652 |
|
653 if can_delete: |
|
654 if request.method == "POST": |
|
655 data = request.POST |
|
656 reason = data.get('reason', None) |
|
657 deleteTask(task, user, reason) |
|
658 return show_msg(user, "The task is deleted", '/', "to return to home page") |
|
659 else: |
|
660 return render_to_response('task/delete.html',{'user':user,}) |
|
661 else: |
|
662 return show_msg(user, "You are not authorised to do this at this stage", task_url, "view the task") |