|
1 """Module containing the views for all the task related activities. |
|
2 |
|
3 If there is something common to all other views. They sit here, here |
|
4 even if there nothing relevant to tasks alone since task is the basis |
|
5 for everything else. |
|
6 """ |
|
7 |
|
8 __authors__ = [ |
|
9 '"Nishanth Amuluru" <nishanth@fossee.in>', |
|
10 '"Madhusudan.C.S" <madhusudancs@fossee.in>', |
|
11 ] |
|
12 |
|
13 |
|
14 from datetime import datetime |
|
15 |
|
16 from django import shortcuts |
|
17 from django import http |
|
18 from django.contrib.auth.decorators import login_required |
|
19 from django.contrib.auth.models import User |
|
20 from django.core.context_processors import csrf |
|
21 from django.core.urlresolvers import reverse |
|
22 from django.template import RequestContext |
|
23 from django.utils import simplejson as json |
|
24 from django.utils.translation import ugettext |
|
25 |
|
26 from tagging.models import Tag |
|
27 |
|
28 from pytask.views import show_msg |
|
29 |
|
30 from pytask.profile import models as profile_models |
|
31 |
|
32 from pytask.taskapp import forms as taskapp_forms |
|
33 from pytask.taskapp import models as taskapp_models |
|
34 |
|
35 |
|
36 DONT_CLAIM_TASK_MSG = ugettext( |
|
37 "Please don't submit any claims for the tasks until the workshop is " |
|
38 "over. During the workshop we will introduce you to the work-flow of " |
|
39 "this entire project. Also please be warned that the task claim work-" |
|
40 "flow may change. So all the claims submitted before the workshop may " |
|
41 "not be valid.") |
|
42 |
|
43 |
|
44 @login_required |
|
45 def create_task(request): |
|
46 |
|
47 user = request.user |
|
48 profile = user.get_profile() |
|
49 |
|
50 context = {"user": user, |
|
51 "profile": profile, |
|
52 } |
|
53 |
|
54 context.update(csrf(request)) |
|
55 |
|
56 can_create_task = False if ( |
|
57 profile.role == profile_models.ROLES_CHOICES[3][0]) else True |
|
58 if can_create_task: |
|
59 if request.method == "POST": |
|
60 form = taskapp_forms.CreateTaskForm(request.POST) |
|
61 if form.is_valid(): |
|
62 data = form.cleaned_data.copy() |
|
63 data.update({"created_by": user, |
|
64 "creation_datetime": datetime.now(), |
|
65 }) |
|
66 |
|
67 task = taskapp_models.Task(**data) |
|
68 task.save() |
|
69 |
|
70 task_url = reverse('view_task', kwargs={'task_id': task.id}) |
|
71 return shortcuts.redirect(task_url) |
|
72 else: |
|
73 context.update({'form':form}) |
|
74 return shortcuts.render_to_response( |
|
75 'task/edit.html', RequestContext(request, context)) |
|
76 else: |
|
77 form = taskapp_forms.CreateTaskForm() |
|
78 context.update({'form': form}) |
|
79 return shortcuts.render_to_response( |
|
80 'task/edit.html', RequestContext(request, context)) |
|
81 else: |
|
82 return show_msg(user, 'You are not authorised to create a task.') |
|
83 |
|
84 def browse_tasks(request): |
|
85 |
|
86 context = {} |
|
87 |
|
88 # TODO(disable): Disable once the tasks can be claimed |
|
89 context['uberbar_message'] = DONT_CLAIM_TASK_MSG |
|
90 |
|
91 open_tasks = taskapp_models.Task.objects.filter( |
|
92 status=taskapp_models.TASK_STATUS_CHOICES[1][0]) |
|
93 working_tasks = taskapp_models.Task.objects.filter( |
|
94 status=taskapp_models.TASK_STATUS_CHOICES[3][0]) |
|
95 comp_tasks = taskapp_models.Task.objects.filter( |
|
96 status=taskapp_models.TASK_STATUS_CHOICES[6][0]) |
|
97 |
|
98 context.update({ |
|
99 'open_tasks': open_tasks, |
|
100 'working_tasks': working_tasks, |
|
101 'comp_tasks': comp_tasks, |
|
102 }) |
|
103 |
|
104 user = request.user |
|
105 if not user.is_authenticated(): |
|
106 return shortcuts.render_to_response('task/browse.html', |
|
107 RequestContext(request, context)) |
|
108 |
|
109 profile = user.get_profile() |
|
110 |
|
111 |
|
112 if profile.role in [profile_models.ROLES_CHOICES[0][0], |
|
113 profile_models.ROLES_CHOICES[1][0]]: |
|
114 can_approve = True |
|
115 else: |
|
116 can_approve = False |
|
117 |
|
118 unpub_tasks = taskapp_models.Task.objects.filter( |
|
119 status=taskapp_models.TASK_STATUS_CHOICES[0][0]).exclude( |
|
120 status=taskapp_models.TASK_STATUS_CHOICES[5][0]) |
|
121 |
|
122 if can_approve: |
|
123 context.update({'unpub_tasks': unpub_tasks}) |
|
124 |
|
125 context.update({'user': user, |
|
126 'profile': profile, |
|
127 }) |
|
128 |
|
129 return shortcuts.render_to_response('task/browse.html', |
|
130 RequestContext(request, context)) |
|
131 |
|
132 |
|
133 def view_task(request, task_id): |
|
134 """ get the task depending on its task_id and display accordingly if it is a get. |
|
135 check for authentication and add a comment if it is a post request. |
|
136 """ |
|
137 |
|
138 context = {} |
|
139 |
|
140 # TODO(disable): Disable once the tasks can be claimed |
|
141 context['uberbar_message'] = DONT_CLAIM_TASK_MSG |
|
142 |
|
143 task_url = reverse('view_task', kwargs={'task_id': task_id}) |
|
144 task = shortcuts.get_object_or_404(taskapp_models.Task, pk=task_id) |
|
145 |
|
146 user = request.user |
|
147 |
|
148 if not user.is_authenticated(): |
|
149 return shortcuts.render_to_response('task/view.html', {'task': task}) |
|
150 |
|
151 profile = user.get_profile() |
|
152 |
|
153 context.update({ |
|
154 'user': user, |
|
155 'profile': profile, |
|
156 'task': task, |
|
157 }) |
|
158 |
|
159 context.update(csrf(request)) |
|
160 |
|
161 if task.status == taskapp_models.TASK_STATUS_CHOICES[5][0]: |
|
162 return show_msg(user, 'This task no longer exists', |
|
163 reverse('browse_tasks'), 'browse the tasks') |
|
164 |
|
165 if ((task.status != taskapp_models.TASK_STATUS_CHOICES[0][0] ) |
|
166 or profile.role != profile_models.ROLES_CHOICES[3][0]): |
|
167 task_viewable = True |
|
168 else: |
|
169 task_viewable = False |
|
170 |
|
171 if not task_viewable: |
|
172 return show_msg(user, 'You are not authorised to view this task', |
|
173 reverse('browse_tasks'), 'browse the tasks') |
|
174 |
|
175 reviewers = task.reviewers.all() |
|
176 is_reviewer = True if user in task.reviewers.all() else False |
|
177 comments = task.comments.filter( |
|
178 is_deleted=False).order_by('comment_datetime') |
|
179 |
|
180 context.update({'is_reviewer':is_reviewer, |
|
181 'comments':comments, |
|
182 'reviewers':reviewers, |
|
183 }) |
|
184 |
|
185 selected_users = task.selected_users.all() |
|
186 |
|
187 user_role = user.get_profile().role |
|
188 is_creator = True if user == task.created_by else False |
|
189 |
|
190 context['selected_users'] = selected_users |
|
191 |
|
192 context['is_selected'] = True if user in selected_users else False |
|
193 |
|
194 if (task.status == taskapp_models.TASK_STATUS_CHOICES[0][0] and |
|
195 profile.role in [profile_models.ROLES_CHOICES[0][0], |
|
196 profile_models.ROLES_CHOICES[1][0]]): |
|
197 context['can_approve'] = True |
|
198 else: |
|
199 context['can_approve'] = False |
|
200 |
|
201 if ((is_creator or user_role != profile_models.ROLES_CHOICES[3][0]) |
|
202 and task.status == taskapp_models.TASK_STATUS_CHOICES[0][0]): |
|
203 context['can_edit'] = True |
|
204 else: |
|
205 context['can_edit'] = False |
|
206 |
|
207 if (task.status not in [taskapp_models.TASK_STATUS_CHOICES[0][0], |
|
208 taskapp_models.TASK_STATUS_CHOICES[4][0], |
|
209 taskapp_models.TASK_STATUS_CHOICES[6][0]] and is_reviewer): |
|
210 context['can_close'] = True |
|
211 else: |
|
212 context['can_close'] = False |
|
213 |
|
214 if task.status == taskapp_models.TASK_STATUS_CHOICES[0][0] and is_creator: |
|
215 context['can_delete'] = True |
|
216 else: |
|
217 context['can_delete'] = False |
|
218 |
|
219 if (task.status in [taskapp_models.TASK_STATUS_CHOICES[1][0], |
|
220 taskapp_models.TASK_STATUS_CHOICES[3][0]] and is_reviewer): |
|
221 context['can_assign_pynts'] = True |
|
222 else: |
|
223 context['can_assign_pynts'] = False |
|
224 |
|
225 if (task.status in [taskapp_models.TASK_STATUS_CHOICES[1][0], |
|
226 taskapp_models.TASK_STATUS_CHOICES[3][0]]): |
|
227 context['task_claimable'] = True |
|
228 else: |
|
229 context['task_claimable'] = False |
|
230 |
|
231 if (task.status != taskapp_models.TASK_STATUS_CHOICES[0][0] or\ |
|
232 profile.role != profile_models.ROLES_CHOICES[3][0]): |
|
233 context['can_comment'] = True |
|
234 else: |
|
235 context['can_comment'] = False |
|
236 |
|
237 if (profile.role in [profile_models.ROLES_CHOICES[0][0], |
|
238 profile_models.ROLES_CHOICES[1][0]]): |
|
239 context['can_mod_reviewers'] = True |
|
240 else: |
|
241 context['can_mod_reviewers'] = False |
|
242 |
|
243 if request.method == 'POST': |
|
244 form = taskapp_forms.TaskCommentForm(request.POST) |
|
245 if form.is_valid(): |
|
246 data = form.cleaned_data['data'] |
|
247 new_comment = taskapp_forms.TaskComment( |
|
248 task=task, data=data, commented_by=user, |
|
249 comment_datetime=datetime.now()) |
|
250 new_comment.save() |
|
251 return shortcuts.redirect(task_url) |
|
252 else: |
|
253 context['form'] = form |
|
254 return shortcuts.render_to_response( |
|
255 'task/view.html', RequestContext(request, context)) |
|
256 else: |
|
257 form = taskapp_forms.TaskCommentForm() |
|
258 context['form'] = form |
|
259 return shortcuts.render_to_response( |
|
260 'task/view.html', RequestContext(request, context)) |
|
261 |
|
262 @login_required |
|
263 def edit_task(request, task_id): |
|
264 """ only creator gets to edit the task and that too only before it gets |
|
265 approved. |
|
266 """ |
|
267 |
|
268 user = request.user |
|
269 profile = user.get_profile() |
|
270 |
|
271 task_url = reverse('view_task', kwargs={'task_id': task_id}) |
|
272 task = shortcuts.get_object_or_404(taskapp_models.Task, pk=task_id) |
|
273 |
|
274 is_creator = True if user == task.created_by else False |
|
275 can_edit = True if task.status == taskapp_models.TASK_STATUS_CHOICES[0][0] and is_creator else False |
|
276 if not can_edit: |
|
277 raise http.Http404 |
|
278 |
|
279 context = {"user": user, |
|
280 "profile": profile, |
|
281 "task": task, |
|
282 } |
|
283 |
|
284 context.update(csrf(request)) |
|
285 |
|
286 if request.method == "POST": |
|
287 form = taskapp_forms.EditTaskForm(request.POST, instance=task) |
|
288 if form.is_valid(): |
|
289 form.save() |
|
290 return shortcuts.redirect(task_url) |
|
291 else: |
|
292 context.update({"form": form}) |
|
293 return shortcuts.render_to_response( |
|
294 "task/edit.html", RequestContext(request, context)) |
|
295 else: |
|
296 form = taskapp_forms.EditTaskForm(instance=task) |
|
297 context.update({"form": form}) |
|
298 return shortcuts.render_to_response("task/edit.html", |
|
299 RequestContext(request, context)) |
|
300 |
|
301 @login_required |
|
302 def approve_task(request, task_id): |
|
303 |
|
304 user = request.user |
|
305 profile = user.get_profile() |
|
306 |
|
307 task = shortcuts.get_object_or_404(taskapp_models.Task, pk=task_id) |
|
308 |
|
309 if profile.role not in [profile_models.ROLES_CHOICES[0][0], profile_models.ROLES_CHOICES[1][0]] or task.status != taskapp_models.TASK_STATUS_CHOICES[0][0]: |
|
310 raise http.Http404 |
|
311 |
|
312 context = {"user": user, |
|
313 "profile": profile, |
|
314 "task": task, |
|
315 } |
|
316 |
|
317 return shortcuts.render_to_response( |
|
318 "task/confirm_approval.html", RequestContext(request, context)) |
|
319 |
|
320 @login_required |
|
321 def approved_task(request, task_id): |
|
322 |
|
323 user = request.user |
|
324 profile = user.get_profile() |
|
325 |
|
326 task = shortcuts.get_object_or_404(taskapp_models.Task, pk=task_id) |
|
327 |
|
328 if profile.role not in [profile_models.ROLES_CHOICES[0][0], profile_models.ROLES_CHOICES[1][0]] or task.status != taskapp_models.TASK_STATUS_CHOICES[0][0]: |
|
329 raise http.Http404 |
|
330 |
|
331 task.approved_by = user |
|
332 task.approval_datetime = datetime.now() |
|
333 task.status = taskapp_models.TASK_STATUS_CHOICES[1][0] |
|
334 task.save() |
|
335 |
|
336 context = {"user": user, |
|
337 "profile": profile, |
|
338 "task": task, |
|
339 } |
|
340 |
|
341 return shortcuts.render_to_response( |
|
342 "task/approved_task.html", RequestContext(request, context)) |
|
343 |
|
344 @login_required |
|
345 def addreviewer(request, task_id): |
|
346 |
|
347 user = request.user |
|
348 profile = user.get_profile() |
|
349 |
|
350 task_url = reverse('view_task', kwargs={'task_id': task_id}) |
|
351 task = shortcuts.get_object_or_404(taskapp_models.Task, pk=task_id) |
|
352 |
|
353 can_mod_reviewers = True if profile.role in [profile_models.ROLES_CHOICES[0][0], profile_models.ROLES_CHOICES[1][0]] else False |
|
354 if not can_mod_reviewers: |
|
355 raise http.Http404 |
|
356 |
|
357 context = {"user": user, |
|
358 "profile": profile, |
|
359 "task": task, |
|
360 } |
|
361 |
|
362 context.update(csrf(request)) |
|
363 |
|
364 |
|
365 # This part has to be made better |
|
366 reviewer_choices = User.objects.filter(is_active=True).\ |
|
367 exclude(reviewing_tasks__id=task_id).\ |
|
368 exclude(claimed_tasks__id=task_id).\ |
|
369 exclude(selected_tasks__id=task_id).\ |
|
370 exclude(created_tasks__id=task_id) |
|
371 |
|
372 choices = ((a_user.id,a_user.username) for a_user in reviewer_choices) |
|
373 label = "Reviewer" |
|
374 |
|
375 if request.method == "POST": |
|
376 form = taskapp_forms.ChoiceForm(choices, data=request.POST, label=label) |
|
377 if form.is_valid(): |
|
378 data = form.cleaned_data.copy() |
|
379 uid = data['choice'] |
|
380 reviewer = User.objects.get(id=uid) |
|
381 |
|
382 task.reviewers.add(reviewer) |
|
383 return shortcuts.redirect(task_url) |
|
384 else: |
|
385 context.update({"form": form}) |
|
386 return shortcuts.render_to_response( |
|
387 "task/addreviewer.html", RequestContext(request, context)) |
|
388 else: |
|
389 form = taskapp_forms.ChoiceForm(choices, label=label) |
|
390 context.update({"form": form}) |
|
391 return shortcuts.render_to_response( |
|
392 "task/addreviewer.html", RequestContext(request, context)) |
|
393 |
|
394 def view_work(request, task_id): |
|
395 |
|
396 task = shortcuts.get_object_or_404(taskapp_models.Task, pk=task_id) |
|
397 |
|
398 user = request.user |
|
399 old_reports = task.reports.all() |
|
400 |
|
401 context = { |
|
402 'task': task, |
|
403 'old_reports': old_reports, |
|
404 } |
|
405 |
|
406 if not user.is_authenticated(): |
|
407 return shortcuts.render_to_response( |
|
408 "task/view_work.html", RequestContext(request, context)) |
|
409 |
|
410 profile = user.get_profile() |
|
411 |
|
412 context.update({"user": user, |
|
413 "profile": profile, |
|
414 }) |
|
415 |
|
416 context.update(csrf(request)) |
|
417 |
|
418 working_users = task.selected_users.all() |
|
419 is_working = True if user in working_users else False |
|
420 |
|
421 context.update({"is_working": is_working}) |
|
422 |
|
423 return shortcuts.render_to_response("task/view_work.html", |
|
424 RequestContext(request, context)) |
|
425 |
|
426 @login_required |
|
427 def view_report(request, report_id): |
|
428 |
|
429 report = shortcuts.get_object_or_404(taskapp_models.WorkReport, |
|
430 pk=report_id) |
|
431 |
|
432 user = request.user |
|
433 context = {"report": report, |
|
434 "user": user, |
|
435 } |
|
436 |
|
437 if not user.is_authenticated(): |
|
438 return shortcuts.render_to_response( |
|
439 "task/view_report.html", RequestContext(request, context)) |
|
440 |
|
441 profile = user.get_profile() |
|
442 |
|
443 context.update({"profile": profile}) |
|
444 return shortcuts.render_to_response("task/view_report.html", |
|
445 RequestContext(request, context)) |
|
446 |
|
447 @login_required |
|
448 def submit_report(request, task_id): |
|
449 """ Check if the work is in WR state and the user is in assigned_users. |
|
450 """ |
|
451 task_url = reverse('view_task', kwargs={'task_id': task_id}) |
|
452 task = shortcuts.get_object_or_404(taskapp_models.Task, pk=task_id) |
|
453 |
|
454 user = request.user |
|
455 old_reports = task.reports.all() |
|
456 |
|
457 if not task.status == taskapp_models.TASK_STATUS_CHOICES[3][0]: |
|
458 raise http.Http404 |
|
459 |
|
460 can_upload = True if user in task.selected_users.all() else False |
|
461 |
|
462 context = { |
|
463 'user': user, |
|
464 'task': task, |
|
465 'can_upload': can_upload, |
|
466 } |
|
467 |
|
468 context.update(csrf(request)) |
|
469 |
|
470 if request.method == "POST": |
|
471 if not can_upload: |
|
472 return show_msg(user, "You are not authorised to upload data to this task", task_url, "view the task") |
|
473 |
|
474 form = taskapp_forms.WorkReportForm(request.POST, request.FILES) |
|
475 |
|
476 if form.is_valid(): |
|
477 data = form.cleaned_data.copy() |
|
478 data.update({"task":task, |
|
479 "revision": old_reports.count(), |
|
480 "submitted_by": user, |
|
481 "submitted_at": datetime.now(), |
|
482 }) |
|
483 r = taskapp_models.WorkReport(**data) |
|
484 r.save() |
|
485 |
|
486 report_url = reverse('view_report', kwargs={'report_id': r.id}) |
|
487 return shortcuts.redirect(report_url) |
|
488 |
|
489 else: |
|
490 context.update({"form":form}) |
|
491 return shortcuts.render_to_response( |
|
492 'task/submit_report.html', RequestContext(request, context)) |
|
493 |
|
494 else: |
|
495 form = taskapp_forms.WorkReportForm() |
|
496 context.update({"form":form}) |
|
497 return shortcuts.render_to_response( |
|
498 'task/submit_report.html', RequestContext(request, context)) |
|
499 |
|
500 @login_required |
|
501 def claim_task(request, task_id): |
|
502 |
|
503 context = {} |
|
504 |
|
505 # TODO(disable): Disable once the tasks can be claimed |
|
506 context['uberbar_message'] = DONT_CLAIM_TASK_MSG |
|
507 |
|
508 claim_url = reverse('claim_task', kwargs={'task_id': task_id}) |
|
509 task = shortcuts.get_object_or_404(taskapp_models.Task, pk=task_id) |
|
510 |
|
511 if task.status == taskapp_models.TASK_STATUS_CHOICES[0][0]: |
|
512 raise http.Http404 |
|
513 |
|
514 user = request.user |
|
515 profile = user.get_profile() |
|
516 |
|
517 context.update({ |
|
518 'user': user, |
|
519 'profile': profile, |
|
520 'task': task, |
|
521 }) |
|
522 |
|
523 context.update(csrf(request)) |
|
524 |
|
525 reviewers = task.reviewers.all() |
|
526 claimed_users = task.claimed_users.all() |
|
527 |
|
528 is_creator = True if user == task.created_by else False |
|
529 is_reviewer = True if user in reviewers else False |
|
530 has_claimed = True if user in claimed_users else False |
|
531 |
|
532 task_claimable = True if task.status in [taskapp_models.TASK_STATUS_CHOICES[1][0], taskapp_models.TASK_STATUS_CHOICES[3][0]] else False |
|
533 can_claim = True if task_claimable and ( not has_claimed )\ |
|
534 and ( not is_reviewer ) and (not is_creator ) \ |
|
535 else False |
|
536 |
|
537 old_claims = task.claims.all() |
|
538 |
|
539 context.update({"is_creator": is_creator, |
|
540 "task_claimable": task_claimable, |
|
541 "can_claim": can_claim, |
|
542 "old_claims": old_claims}) |
|
543 |
|
544 if request.method == "POST" and can_claim: |
|
545 form = taskapp_forms.ClaimTaskForm(request.POST) |
|
546 if form.is_valid(): |
|
547 data = form.cleaned_data.copy() |
|
548 data.update({"task": task, |
|
549 "claim_datetime": datetime.now(), |
|
550 "claimed_by": user,}) |
|
551 new_claim = taskapp_models.TaskClaim(**data) |
|
552 new_claim.save() |
|
553 |
|
554 task.claimed_users.add(user) |
|
555 task.save() |
|
556 |
|
557 return shortcuts.redirect(claim_url) |
|
558 |
|
559 else: |
|
560 context.update({"form": form}) |
|
561 return shortcuts.render_to_response( |
|
562 "task/claim.html", RequestContext(request, context)) |
|
563 else: |
|
564 form = taskapp_forms.ClaimTaskForm() |
|
565 context.update({"form": form}) |
|
566 return shortcuts.render_to_response( |
|
567 "task/claim.html", RequestContext(request, context)) |
|
568 |
|
569 @login_required |
|
570 def select_user(request, task_id): |
|
571 """ first get the status of the task and then select one of claimed users |
|
572 generate list of claimed users by passing it as an argument to a function. |
|
573 """ |
|
574 |
|
575 task_url = reverse('view_task', kwargs={'task_id': task_id}) |
|
576 |
|
577 user = request.user |
|
578 profile = user.get_profile() |
|
579 task = shortcuts.get_object_or_404(taskapp_models.Task, pk=task_id) |
|
580 |
|
581 context = {"user": user, |
|
582 "profile": profile, |
|
583 "task": task, |
|
584 } |
|
585 |
|
586 context.update(csrf(request)) |
|
587 |
|
588 claimed_users = task.claimed_users.all() |
|
589 task_claimed = True if claimed_users else False |
|
590 |
|
591 is_creator = True if user == task.created_by else False |
|
592 |
|
593 if (is_creator or profile.role in [profile_models.ROLES_CHOICES[1][0], profile_models.ROLES_CHOICES[2][0]]) and \ |
|
594 task.status in [taskapp_models.TASK_STATUS_CHOICES[1][0], taskapp_models.TASK_STATUS_CHOICES[3][0]]: |
|
595 |
|
596 if task_claimed: |
|
597 |
|
598 user_list = ((user.id,user.username) for user in claimed_users) |
|
599 |
|
600 if request.method == "POST": |
|
601 form = taskapp_forms.ChoiceForm(user_list, request.POST) |
|
602 if form.is_valid(): |
|
603 uid = form.cleaned_data['choice'] |
|
604 selected_user = User.objects.get(id=uid) |
|
605 |
|
606 task.selected_users.add(selected_user) |
|
607 task.claimed_users.remove(selected_user) |
|
608 task.status = taskapp_models.TASK_STATUS_CHOICES[3][0] |
|
609 task.save() |
|
610 |
|
611 return shortcuts.redirect(task_url) |
|
612 else: |
|
613 context.update({"form": form}) |
|
614 return shortcuts.render_to_response( |
|
615 'task/select_user.html', |
|
616 RequestContext(request, context)) |
|
617 else: |
|
618 form = taskapp_forms.ChoiceForm(user_list) |
|
619 context.update({"form": form}) |
|
620 return shortcuts.render_to_response( |
|
621 'task/select_user.html', |
|
622 RequestContext(request, context)) |
|
623 else: |
|
624 return show_msg(user, 'There are no pending claims for this task', |
|
625 task_url, 'view the task') |
|
626 else: |
|
627 raise http.Http404 |
|
628 |
|
629 def suggest_task_tags(request): |
|
630 """Returns the tags matching the query for the AJAXy autocomplete |
|
631 to get tags related to tasks. |
|
632 """ |
|
633 |
|
634 term = request.GET.get('term', None) |
|
635 response = [] |
|
636 |
|
637 if term: |
|
638 tag_entities = Tag.objects.filter(name__icontains=term) |
|
639 response = [tag.name for tag in tag_entities] |
|
640 |
|
641 json_response = json.dumps(response) |
|
642 return http.HttpResponse(json_response) |