8 from django.views.decorators.csrf import csrf_protect |
8 from django.views.decorators.csrf import csrf_protect |
9 |
9 |
10 from pytask.utils import make_key |
10 from pytask.utils import make_key |
11 from pytask.views import show_msg |
11 from pytask.views import show_msg |
12 |
12 |
13 from pytask.taskapp.models import Task |
13 from pytask.taskapp.models import Task, TaskComment |
14 from pytask.taskapp.forms import CreateTaskForm, EditTaskForm |
14 from pytask.taskapp.forms import CreateTaskForm, EditTaskForm, TaskCommentForm |
|
15 from pytask.taskapp.utils import getTask |
15 from pytask.profile.utils import get_notification |
16 from pytask.profile.utils import get_notification |
16 |
17 |
17 |
18 |
18 @login_required |
19 @login_required |
19 def create_task(request): |
20 def create_task(request): |
50 form = CreateTaskForm() |
51 form = CreateTaskForm() |
51 context.update({'form':form}) |
52 context.update({'form':form}) |
52 return render_to_response('task/create.html', context) |
53 return render_to_response('task/create.html', context) |
53 else: |
54 else: |
54 return show_msg(user, 'You are not authorised to create a task.') |
55 return show_msg(user, 'You are not authorised to create a task.') |
|
56 |
|
57 def view_task(request, tid): |
|
58 """ get the task depending on its tid and display accordingly if it is a get. |
|
59 check for authentication and add a comment if it is a post request. |
|
60 """ |
|
61 |
|
62 task_url = "/task/view/tid=%s"%tid |
|
63 task = getTask(tid) |
|
64 |
|
65 user = request.user |
|
66 profile = user.get_profile() |
|
67 |
|
68 context = {"user": user, |
|
69 "profile": profile, |
|
70 "task": task, |
|
71 } |
|
72 |
|
73 context.update(csrf(request)) |
|
74 |
|
75 if task.status == "DL": |
|
76 return show_msg(user, 'This task no longer exists', '/task/browse/','browse the tasks') |
|
77 |
|
78 comments = task.comments.filter(is_deleted=False).order_by('comment_datetime') |
|
79 reviewers = task.reviewers.all() |
|
80 |
|
81 is_guest = True if not user.is_authenticated() else False |
|
82 is_reviewer = True if user in task.reviewers.all() else False |
|
83 |
|
84 context.update({'is_guest':is_guest, |
|
85 'is_reviewer':is_reviewer, |
|
86 'comments':comments, |
|
87 'reviewers':reviewers, |
|
88 }) |
|
89 |
|
90 claimed_users = task.claimed_users.all() |
|
91 |
|
92 |
|
93 # is_requested_reviewer = True if user.is_authenticated() and user.request_sent_to.filter(is_valid=True,is_replied=False,role="MT",task=task) else False |
|
94 # task_viewable = True if ( task.status != "UP" ) or is_reviewer or is_requested_reviewer else False |
|
95 # if not task_viewable: |
|
96 # return show_msg(user, "You are not authorised to view this task", "/task/browse/", "browse the tasks") |
|
97 |
|
98 # context['is_requested_reviewer'] = is_requested_reviewer |
|
99 |
|
100 context['can_publish'] = True if task.status == "UP" and user == task.created_by else False |
|
101 context['can_edit'] = True if task.status == "UP" and is_reviewer else False |
|
102 context['can_close'] = True if task.status not in ["UP", "CD", "CM"] and is_reviewer else False |
|
103 context['can_delete'] = True if task.status == "UP" and user == task.created_by else False |
|
104 |
|
105 context['can_mod_reviewers'] = True if task.status in ["UP", "OP", "LO", "WR"] and is_reviewer else False |
|
106 context['can_mod_tasks'] = True if task.status in ["UP", "OP", "LO"] and is_reviewer else False |
|
107 |
|
108 context['can_assign_pynts'] = True if task.status in ["OP", "WR"] and is_reviewer else False |
|
109 context['task_claimable'] = True if task.status in ["OP", "WR"] and not is_guest else False |
|
110 |
|
111 # if task.status == "CD": |
|
112 # context['closing_notification'] = Notification.objects.filter(task=task,role="CD")[0] |
|
113 # elif task.status == "CM": |
|
114 # context['completed_notification'] = Notifications.objects.filter(task=task,role="CM")[0] |
|
115 # elif task.status == "WR": |
|
116 # context['assigned_users'] = task.assigned_users.all() |
|
117 |
|
118 if request.method == 'POST': |
|
119 if not is_guest: |
|
120 form = TaskCommentForm(request.POST) |
|
121 if form.is_valid(): |
|
122 data = form.cleaned_data['data'] |
|
123 new_comment = TaskComment(task=task, data=data, |
|
124 uniq_key=make_key(TaskComment), |
|
125 commented_by=user, comment_datetime=datetime.now()) |
|
126 new_comment.save() |
|
127 return redirect(task_url) |
|
128 else: |
|
129 context['form'] = form |
|
130 return render_to_response('task/view.html', context) |
|
131 else: |
|
132 return redirect(task_url) |
|
133 else: |
|
134 form = TaskCommentForm() |
|
135 context['form'] = form |
|
136 return render_to_response('task/view.html', context) |
|
137 |