26 "profile": profile, |
28 "profile": profile, |
27 } |
29 } |
28 |
30 |
29 context.update(csrf(request)) |
31 context.update(csrf(request)) |
30 |
32 |
31 can_create_task = False if profile.rights == "CT" else True |
33 can_create_task = False if ( |
|
34 profile.role == profile_models.ROLE_CHOICES[3][0]) else True |
32 if can_create_task: |
35 if can_create_task: |
33 if request.method == "POST": |
36 if request.method == "POST": |
34 form = taskapp_forms.CreateTaskForm(request.POST) |
37 form = taskapp_forms.CreateTaskForm(request.POST) |
35 if form.is_valid(): |
38 if form.is_valid(): |
36 data = form.cleaned_data.copy() |
39 data = form.cleaned_data.copy() |
54 else: |
57 else: |
55 return show_msg(user, 'You are not authorised to create a task.') |
58 return show_msg(user, 'You are not authorised to create a task.') |
56 |
59 |
57 def browse_tasks(request): |
60 def browse_tasks(request): |
58 |
61 |
59 open_tasks = taskapp_models.Task.objects.filter(status="OP") |
62 open_tasks = taskapp_models.Task.objects.filter(status=taskapp_models.TASK_STATUS_CHOICES[1][0]) |
60 working_tasks = taskapp_models.Task.objects.filter(status="WR") |
63 working_tasks = taskapp_models.Task.objects.filter(status=taskapp_models.TASK_STATUS_CHOICES[3][0]) |
61 comp_tasks = taskapp_models.Task.objects.filter(status="CM") |
64 comp_tasks = taskapp_models.Task.objects.filter(status=taskapp_models.TASK_STATUS_CHOICES[6][0]) |
62 |
65 |
63 context = {"open_tasks": open_tasks, |
66 context = {"open_tasks": open_tasks, |
64 "working_tasks": working_tasks, |
67 "working_tasks": working_tasks, |
65 "comp_tasks": comp_tasks, |
68 "comp_tasks": comp_tasks, |
66 } |
69 } |
69 if not user.is_authenticated(): |
72 if not user.is_authenticated(): |
70 return shortcuts.render_to_response("task/browse.html") |
73 return shortcuts.render_to_response("task/browse.html") |
71 |
74 |
72 profile = user.get_profile() |
75 profile = user.get_profile() |
73 |
76 |
74 can_approve = True if profile.rights in ["MG", "DC"] else False |
77 can_approve = True if profile.role in [profile_models.ROLE_CHOICES[0][0], profile_models.ROLE_CHOICES[1][0]] else False |
75 unpub_tasks = taskapp_models.Task.objects.filter(status="UP").exclude(status="DL") |
78 unpub_tasks = taskapp_models.Task.objects.filter(status=taskapp_models.TASK_STATUS_CHOICES[0][0]).exclude(status=taskapp_models.TASK_STATUS_CHOICES[5][0]) |
76 if can_approve: |
79 if can_approve: |
77 context.update({"unpub_tasks": unpub_tasks}) |
80 context.update({"unpub_tasks": unpub_tasks}) |
78 |
81 |
79 context.update({"user": user, |
82 context.update({"user": user, |
80 "profile": profile, |
83 "profile": profile, |
103 "task": task, |
106 "task": task, |
104 } |
107 } |
105 |
108 |
106 context.update(csrf(request)) |
109 context.update(csrf(request)) |
107 |
110 |
108 if task.status == "DL": |
111 if task.status == taskapp_models.TASK_STATUS_CHOICES[5][0]: |
109 return show_msg(user, 'This task no longer exists', |
112 return show_msg(user, 'This task no longer exists', |
110 reverse('browse_tasks'), 'browse the tasks') |
113 reverse('browse_tasks'), 'browse the tasks') |
111 |
114 |
112 task_viewable = True if ( task.status != "UP" ) or profile.rights != "CT"\ |
115 task_viewable = True if ( task.status != taskapp_models.TASK_STATUS_CHOICES[0][0] ) or profile.role != profile_models.ROLE_CHOICES[3][0] \ |
113 else False |
116 else False |
114 if not task_viewable: |
117 if not task_viewable: |
115 return show_msg(user, "You are not authorised to view this task", |
118 return show_msg(user, "You are not authorised to view this task", |
116 reverse('browse_tasks'), "browse the tasks") |
119 reverse('browse_tasks'), "browse the tasks") |
117 |
120 |
129 |
132 |
130 is_creator = True if user == task.created_by else False |
133 is_creator = True if user == task.created_by else False |
131 |
134 |
132 context['selected_users'] = selected_users |
135 context['selected_users'] = selected_users |
133 context['is_selected'] = True if user in selected_users else False |
136 context['is_selected'] = True if user in selected_users else False |
134 context['can_approve'] = True if task.status == "UP" and\ |
137 context['can_approve'] = True if task.status == taskapp_models.TASK_STATUS_CHOICES[0][0] and\ |
135 profile.rights in ["MG", "DC"]\ |
138 profile.role in [profile_models.ROLE_CHOICES[0][0], profile_models.ROLE_CHOICES[1][0]]\ |
136 else False |
139 else False |
137 context['can_edit'] = True if is_creator and task.status == "UP" else False |
140 context['can_edit'] = True if is_creator and task.status == taskapp_models.TASK_STATUS_CHOICES[0][0] else False |
138 context['can_close'] = True if task.status not in ["UP", "CD", "CM"] and is_reviewer else False |
141 context['can_close'] = True if task.status not in [taskapp_models.TASK_STATUS_CHOICES[0][0], taskapp_models.TASK_STATUS_CHOICES[4][0], taskapp_models.TASK_STATUS_CHOICES[6][0]] and is_reviewer else False |
139 context['can_delete'] = True if task.status == "UP" and is_creator else False |
142 context['can_delete'] = True if task.status == taskapp_models.TASK_STATUS_CHOICES[0][0] and is_creator else False |
140 |
143 |
141 context['can_assign_pynts'] = True if task.status in ["OP", "WR"] and is_reviewer else False |
144 context['can_assign_pynts'] = True if task.status in [taskapp_models.TASK_STATUS_CHOICES[1][0], taskapp_models.TASK_STATUS_CHOICES[3][0]] and is_reviewer else False |
142 context['task_claimable'] = True if task.status in ["OP", "WR"] else False |
145 context['task_claimable'] = True if task.status in [taskapp_models.TASK_STATUS_CHOICES[1][0], taskapp_models.TASK_STATUS_CHOICES[3][0]] else False |
143 |
146 |
144 context['can_comment'] = True if task.status != "UP" or\ |
147 context['can_comment'] = True if task.status != taskapp_models.TASK_STATUS_CHOICES[0][0] or\ |
145 profile.rights!="CT" else False |
148 profile.role != profile_models.ROLE_CHOICES[3][0] else False |
146 |
149 |
147 context['can_mod_reviewers'] = True if profile.rights in ["MG", "DC"] else\ |
150 context['can_mod_reviewers'] = True if profile.role in [profile_models.ROLE_CHOICES[0][0], profile_models.ROLE_CHOICES[1][0]] else\ |
148 False |
151 False |
149 |
152 |
150 if request.method == 'POST': |
153 if request.method == 'POST': |
151 form = taskapp_forms.TaskCommentForm(request.POST) |
154 form = taskapp_forms.TaskCommentForm(request.POST) |
152 if form.is_valid(): |
155 if form.is_valid(): |
175 |
178 |
176 task_url = reverse('view_task', kwargs={'task_id': task_id}) |
179 task_url = reverse('view_task', kwargs={'task_id': task_id}) |
177 task = shortcuts.get_object_or_404(taskapp_models.Task, pk=task_id) |
180 task = shortcuts.get_object_or_404(taskapp_models.Task, pk=task_id) |
178 |
181 |
179 is_creator = True if user == task.created_by else False |
182 is_creator = True if user == task.created_by else False |
180 can_edit = True if task.status == "UP" and is_creator else False |
183 can_edit = True if task.status == taskapp_models.TASK_STATUS_CHOICES[0][0] and is_creator else False |
181 if not can_edit: |
184 if not can_edit: |
182 raise http.Http404 |
185 raise http.Http404 |
183 |
186 |
184 context = {"user": user, |
187 context = {"user": user, |
185 "profile": profile, |
188 "profile": profile, |
207 user = request.user |
210 user = request.user |
208 profile = user.get_profile() |
211 profile = user.get_profile() |
209 |
212 |
210 task = shortcuts.get_object_or_404(taskapp_models.Task, pk=task_id) |
213 task = shortcuts.get_object_or_404(taskapp_models.Task, pk=task_id) |
211 |
214 |
212 if profile.rights not in ["MG", "DC"] or task.status != "UP": |
215 if profile.role not in [profile_models.ROLE_CHOICES[0][0], profile_models.ROLE_CHOICES[1][0]] or task.status != taskapp_models.TASK_STATUS_CHOICES[0][0]: |
213 raise http.Http404 |
216 raise http.Http404 |
214 |
217 |
215 context = {"user": user, |
218 context = {"user": user, |
216 "profile": profile, |
219 "profile": profile, |
217 "task": task, |
220 "task": task, |
225 user = request.user |
228 user = request.user |
226 profile = user.get_profile() |
229 profile = user.get_profile() |
227 |
230 |
228 task = shortcuts.get_object_or_404(taskapp_models.Task, pk=task_id) |
231 task = shortcuts.get_object_or_404(taskapp_models.Task, pk=task_id) |
229 |
232 |
230 if profile.rights not in ["MG", "DC"] or task.status != "UP": |
233 if profile.role not in [profile_models.ROLE_CHOICES[0][0], profile_models.ROLE_CHOICES[1][0]] or task.status != taskapp_models.TASK_STATUS_CHOICES[0][0]: |
231 raise http.Http404 |
234 raise http.Http404 |
232 |
235 |
233 task.approved_by = user |
236 task.approved_by = user |
234 task.approval_datetime = datetime.now() |
237 task.approval_datetime = datetime.now() |
235 task.status = "OP" |
238 task.status = taskapp_models.TASK_STATUS_CHOICES[1][0] |
236 task.save() |
239 task.save() |
237 |
240 |
238 context = {"user": user, |
241 context = {"user": user, |
239 "profile": profile, |
242 "profile": profile, |
240 "task": task, |
243 "task": task, |
249 profile = user.get_profile() |
252 profile = user.get_profile() |
250 |
253 |
251 task_url = reverse('view_task', kwargs={'task_id': task_id}) |
254 task_url = reverse('view_task', kwargs={'task_id': task_id}) |
252 task = shortcuts.get_object_or_404(taskapp_models.Task, pk=task_id) |
255 task = shortcuts.get_object_or_404(taskapp_models.Task, pk=task_id) |
253 |
256 |
254 can_mod_reviewers = True if profile.rights in ["MG", "DC"] else False |
257 can_mod_reviewers = True if profile.role in [profile_models.ROLE_CHOICES[0][0], profile_models.ROLE_CHOICES[1][0]] else False |
255 if not can_mod_reviewers: |
258 if not can_mod_reviewers: |
256 raise http.Http404 |
259 raise http.Http404 |
257 |
260 |
258 context = {"user": user, |
261 context = {"user": user, |
259 "profile": profile, |
262 "profile": profile, |
449 "textbook": textbook, |
452 "textbook": textbook, |
450 }) |
453 }) |
451 |
454 |
452 context.update(csrf(request)) |
455 context.update(csrf(request)) |
453 |
456 |
454 can_edit = True if user == textbook.created_by and textbook.status == "UP"\ |
457 can_edit = True if user == textbook.created_by and textbook.status == taskapp_models.TB_STATUS_CHOICES[0][0]\ |
455 else False |
458 else False |
456 |
459 |
457 can_approve = True if profile.rights in ["MG", "DC"] and \ |
460 can_approve = True if profile.role in [profile_models.ROLE_CHOICES[0][0], profile_models.ROLE_CHOICES[1][0]] and \ |
458 textbook.status == "UP" else False |
461 textbook.status == taskapp_models.TB_STATUS_CHOICES[0][0] else False |
459 |
462 |
460 context.update({"can_edit": can_edit, |
463 context.update({"can_edit": can_edit, |
461 "can_approve": can_approve}) |
464 "can_approve": can_approve}) |
462 return shortcuts.render_to_response("task/view_textbook.html", context) |
465 return shortcuts.render_to_response("task/view_textbook.html", context) |
463 |
466 |
464 def browse_textbooks(request): |
467 def browse_textbooks(request): |
465 |
468 |
466 user = request.user |
469 user = request.user |
467 |
470 |
468 open_textbooks = taskapp_models.TextBook.objects.filter(status="OP").\ |
471 open_textbooks = taskapp_models.TextBook.objects.filter(status=taskapp_models.TB_STATUS_CHOICES[1][0]).\ |
469 order_by("creation_datetime") |
472 order_by("creation_datetime") |
470 comp_textbooks = taskapp_models.TextBook.objects.filter(status="CM").\ |
473 comp_textbooks = taskapp_models.TextBook.objects.filter(status=taskapp_models.TB_STATUS_CHOICES[3][0]).\ |
471 order_by("creation_datetime") |
474 order_by("creation_datetime") |
472 context = {"user": user, |
475 context = {"user": user, |
473 "open_textbooks": open_textbooks, |
476 "open_textbooks": open_textbooks, |
474 "comp_textbooks": comp_textbooks, |
477 "comp_textbooks": comp_textbooks, |
475 } |
478 } |
476 |
479 |
477 if user.is_authenticated() and user.get_profile().rights in ["DC", "MG"]: |
480 if user.is_authenticated() and user.get_profile().role in [profile_models.ROLE_CHOICES[0][0], profile_models.ROLE_CHOICES[1][0]]: |
478 unpub_textbooks = taskapp_models.TextBook.objects.filter(status="UP") |
481 unpub_textbooks = taskapp_models.TextBook.objects.filter(status=taskapp_models.TB_STATUS_CHOICES[0][0]) |
479 |
482 |
480 context.update({"unpub_textbooks": unpub_textbooks}) |
483 context.update({"unpub_textbooks": unpub_textbooks}) |
481 |
484 |
482 return shortcuts.render_to_response("task/browse_textbooks.html", context) |
485 return shortcuts.render_to_response("task/browse_textbooks.html", context) |
483 |
486 |
489 |
492 |
490 textbook = shortcuts.get_object_or_404(taskapp_models.TextBook, pk=task_id) |
493 textbook = shortcuts.get_object_or_404(taskapp_models.TextBook, pk=task_id) |
491 textbook_url = reverse( |
494 textbook_url = reverse( |
492 'view_textbook', kwargs={'task_id': textbook.id}) |
495 'view_textbook', kwargs={'task_id': textbook.id}) |
493 |
496 |
494 can_edit = True if user == textbook.created_by and textbook.status == "UP"\ |
497 can_edit = True if user == textbook.created_by and textbook.status == taskapp_models.TB_STATUS_CHOICES[0][0]\ |
495 else False |
498 else False |
496 |
499 |
497 if not can_edit: |
500 if not can_edit: |
498 raise http.Http404 |
501 raise http.Http404 |
499 |
502 |
521 def claim_task(request, task_id): |
524 def claim_task(request, task_id): |
522 |
525 |
523 claim_url = reverse('claim_task', kwargs={'task_id': task_id}) |
526 claim_url = reverse('claim_task', kwargs={'task_id': task_id}) |
524 task = shortcuts.get_object_or_404(taskapp_models.Task, pk=task_id) |
527 task = shortcuts.get_object_or_404(taskapp_models.Task, pk=task_id) |
525 |
528 |
526 if task.status == "UP": |
529 if task.status == taskapp_models.TASK_STATUS_CHOICES[0][0]: |
527 raise http.Http404 |
530 raise http.Http404 |
528 |
531 |
529 user = request.user |
532 user = request.user |
530 profile = user.get_profile() |
533 profile = user.get_profile() |
531 |
534 |
541 |
544 |
542 is_creator = True if user == task.created_by else False |
545 is_creator = True if user == task.created_by else False |
543 is_reviewer = True if user in reviewers else False |
546 is_reviewer = True if user in reviewers else False |
544 has_claimed = True if user in claimed_users else False |
547 has_claimed = True if user in claimed_users else False |
545 |
548 |
546 task_claimable = True if task.status in ["OP", "WR"] else False |
549 task_claimable = True if task.status in [taskapp_models.TASK_STATUS_CHOICES[1][0], taskapp_models.TASK_STATUS_CHOICES[3][0]] else False |
547 can_claim = True if task_claimable and ( not has_claimed )\ |
550 can_claim = True if task_claimable and ( not has_claimed )\ |
548 and ( not is_reviewer ) and (not is_creator ) \ |
551 and ( not is_reviewer ) and (not is_creator ) \ |
549 else False |
552 else False |
550 |
553 |
551 old_claims = task.claims.all() |
554 old_claims = task.claims.all() |
600 claimed_users = task.claimed_users.all() |
603 claimed_users = task.claimed_users.all() |
601 task_claimed = True if claimed_users else False |
604 task_claimed = True if claimed_users else False |
602 |
605 |
603 is_creator = True if user == task.created_by else False |
606 is_creator = True if user == task.created_by else False |
604 |
607 |
605 if ( is_creator or profile.rights in ["CR", "DC"] ) and \ |
608 if (is_creator or profile.role in [profile_models.ROLE_CHOICES[1][0], profile_models.ROLE_CHOICES[2][0]]) and \ |
606 task.status in ["OP", "WR"]: |
609 task.status in [taskapp_models.TASK_STATUS_CHOICES[1][0], taskapp_models.TASK_STATUS_CHOICES[3][0]]: |
607 |
610 |
608 if task_claimed: |
611 if task_claimed: |
609 |
612 |
610 user_list = ((user.id,user.username) for user in claimed_users) |
613 user_list = ((user.id,user.username) for user in claimed_users) |
611 |
614 |
615 uid = form.cleaned_data['choice'] |
618 uid = form.cleaned_data['choice'] |
616 selected_user = User.objects.get(id=uid) |
619 selected_user = User.objects.get(id=uid) |
617 |
620 |
618 task.selected_users.add(selected_user) |
621 task.selected_users.add(selected_user) |
619 task.claimed_users.remove(selected_user) |
622 task.claimed_users.remove(selected_user) |
620 task.status = "WR" |
623 task.status = taskapp_models.TASK_STATUS_CHOICES[3][0] |
621 task.save() |
624 task.save() |
622 |
625 |
623 return shortcuts.redirect(task_url) |
626 return shortcuts.redirect(task_url) |
624 else: |
627 else: |
625 context.update({"form": form}) |
628 context.update({"form": form}) |
640 user = request.user |
643 user = request.user |
641 profile = user.get_profile() |
644 profile = user.get_profile() |
642 |
645 |
643 textbook = shortcuts.get_object_or_404(taskapp_models.TextBook, pk=task_id) |
646 textbook = shortcuts.get_object_or_404(taskapp_models.TextBook, pk=task_id) |
644 |
647 |
645 if profile.rights not in ["MG", "DC"] or textbook.status != "UP": |
648 if profile.role not in [profile_models.ROLE_CHOICES[0][0], profile_models.ROLE_CHOICES[1][0]] or textbook.status != taskapp_models.TB_STATUS_CHOICES[0][0]: |
646 raise http.Http404 |
649 raise http.Http404 |
647 |
650 |
648 context = {"user": user, |
651 context = {"user": user, |
649 "profile": profile, |
652 "profile": profile, |
650 "textbook": textbook, |
653 "textbook": textbook, |
658 user = request.user |
661 user = request.user |
659 profile = user.get_profile() |
662 profile = user.get_profile() |
660 |
663 |
661 textbook = shortcuts.get_object_or_404(taskapp_models.TextBook, pk=task_id) |
664 textbook = shortcuts.get_object_or_404(taskapp_models.TextBook, pk=task_id) |
662 |
665 |
663 if profile.rights not in ["MG", "DC"] or textbook.status != "UP": |
666 if profile.role not in [profile_models.ROLE_CHOICES[0][0], profile_models.ROLE_CHOICES[1][0]] or textbook.status != taskapp_models.TB_STATUS_CHOICES[0][0]: |
664 raise http.Http404 |
667 raise http.Http404 |
665 |
668 |
666 textbook.approved_by = user |
669 textbook.approved_by = user |
667 textbook.approval_datetime = datetime.now() |
670 textbook.approval_datetime = datetime.now() |
668 textbook.status = "OP" |
671 textbook.status = taskapp_models.TB_STATUS_CHOICES[1][0] |
669 textbook.save() |
672 textbook.save() |
670 |
673 |
671 context = {"user": user, |
674 context = {"user": user, |
672 "profile": profile, |
675 "profile": profile, |
673 "textbook": textbook, |
676 "textbook": textbook, |