author | Madhusudan.C.S <madhusudancs@gmail.com> |
Sun, 30 Jan 2011 20:05:38 +0530 | |
changeset 529 | 58b9a98ffbcf |
parent 528 | 56474add44b1 |
child 530 | ab9b9e59de9d |
permissions | -rwxr-xr-x |
333
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
1 |
from datetime import datetime |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
2 |
|
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
3 |
from django import shortcuts |
425
e15749fab2e4
Restructured create form to use templatetags and use Javascript for autcomplete.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
422
diff
changeset
|
4 |
from django import http |
408
0c12181e2c02
Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
387
diff
changeset
|
5 |
from django.contrib.auth.decorators import login_required |
362
070f01dd7d8e
Select user works completely fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
360
diff
changeset
|
6 |
from django.contrib.auth.models import User |
333
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
7 |
from django.core.context_processors import csrf |
408
0c12181e2c02
Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
387
diff
changeset
|
8 |
from django.core.urlresolvers import reverse |
451
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
9 |
from django.template import RequestContext |
425
e15749fab2e4
Restructured create form to use templatetags and use Javascript for autcomplete.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
422
diff
changeset
|
10 |
from django.utils import simplejson as json |
507
1d4631fcebd0
Add uberbar messages not to claim the task. This must be disabled once claiming is possible.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
506
diff
changeset
|
11 |
from django.utils.translation import ugettext |
333
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
12 |
|
497
6386458d749b
List each department textbooks separately for now, think of a clever way later.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
495
diff
changeset
|
13 |
from tagging.managers import TaggedItem |
428
c9d8cd54195e
Remove the redundant function for suggesting tags and added the required import.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
427
diff
changeset
|
14 |
from tagging.models import Tag |
c9d8cd54195e
Remove the redundant function for suggesting tags and added the required import.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
427
diff
changeset
|
15 |
|
408
0c12181e2c02
Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
387
diff
changeset
|
16 |
from pytask.views import show_msg |
333
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
17 |
|
440
56ea209e559f
Use the right form of names to be stored in the database.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
430
diff
changeset
|
18 |
from pytask.profile import models as profile_models |
56ea209e559f
Use the right form of names to be stored in the database.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
430
diff
changeset
|
19 |
|
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
20 |
from pytask.taskapp import forms as taskapp_forms |
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
21 |
from pytask.taskapp import models as taskapp_models |
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
22 |
|
339
bce480ff6ddc
used proper import for show_msg
Nishanth Amuluru <nishanth@fossee.in>
parents:
333
diff
changeset
|
23 |
|
507
1d4631fcebd0
Add uberbar messages not to claim the task. This must be disabled once claiming is possible.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
506
diff
changeset
|
24 |
DONT_CLAIM_TASK_MSG = ugettext( |
1d4631fcebd0
Add uberbar messages not to claim the task. This must be disabled once claiming is possible.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
506
diff
changeset
|
25 |
"Please don't submit any claims for the tasks until the workshop is " |
1d4631fcebd0
Add uberbar messages not to claim the task. This must be disabled once claiming is possible.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
506
diff
changeset
|
26 |
"over. During the workshop we will introduce you to the work-flow of " |
1d4631fcebd0
Add uberbar messages not to claim the task. This must be disabled once claiming is possible.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
506
diff
changeset
|
27 |
"this entire project. Also please be warned that the task claim work-" |
1d4631fcebd0
Add uberbar messages not to claim the task. This must be disabled once claiming is possible.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
506
diff
changeset
|
28 |
"flow may change. So all the claims submitted before the workshop may " |
1d4631fcebd0
Add uberbar messages not to claim the task. This must be disabled once claiming is possible.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
506
diff
changeset
|
29 |
"not be valid.") |
1d4631fcebd0
Add uberbar messages not to claim the task. This must be disabled once claiming is possible.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
506
diff
changeset
|
30 |
|
1d4631fcebd0
Add uberbar messages not to claim the task. This must be disabled once claiming is possible.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
506
diff
changeset
|
31 |
|
333
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
32 |
@login_required |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
33 |
def create_task(request): |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
34 |
|
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
35 |
user = request.user |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
36 |
profile = user.get_profile() |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
37 |
|
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
38 |
context = {"user": user, |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
39 |
"profile": profile, |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
40 |
} |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
41 |
|
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
42 |
context.update(csrf(request)) |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
43 |
|
440
56ea209e559f
Use the right form of names to be stored in the database.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
430
diff
changeset
|
44 |
can_create_task = False if ( |
443
a13ea00c1a3f
Use the correct choices variable for the role and status.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
440
diff
changeset
|
45 |
profile.role == profile_models.ROLES_CHOICES[3][0]) else True |
333
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
46 |
if can_create_task: |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
47 |
if request.method == "POST": |
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
48 |
form = taskapp_forms.CreateTaskForm(request.POST) |
333
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
49 |
if form.is_valid(): |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
50 |
data = form.cleaned_data.copy() |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
51 |
data.update({"created_by": user, |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
52 |
"creation_datetime": datetime.now(), |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
53 |
}) |
408
0c12181e2c02
Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
387
diff
changeset
|
54 |
|
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
55 |
task = taskapp_models.Task(**data) |
333
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
56 |
task.save() |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
57 |
|
408
0c12181e2c02
Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
387
diff
changeset
|
58 |
task_url = reverse('view_task', kwargs={'task_id': task.id}) |
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
59 |
return shortcuts.redirect(task_url) |
333
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
60 |
else: |
340 | 61 |
context.update({'form':form}) |
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
62 |
return shortcuts.render_to_response( |
451
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
63 |
'task/edit.html', RequestContext(request, context)) |
333
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
64 |
else: |
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
65 |
form = taskapp_forms.CreateTaskForm() |
425
e15749fab2e4
Restructured create form to use templatetags and use Javascript for autcomplete.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
422
diff
changeset
|
66 |
context.update({'form': form}) |
451
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
67 |
return shortcuts.render_to_response( |
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
68 |
'task/edit.html', RequestContext(request, context)) |
333
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
69 |
else: |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
70 |
return show_msg(user, 'You are not authorised to create a task.') |
349
1cc8d0b2eefb
commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents:
340
diff
changeset
|
71 |
|
376
5a94c774473c
browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
374
diff
changeset
|
72 |
def browse_tasks(request): |
5a94c774473c
browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
374
diff
changeset
|
73 |
|
507
1d4631fcebd0
Add uberbar messages not to claim the task. This must be disabled once claiming is possible.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
506
diff
changeset
|
74 |
context = {} |
376
5a94c774473c
browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
374
diff
changeset
|
75 |
|
506
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
76 |
# TODO(disable): Disable once the tasks can be claimed |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
77 |
context['uberbar_message'] = DONT_CLAIM_TASK_MSG |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
78 |
|
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
79 |
open_tasks = taskapp_models.Task.objects.filter( |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
80 |
status=taskapp_models.TASK_STATUS_CHOICES[1][0]) |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
81 |
working_tasks = taskapp_models.Task.objects.filter( |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
82 |
status=taskapp_models.TASK_STATUS_CHOICES[3][0]) |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
83 |
comp_tasks = taskapp_models.Task.objects.filter( |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
84 |
status=taskapp_models.TASK_STATUS_CHOICES[6][0]) |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
85 |
|
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
86 |
context.update({ |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
87 |
'open_tasks': open_tasks, |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
88 |
'working_tasks': working_tasks, |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
89 |
'comp_tasks': comp_tasks, |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
90 |
}) |
376
5a94c774473c
browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
374
diff
changeset
|
91 |
|
5a94c774473c
browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
374
diff
changeset
|
92 |
user = request.user |
5a94c774473c
browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
374
diff
changeset
|
93 |
if not user.is_authenticated(): |
506
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
94 |
return shortcuts.render_to_response('task/browse.html', |
489
9cd090b8cd52
Return whatever context can be shown for non-logged in user for tasks browse.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
451
diff
changeset
|
95 |
RequestContext(request, context)) |
376
5a94c774473c
browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
374
diff
changeset
|
96 |
|
5a94c774473c
browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
374
diff
changeset
|
97 |
profile = user.get_profile() |
5a94c774473c
browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
374
diff
changeset
|
98 |
|
506
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
99 |
|
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
100 |
if profile.role in [profile_models.ROLES_CHOICES[0][0], |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
101 |
profile_models.ROLES_CHOICES[1][0]]: |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
102 |
can_approve = True |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
103 |
else: |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
104 |
can_approve = False |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
105 |
|
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
106 |
unpub_tasks = taskapp_models.Task.objects.filter( |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
107 |
status=taskapp_models.TASK_STATUS_CHOICES[0][0]).exclude( |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
108 |
status=taskapp_models.TASK_STATUS_CHOICES[5][0]) |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
109 |
|
376
5a94c774473c
browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
374
diff
changeset
|
110 |
if can_approve: |
506
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
111 |
context.update({'unpub_tasks': unpub_tasks}) |
376
5a94c774473c
browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
374
diff
changeset
|
112 |
|
506
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
113 |
context.update({'user': user, |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
114 |
'profile': profile, |
376
5a94c774473c
browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
374
diff
changeset
|
115 |
}) |
5a94c774473c
browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
374
diff
changeset
|
116 |
|
506
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
117 |
return shortcuts.render_to_response('task/browse.html', |
451
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
118 |
RequestContext(request, context)) |
376
5a94c774473c
browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
374
diff
changeset
|
119 |
|
5a94c774473c
browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
374
diff
changeset
|
120 |
|
408
0c12181e2c02
Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
387
diff
changeset
|
121 |
def view_task(request, task_id): |
0c12181e2c02
Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
387
diff
changeset
|
122 |
""" get the task depending on its task_id and display accordingly if it is a get. |
349
1cc8d0b2eefb
commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents:
340
diff
changeset
|
123 |
check for authentication and add a comment if it is a post request. |
1cc8d0b2eefb
commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents:
340
diff
changeset
|
124 |
""" |
408
0c12181e2c02
Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
387
diff
changeset
|
125 |
|
507
1d4631fcebd0
Add uberbar messages not to claim the task. This must be disabled once claiming is possible.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
506
diff
changeset
|
126 |
context = {} |
1d4631fcebd0
Add uberbar messages not to claim the task. This must be disabled once claiming is possible.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
506
diff
changeset
|
127 |
|
1d4631fcebd0
Add uberbar messages not to claim the task. This must be disabled once claiming is possible.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
506
diff
changeset
|
128 |
# TODO(disable): Disable once the tasks can be claimed |
1d4631fcebd0
Add uberbar messages not to claim the task. This must be disabled once claiming is possible.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
506
diff
changeset
|
129 |
context['uberbar_message'] = DONT_CLAIM_TASK_MSG |
1d4631fcebd0
Add uberbar messages not to claim the task. This must be disabled once claiming is possible.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
506
diff
changeset
|
130 |
|
408
0c12181e2c02
Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
387
diff
changeset
|
131 |
task_url = reverse('view_task', kwargs={'task_id': task_id}) |
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
132 |
task = shortcuts.get_object_or_404(taskapp_models.Task, pk=task_id) |
349
1cc8d0b2eefb
commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents:
340
diff
changeset
|
133 |
|
1cc8d0b2eefb
commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents:
340
diff
changeset
|
134 |
user = request.user |
350
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
349
diff
changeset
|
135 |
|
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
349
diff
changeset
|
136 |
if not user.is_authenticated(): |
506
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
137 |
return shortcuts.render_to_response('task/view.html', {'task': task}) |
350
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
349
diff
changeset
|
138 |
|
349
1cc8d0b2eefb
commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents:
340
diff
changeset
|
139 |
profile = user.get_profile() |
1cc8d0b2eefb
commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents:
340
diff
changeset
|
140 |
|
506
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
141 |
context.update({ |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
142 |
'user': user, |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
143 |
'profile': profile, |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
144 |
'task': task, |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
145 |
}) |
349
1cc8d0b2eefb
commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents:
340
diff
changeset
|
146 |
|
1cc8d0b2eefb
commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents:
340
diff
changeset
|
147 |
context.update(csrf(request)) |
1cc8d0b2eefb
commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents:
340
diff
changeset
|
148 |
|
440
56ea209e559f
Use the right form of names to be stored in the database.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
430
diff
changeset
|
149 |
if task.status == taskapp_models.TASK_STATUS_CHOICES[5][0]: |
408
0c12181e2c02
Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
387
diff
changeset
|
150 |
return show_msg(user, 'This task no longer exists', |
0c12181e2c02
Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
387
diff
changeset
|
151 |
reverse('browse_tasks'), 'browse the tasks') |
349
1cc8d0b2eefb
commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents:
340
diff
changeset
|
152 |
|
506
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
153 |
if ((task.status != taskapp_models.TASK_STATUS_CHOICES[0][0] ) |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
154 |
or profile.role != profile_models.ROLES_CHOICES[3][0]): |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
155 |
task_viewable = True |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
156 |
else: |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
157 |
task_viewable = False |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
158 |
|
350
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
349
diff
changeset
|
159 |
if not task_viewable: |
506
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
160 |
return show_msg(user, 'You are not authorised to view this task', |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
161 |
reverse('browse_tasks'), 'browse the tasks') |
349
1cc8d0b2eefb
commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents:
340
diff
changeset
|
162 |
|
350
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
349
diff
changeset
|
163 |
reviewers = task.reviewers.all() |
349
1cc8d0b2eefb
commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents:
340
diff
changeset
|
164 |
is_reviewer = True if user in task.reviewers.all() else False |
408
0c12181e2c02
Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
387
diff
changeset
|
165 |
comments = task.comments.filter( |
0c12181e2c02
Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
387
diff
changeset
|
166 |
is_deleted=False).order_by('comment_datetime') |
349
1cc8d0b2eefb
commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents:
340
diff
changeset
|
167 |
|
350
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
349
diff
changeset
|
168 |
context.update({'is_reviewer':is_reviewer, |
349
1cc8d0b2eefb
commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents:
340
diff
changeset
|
169 |
'comments':comments, |
1cc8d0b2eefb
commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents:
340
diff
changeset
|
170 |
'reviewers':reviewers, |
1cc8d0b2eefb
commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents:
340
diff
changeset
|
171 |
}) |
1cc8d0b2eefb
commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents:
340
diff
changeset
|
172 |
|
350
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
349
diff
changeset
|
173 |
selected_users = task.selected_users.all() |
349
1cc8d0b2eefb
commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents:
340
diff
changeset
|
174 |
|
528
56474add44b1
Allow editing of tasks even to coordinators and mentors.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
526
diff
changeset
|
175 |
user_role = user.get_profile().role |
350
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
349
diff
changeset
|
176 |
is_creator = True if user == task.created_by else False |
349
1cc8d0b2eefb
commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents:
340
diff
changeset
|
177 |
|
365
32457bce3437
prettified a few pages
Nishanth Amuluru <nishanth@fossee.in>
parents:
363
diff
changeset
|
178 |
context['selected_users'] = selected_users |
506
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
179 |
|
350
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
349
diff
changeset
|
180 |
context['is_selected'] = True if user in selected_users else False |
506
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
181 |
|
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
182 |
if (task.status == taskapp_models.TASK_STATUS_CHOICES[0][0] and |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
183 |
profile.role in [profile_models.ROLES_CHOICES[0][0], |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
184 |
profile_models.ROLES_CHOICES[1][0]]): |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
185 |
context['can_approve'] = True |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
186 |
else: |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
187 |
context['can_approve'] = False |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
188 |
|
528
56474add44b1
Allow editing of tasks even to coordinators and mentors.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
526
diff
changeset
|
189 |
if ((is_creator or user_role != profile_models.ROLES_CHOICES[3][0]) |
56474add44b1
Allow editing of tasks even to coordinators and mentors.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
526
diff
changeset
|
190 |
and task.status == taskapp_models.TASK_STATUS_CHOICES[0][0]): |
506
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
191 |
context['can_edit'] = True |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
192 |
else: |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
193 |
context['can_edit'] = False |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
194 |
|
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
195 |
if (task.status not in [taskapp_models.TASK_STATUS_CHOICES[0][0], |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
196 |
taskapp_models.TASK_STATUS_CHOICES[4][0], |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
197 |
taskapp_models.TASK_STATUS_CHOICES[6][0]] and is_reviewer): |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
198 |
context['can_close'] = True |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
199 |
else: |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
200 |
context['can_close'] = False |
349
1cc8d0b2eefb
commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents:
340
diff
changeset
|
201 |
|
506
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
202 |
if task.status == taskapp_models.TASK_STATUS_CHOICES[0][0] and is_creator: |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
203 |
context['can_delete'] = True |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
204 |
else: |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
205 |
context['can_delete'] = False |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
206 |
|
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
207 |
if (task.status in [taskapp_models.TASK_STATUS_CHOICES[1][0], |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
208 |
taskapp_models.TASK_STATUS_CHOICES[3][0]] and is_reviewer): |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
209 |
context['can_assign_pynts'] = True |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
210 |
else: |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
211 |
context['can_assign_pynts'] = False |
350
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
349
diff
changeset
|
212 |
|
506
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
213 |
if (task.status in [taskapp_models.TASK_STATUS_CHOICES[1][0], |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
214 |
taskapp_models.TASK_STATUS_CHOICES[3][0]]): |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
215 |
context['task_claimable'] = True |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
216 |
else: |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
217 |
context['task_claimable'] = False |
349
1cc8d0b2eefb
commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents:
340
diff
changeset
|
218 |
|
506
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
219 |
if (task.status != taskapp_models.TASK_STATUS_CHOICES[0][0] or\ |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
220 |
profile.role != profile_models.ROLES_CHOICES[3][0]): |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
221 |
context['can_comment'] = True |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
222 |
else: |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
223 |
context['can_comment'] = False |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
224 |
|
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
225 |
if (profile.role in [profile_models.ROLES_CHOICES[0][0], |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
226 |
profile_models.ROLES_CHOICES[1][0]]): |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
227 |
context['can_mod_reviewers'] = True |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
228 |
else: |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
229 |
context['can_mod_reviewers'] = False |
381
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
380
diff
changeset
|
230 |
|
349
1cc8d0b2eefb
commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents:
340
diff
changeset
|
231 |
if request.method == 'POST': |
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
232 |
form = taskapp_forms.TaskCommentForm(request.POST) |
350
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
349
diff
changeset
|
233 |
if form.is_valid(): |
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
349
diff
changeset
|
234 |
data = form.cleaned_data['data'] |
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
235 |
new_comment = taskapp_forms.TaskComment( |
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
236 |
task=task, data=data, commented_by=user, |
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
237 |
comment_datetime=datetime.now()) |
350
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
349
diff
changeset
|
238 |
new_comment.save() |
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
239 |
return shortcuts.redirect(task_url) |
349
1cc8d0b2eefb
commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents:
340
diff
changeset
|
240 |
else: |
350
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
349
diff
changeset
|
241 |
context['form'] = form |
451
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
242 |
return shortcuts.render_to_response( |
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
243 |
'task/view.html', RequestContext(request, context)) |
349
1cc8d0b2eefb
commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents:
340
diff
changeset
|
244 |
else: |
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
245 |
form = taskapp_forms.TaskCommentForm() |
349
1cc8d0b2eefb
commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents:
340
diff
changeset
|
246 |
context['form'] = form |
451
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
247 |
return shortcuts.render_to_response( |
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
248 |
'task/view.html', RequestContext(request, context)) |
349
1cc8d0b2eefb
commenting on a task works as of now and there is a lot to do with view task
Nishanth Amuluru <nishanth@fossee.in>
parents:
340
diff
changeset
|
249 |
|
353
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
250 |
@login_required |
408
0c12181e2c02
Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
387
diff
changeset
|
251 |
def edit_task(request, task_id): |
366 | 252 |
""" only creator gets to edit the task and that too only before it gets |
253 |
approved. |
|
254 |
""" |
|
255 |
||
256 |
user = request.user |
|
257 |
profile = user.get_profile() |
|
258 |
||
408
0c12181e2c02
Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
387
diff
changeset
|
259 |
task_url = reverse('view_task', kwargs={'task_id': task_id}) |
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
260 |
task = shortcuts.get_object_or_404(taskapp_models.Task, pk=task_id) |
366 | 261 |
|
262 |
is_creator = True if user == task.created_by else False |
|
440
56ea209e559f
Use the right form of names to be stored in the database.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
430
diff
changeset
|
263 |
can_edit = True if task.status == taskapp_models.TASK_STATUS_CHOICES[0][0] and is_creator else False |
366 | 264 |
if not can_edit: |
425
e15749fab2e4
Restructured create form to use templatetags and use Javascript for autcomplete.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
422
diff
changeset
|
265 |
raise http.Http404 |
366 | 266 |
|
267 |
context = {"user": user, |
|
268 |
"profile": profile, |
|
269 |
"task": task, |
|
270 |
} |
|
271 |
||
272 |
context.update(csrf(request)) |
|
273 |
||
274 |
if request.method == "POST": |
|
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
275 |
form = taskapp_forms.EditTaskForm(request.POST, instance=task) |
366 | 276 |
if form.is_valid(): |
277 |
form.save() |
|
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
278 |
return shortcuts.redirect(task_url) |
366 | 279 |
else: |
280 |
context.update({"form": form}) |
|
451
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
281 |
return shortcuts.render_to_response( |
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
282 |
"task/edit.html", RequestContext(request, context)) |
366 | 283 |
else: |
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
284 |
form = taskapp_forms.EditTaskForm(instance=task) |
366 | 285 |
context.update({"form": form}) |
451
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
286 |
return shortcuts.render_to_response("task/edit.html", |
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
287 |
RequestContext(request, context)) |
366 | 288 |
|
368
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
366
diff
changeset
|
289 |
@login_required |
408
0c12181e2c02
Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
387
diff
changeset
|
290 |
def approve_task(request, task_id): |
374
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
373
diff
changeset
|
291 |
|
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
373
diff
changeset
|
292 |
user = request.user |
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
373
diff
changeset
|
293 |
profile = user.get_profile() |
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
373
diff
changeset
|
294 |
|
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
295 |
task = shortcuts.get_object_or_404(taskapp_models.Task, pk=task_id) |
374
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
373
diff
changeset
|
296 |
|
443
a13ea00c1a3f
Use the correct choices variable for the role and status.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
440
diff
changeset
|
297 |
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]: |
425
e15749fab2e4
Restructured create form to use templatetags and use Javascript for autcomplete.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
422
diff
changeset
|
298 |
raise http.Http404 |
374
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
373
diff
changeset
|
299 |
|
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
373
diff
changeset
|
300 |
context = {"user": user, |
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
373
diff
changeset
|
301 |
"profile": profile, |
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
373
diff
changeset
|
302 |
"task": task, |
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
373
diff
changeset
|
303 |
} |
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
373
diff
changeset
|
304 |
|
451
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
305 |
return shortcuts.render_to_response( |
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
306 |
"task/confirm_approval.html", RequestContext(request, context)) |
374
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
373
diff
changeset
|
307 |
|
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
373
diff
changeset
|
308 |
@login_required |
408
0c12181e2c02
Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
387
diff
changeset
|
309 |
def approved_task(request, task_id): |
374
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
373
diff
changeset
|
310 |
|
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
373
diff
changeset
|
311 |
user = request.user |
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
373
diff
changeset
|
312 |
profile = user.get_profile() |
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
373
diff
changeset
|
313 |
|
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
314 |
task = shortcuts.get_object_or_404(taskapp_models.Task, pk=task_id) |
374
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
373
diff
changeset
|
315 |
|
443
a13ea00c1a3f
Use the correct choices variable for the role and status.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
440
diff
changeset
|
316 |
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]: |
425
e15749fab2e4
Restructured create form to use templatetags and use Javascript for autcomplete.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
422
diff
changeset
|
317 |
raise http.Http404 |
374
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
373
diff
changeset
|
318 |
|
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
373
diff
changeset
|
319 |
task.approved_by = user |
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
373
diff
changeset
|
320 |
task.approval_datetime = datetime.now() |
440
56ea209e559f
Use the right form of names to be stored in the database.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
430
diff
changeset
|
321 |
task.status = taskapp_models.TASK_STATUS_CHOICES[1][0] |
374
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
373
diff
changeset
|
322 |
task.save() |
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
373
diff
changeset
|
323 |
|
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
373
diff
changeset
|
324 |
context = {"user": user, |
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
373
diff
changeset
|
325 |
"profile": profile, |
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
373
diff
changeset
|
326 |
"task": task, |
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
373
diff
changeset
|
327 |
} |
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
373
diff
changeset
|
328 |
|
451
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
329 |
return shortcuts.render_to_response( |
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
330 |
"task/approved_task.html", RequestContext(request, context)) |
374
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
373
diff
changeset
|
331 |
|
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
373
diff
changeset
|
332 |
@login_required |
408
0c12181e2c02
Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
387
diff
changeset
|
333 |
def addreviewer(request, task_id): |
381
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
380
diff
changeset
|
334 |
|
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
380
diff
changeset
|
335 |
user = request.user |
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
380
diff
changeset
|
336 |
profile = user.get_profile() |
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
380
diff
changeset
|
337 |
|
408
0c12181e2c02
Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
387
diff
changeset
|
338 |
task_url = reverse('view_task', kwargs={'task_id': task_id}) |
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
339 |
task = shortcuts.get_object_or_404(taskapp_models.Task, pk=task_id) |
381
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
380
diff
changeset
|
340 |
|
443
a13ea00c1a3f
Use the correct choices variable for the role and status.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
440
diff
changeset
|
341 |
can_mod_reviewers = True if profile.role in [profile_models.ROLES_CHOICES[0][0], profile_models.ROLES_CHOICES[1][0]] else False |
381
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
380
diff
changeset
|
342 |
if not can_mod_reviewers: |
425
e15749fab2e4
Restructured create form to use templatetags and use Javascript for autcomplete.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
422
diff
changeset
|
343 |
raise http.Http404 |
381
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
380
diff
changeset
|
344 |
|
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
380
diff
changeset
|
345 |
context = {"user": user, |
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
380
diff
changeset
|
346 |
"profile": profile, |
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
380
diff
changeset
|
347 |
"task": task, |
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
380
diff
changeset
|
348 |
} |
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
380
diff
changeset
|
349 |
|
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
380
diff
changeset
|
350 |
context.update(csrf(request)) |
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
380
diff
changeset
|
351 |
|
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
380
diff
changeset
|
352 |
|
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
380
diff
changeset
|
353 |
# This part has to be made better |
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
380
diff
changeset
|
354 |
reviewer_choices = User.objects.filter(is_active=True).\ |
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
355 |
exclude(reviewing_tasks__id=task_id).\ |
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
356 |
exclude(claimed_tasks__id=task_id).\ |
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
357 |
exclude(selected_tasks__id=task_id).\ |
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
358 |
exclude(created_tasks__id=task_id) |
382
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
381
diff
changeset
|
359 |
|
381
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
380
diff
changeset
|
360 |
choices = ((a_user.id,a_user.username) for a_user in reviewer_choices) |
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
380
diff
changeset
|
361 |
label = "Reviewer" |
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
380
diff
changeset
|
362 |
|
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
380
diff
changeset
|
363 |
if request.method == "POST": |
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
364 |
form = taskapp_forms.ChoiceForm(choices, data=request.POST, label=label) |
381
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
380
diff
changeset
|
365 |
if form.is_valid(): |
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
380
diff
changeset
|
366 |
data = form.cleaned_data.copy() |
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
380
diff
changeset
|
367 |
uid = data['choice'] |
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
380
diff
changeset
|
368 |
reviewer = User.objects.get(id=uid) |
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
380
diff
changeset
|
369 |
|
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
380
diff
changeset
|
370 |
task.reviewers.add(reviewer) |
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
371 |
return shortcuts.redirect(task_url) |
381
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
380
diff
changeset
|
372 |
else: |
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
380
diff
changeset
|
373 |
context.update({"form": form}) |
451
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
374 |
return shortcuts.render_to_response( |
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
375 |
"task/addreviewer.html", RequestContext(request, context)) |
381
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
380
diff
changeset
|
376 |
else: |
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
377 |
form = taskapp_forms.ChoiceForm(choices, label=label) |
381
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
380
diff
changeset
|
378 |
context.update({"form": form}) |
451
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
379 |
return shortcuts.render_to_response( |
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
380 |
"task/addreviewer.html", RequestContext(request, context)) |
381
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
380
diff
changeset
|
381 |
|
408
0c12181e2c02
Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
387
diff
changeset
|
382 |
def view_work(request, task_id): |
382
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
381
diff
changeset
|
383 |
|
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
384 |
task = shortcuts.get_object_or_404(taskapp_models.Task, pk=task_id) |
382
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
381
diff
changeset
|
385 |
|
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
381
diff
changeset
|
386 |
user = request.user |
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
381
diff
changeset
|
387 |
old_reports = task.reports.all() |
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
381
diff
changeset
|
388 |
|
515 | 389 |
context = { |
390 |
'task': task, |
|
391 |
'old_reports': old_reports, |
|
392 |
} |
|
382
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
381
diff
changeset
|
393 |
|
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
381
diff
changeset
|
394 |
if not user.is_authenticated(): |
451
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
395 |
return shortcuts.render_to_response( |
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
396 |
"task/view_work.html", RequestContext(request, context)) |
382
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
381
diff
changeset
|
397 |
|
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
381
diff
changeset
|
398 |
profile = user.get_profile() |
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
381
diff
changeset
|
399 |
|
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
381
diff
changeset
|
400 |
context.update({"user": user, |
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
381
diff
changeset
|
401 |
"profile": profile, |
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
381
diff
changeset
|
402 |
}) |
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
381
diff
changeset
|
403 |
|
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
381
diff
changeset
|
404 |
context.update(csrf(request)) |
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
381
diff
changeset
|
405 |
|
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
381
diff
changeset
|
406 |
working_users = task.selected_users.all() |
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
381
diff
changeset
|
407 |
is_working = True if user in working_users else False |
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
381
diff
changeset
|
408 |
|
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
381
diff
changeset
|
409 |
context.update({"is_working": is_working}) |
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
381
diff
changeset
|
410 |
|
451
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
411 |
return shortcuts.render_to_response("task/view_work.html", |
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
412 |
RequestContext(request, context)) |
382
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
381
diff
changeset
|
413 |
|
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
381
diff
changeset
|
414 |
@login_required |
408
0c12181e2c02
Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
387
diff
changeset
|
415 |
def view_report(request, report_id): |
383
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
416 |
|
425
e15749fab2e4
Restructured create form to use templatetags and use Javascript for autcomplete.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
422
diff
changeset
|
417 |
report = shortcuts.get_object_or_404(taskapp_models.WorkReport, |
e15749fab2e4
Restructured create form to use templatetags and use Javascript for autcomplete.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
422
diff
changeset
|
418 |
pk=report_id) |
383
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
419 |
|
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
420 |
user = request.user |
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
421 |
context = {"report": report, |
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
422 |
"user": user, |
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
423 |
} |
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
424 |
|
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
425 |
if not user.is_authenticated(): |
451
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
426 |
return shortcuts.render_to_response( |
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
427 |
"task/view_report.html", RequestContext(request, context)) |
383
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
428 |
|
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
429 |
profile = user.get_profile() |
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
430 |
|
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
431 |
context.update({"profile": profile}) |
451
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
432 |
return shortcuts.render_to_response("task/view_report.html", |
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
433 |
RequestContext(request, context)) |
383
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
434 |
|
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
435 |
@login_required |
408
0c12181e2c02
Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
387
diff
changeset
|
436 |
def submit_report(request, task_id): |
383
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
437 |
""" Check if the work is in WR state and the user is in assigned_users. |
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
438 |
""" |
408
0c12181e2c02
Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
387
diff
changeset
|
439 |
task_url = reverse('view_task', kwargs={'task_id': task_id}) |
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
440 |
task = shortcuts.get_object_or_404(taskapp_models.Task, pk=task_id) |
408
0c12181e2c02
Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
387
diff
changeset
|
441 |
|
383
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
442 |
user = request.user |
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
443 |
old_reports = task.reports.all() |
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
444 |
|
440
56ea209e559f
Use the right form of names to be stored in the database.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
430
diff
changeset
|
445 |
if not task.status == taskapp_models.TASK_STATUS_CHOICES[3][0]: |
425
e15749fab2e4
Restructured create form to use templatetags and use Javascript for autcomplete.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
422
diff
changeset
|
446 |
raise http.Http404 |
383
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
447 |
|
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
448 |
can_upload = True if user in task.selected_users.all() else False |
382
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
381
diff
changeset
|
449 |
|
383
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
450 |
context = { |
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
451 |
'user': user, |
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
452 |
'task': task, |
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
453 |
'can_upload': can_upload, |
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
454 |
} |
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
455 |
|
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
456 |
context.update(csrf(request)) |
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
457 |
|
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
458 |
if request.method == "POST": |
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
459 |
if not can_upload: |
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
460 |
return show_msg(user, "You are not authorised to upload data to this task", task_url, "view the task") |
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
461 |
|
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
462 |
form = taskapp_forms.WorkReportForm(request.POST, request.FILES) |
383
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
463 |
|
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
464 |
if form.is_valid(): |
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
465 |
data = form.cleaned_data.copy() |
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
466 |
data.update({"task":task, |
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
467 |
"revision": old_reports.count(), |
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
468 |
"submitted_by": user, |
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
469 |
"submitted_at": datetime.now(), |
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
470 |
}) |
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
471 |
r = taskapp_models.WorkReport(**data) |
383
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
472 |
r.save() |
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
473 |
|
408
0c12181e2c02
Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
387
diff
changeset
|
474 |
report_url = reverse('view_report', kwargs={'report_id': r.id}) |
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
475 |
return shortcuts.redirect(report_url) |
383
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
476 |
|
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
477 |
else: |
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
478 |
context.update({"form":form}) |
451
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
479 |
return shortcuts.render_to_response( |
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
480 |
'task/submit_report.html', RequestContext(request, context)) |
383
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
481 |
|
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
482 |
else: |
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
483 |
form = taskapp_forms.WorkReportForm() |
383
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
484 |
context.update({"form":form}) |
451
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
485 |
return shortcuts.render_to_response( |
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
486 |
'task/submit_report.html', RequestContext(request, context)) |
382
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
381
diff
changeset
|
487 |
|
381
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
380
diff
changeset
|
488 |
@login_required |
368
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
366
diff
changeset
|
489 |
def create_textbook(request): |
366 | 490 |
|
368
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
366
diff
changeset
|
491 |
user = request.user |
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
366
diff
changeset
|
492 |
profile = user.get_profile() |
366 | 493 |
|
528
56474add44b1
Allow editing of tasks even to coordinators and mentors.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
526
diff
changeset
|
494 |
if profile.role != profile_models.ROLES_CHOICES[3][0]: |
56474add44b1
Allow editing of tasks even to coordinators and mentors.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
526
diff
changeset
|
495 |
can_create = True |
56474add44b1
Allow editing of tasks even to coordinators and mentors.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
526
diff
changeset
|
496 |
else: |
56474add44b1
Allow editing of tasks even to coordinators and mentors.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
526
diff
changeset
|
497 |
can_create= False |
368
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
366
diff
changeset
|
498 |
|
528
56474add44b1
Allow editing of tasks even to coordinators and mentors.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
526
diff
changeset
|
499 |
if not can_create: |
56474add44b1
Allow editing of tasks even to coordinators and mentors.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
526
diff
changeset
|
500 |
raise http.HttpResponseForbidden |
56474add44b1
Allow editing of tasks even to coordinators and mentors.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
526
diff
changeset
|
501 |
|
56474add44b1
Allow editing of tasks even to coordinators and mentors.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
526
diff
changeset
|
502 |
context = { |
56474add44b1
Allow editing of tasks even to coordinators and mentors.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
526
diff
changeset
|
503 |
'user': user, |
56474add44b1
Allow editing of tasks even to coordinators and mentors.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
526
diff
changeset
|
504 |
'profile': profile, |
56474add44b1
Allow editing of tasks even to coordinators and mentors.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
526
diff
changeset
|
505 |
} |
368
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
366
diff
changeset
|
506 |
|
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
366
diff
changeset
|
507 |
context.update(csrf(request)) |
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
366
diff
changeset
|
508 |
|
529 | 509 |
if request.method == 'POST': |
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
510 |
form = taskapp_forms.CreateTextbookForm(request.POST) |
368
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
366
diff
changeset
|
511 |
if form.is_valid(): |
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
366
diff
changeset
|
512 |
data = form.cleaned_data.copy() |
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
513 |
data.update({"created_by": user, |
368
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
366
diff
changeset
|
514 |
"creation_datetime": datetime.now()}) |
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
366
diff
changeset
|
515 |
del data['chapters'] |
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
516 |
new_textbook = taskapp_models.TextBook(**data) |
368
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
366
diff
changeset
|
517 |
new_textbook.save() |
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
366
diff
changeset
|
518 |
|
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
366
diff
changeset
|
519 |
new_textbook.chapters = form.cleaned_data['chapters'] |
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
366
diff
changeset
|
520 |
|
408
0c12181e2c02
Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
387
diff
changeset
|
521 |
textbook_url = reverse( |
0c12181e2c02
Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
387
diff
changeset
|
522 |
'view_textbook', kwargs={'task_id': new_textbook.id}) |
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
523 |
return shortcuts.redirect(textbook_url) |
368
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
366
diff
changeset
|
524 |
else: |
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
366
diff
changeset
|
525 |
context.update({"form": form}) |
451
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
526 |
return shortcuts.render_to_response( |
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
527 |
"task/edit.html", RequestContext(request, context)) |
368
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
366
diff
changeset
|
528 |
else: |
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
529 |
form = taskapp_forms.CreateTextbookForm() |
368
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
366
diff
changeset
|
530 |
context.update({"form": form}) |
451
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
531 |
return shortcuts.render_to_response( |
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
532 |
"task/edit.html", RequestContext(request, context)) |
366 | 533 |
|
529 | 534 |
def view_textbook(request, task_id, template='task/view_textbook.html'): |
370
1be4a3c09a47
view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
368
diff
changeset
|
535 |
|
501
b84d6a1d4603
Change all the queries to Textbook model to Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
500
diff
changeset
|
536 |
# Shortcut to get_object_or_404 is not used since django-tagging |
b84d6a1d4603
Change all the queries to Textbook model to Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
500
diff
changeset
|
537 |
# api expects a queryset object for tag filtering. |
b84d6a1d4603
Change all the queries to Textbook model to Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
500
diff
changeset
|
538 |
task = taskapp_models.Task.objects.filter(pk=task_id) |
b84d6a1d4603
Change all the queries to Textbook model to Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
500
diff
changeset
|
539 |
|
b84d6a1d4603
Change all the queries to Textbook model to Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
500
diff
changeset
|
540 |
textbooks = TaggedItem.objects.get_by_model(task, ['Textbook']) |
b84d6a1d4603
Change all the queries to Textbook model to Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
500
diff
changeset
|
541 |
|
b84d6a1d4603
Change all the queries to Textbook model to Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
500
diff
changeset
|
542 |
if textbooks: |
b84d6a1d4603
Change all the queries to Textbook model to Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
500
diff
changeset
|
543 |
textbook = textbooks[0] |
b84d6a1d4603
Change all the queries to Textbook model to Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
500
diff
changeset
|
544 |
else: |
b84d6a1d4603
Change all the queries to Textbook model to Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
500
diff
changeset
|
545 |
raise http.Http404 |
b84d6a1d4603
Change all the queries to Textbook model to Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
500
diff
changeset
|
546 |
|
b84d6a1d4603
Change all the queries to Textbook model to Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
500
diff
changeset
|
547 |
#chapters = textbook.chapters.all() |
370
1be4a3c09a47
view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
368
diff
changeset
|
548 |
|
1be4a3c09a47
view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
368
diff
changeset
|
549 |
user = request.user |
387
32dd15eaf9d0
fixed a bug where guest users were not able to view the page correctly
Nishanth Amuluru <nishanth@fossee.in>
parents:
386
diff
changeset
|
550 |
|
32dd15eaf9d0
fixed a bug where guest users were not able to view the page correctly
Nishanth Amuluru <nishanth@fossee.in>
parents:
386
diff
changeset
|
551 |
context = {"user": user, |
32dd15eaf9d0
fixed a bug where guest users were not able to view the page correctly
Nishanth Amuluru <nishanth@fossee.in>
parents:
386
diff
changeset
|
552 |
"textbook": textbook, |
501
b84d6a1d4603
Change all the queries to Textbook model to Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
500
diff
changeset
|
553 |
# "chapters": chapters, |
387
32dd15eaf9d0
fixed a bug where guest users were not able to view the page correctly
Nishanth Amuluru <nishanth@fossee.in>
parents:
386
diff
changeset
|
554 |
} |
32dd15eaf9d0
fixed a bug where guest users were not able to view the page correctly
Nishanth Amuluru <nishanth@fossee.in>
parents:
386
diff
changeset
|
555 |
|
370
1be4a3c09a47
view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
368
diff
changeset
|
556 |
if not user.is_authenticated(): |
529 | 557 |
return shortcuts.render_to_response(template, |
451
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
558 |
RequestContext(request, context)) |
370
1be4a3c09a47
view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
368
diff
changeset
|
559 |
|
1be4a3c09a47
view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
368
diff
changeset
|
560 |
profile = user.get_profile() |
1be4a3c09a47
view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
368
diff
changeset
|
561 |
|
529 | 562 |
context.update({ |
563 |
'profile': profile, |
|
564 |
'textbook': textbook, |
|
565 |
}) |
|
370
1be4a3c09a47
view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
368
diff
changeset
|
566 |
|
1be4a3c09a47
view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
368
diff
changeset
|
567 |
context.update(csrf(request)) |
1be4a3c09a47
view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
368
diff
changeset
|
568 |
|
529 | 569 |
user_role = user.get_profile().role |
570 |
if ((user == textbook.created_by or |
|
571 |
user_role != profile_models.ROLES_CHOICES[3][0]) and |
|
572 |
textbook.status in [taskapp_models.TB_STATUS_CHOICES[0][0], |
|
573 |
taskapp_models.TB_STATUS_CHOICES[1][0]]): |
|
500
42516ec56822
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
497
diff
changeset
|
574 |
can_edit = True |
42516ec56822
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
497
diff
changeset
|
575 |
else: |
42516ec56822
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
497
diff
changeset
|
576 |
can_edit = False |
42516ec56822
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
497
diff
changeset
|
577 |
|
370
1be4a3c09a47
view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
368
diff
changeset
|
578 |
|
500
42516ec56822
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
497
diff
changeset
|
579 |
if (profile.role in [profile_models.ROLES_CHOICES[0][0], |
42516ec56822
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
497
diff
changeset
|
580 |
profile_models.ROLES_CHOICES[1][0]] and |
42516ec56822
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
497
diff
changeset
|
581 |
textbook.status == taskapp_models.TB_STATUS_CHOICES[0][0]): |
42516ec56822
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
497
diff
changeset
|
582 |
can_approve = True |
42516ec56822
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
497
diff
changeset
|
583 |
else: |
42516ec56822
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
497
diff
changeset
|
584 |
can_approve = False |
370
1be4a3c09a47
view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
368
diff
changeset
|
585 |
|
529 | 586 |
context.update({ |
587 |
'can_edit': can_edit, |
|
588 |
'can_approve': can_approve, |
|
589 |
'can_create_chapters': can_create_chapters, |
|
590 |
}) |
|
591 |
return shortcuts.render_to_response(template, |
|
451
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
592 |
RequestContext(request, context)) |
370
1be4a3c09a47
view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
368
diff
changeset
|
593 |
|
372
563fe356947d
created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents:
370
diff
changeset
|
594 |
def browse_textbooks(request): |
495
773e886d9b80
Textbooks list page should list all the tasks tagged with textbooks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
489
diff
changeset
|
595 |
"""View to list all the open textbooks. This view fetches tasks |
773e886d9b80
Textbooks list page should list all the tasks tagged with textbooks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
489
diff
changeset
|
596 |
tagged with Textbook. |
773e886d9b80
Textbooks list page should list all the tasks tagged with textbooks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
489
diff
changeset
|
597 |
""" |
372
563fe356947d
created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents:
370
diff
changeset
|
598 |
|
563fe356947d
created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents:
370
diff
changeset
|
599 |
user = request.user |
563fe356947d
created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents:
370
diff
changeset
|
600 |
|
495
773e886d9b80
Textbooks list page should list all the tasks tagged with textbooks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
489
diff
changeset
|
601 |
|
773e886d9b80
Textbooks list page should list all the tasks tagged with textbooks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
489
diff
changeset
|
602 |
# Get all the textbooks that are Open. |
497
6386458d749b
List each department textbooks separately for now, think of a clever way later.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
495
diff
changeset
|
603 |
open_textbooks = taskapp_models.Task.objects.filter( |
495
773e886d9b80
Textbooks list page should list all the tasks tagged with textbooks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
489
diff
changeset
|
604 |
status=taskapp_models.TASK_STATUS_CHOICES[1][0]).order_by( |
773e886d9b80
Textbooks list page should list all the tasks tagged with textbooks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
489
diff
changeset
|
605 |
'creation_datetime') |
372
563fe356947d
created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents:
370
diff
changeset
|
606 |
|
497
6386458d749b
List each department textbooks separately for now, think of a clever way later.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
495
diff
changeset
|
607 |
|
6386458d749b
List each department textbooks separately for now, think of a clever way later.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
495
diff
changeset
|
608 |
context = { |
6386458d749b
List each department textbooks separately for now, think of a clever way later.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
495
diff
changeset
|
609 |
'aero_textbooks': TaggedItem.objects.get_by_model( |
6386458d749b
List each department textbooks separately for now, think of a clever way later.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
495
diff
changeset
|
610 |
open_textbooks, ['Textbook', 'Aerospace']), |
6386458d749b
List each department textbooks separately for now, think of a clever way later.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
495
diff
changeset
|
611 |
'chemical_textbooks': TaggedItem.objects.get_by_model( |
6386458d749b
List each department textbooks separately for now, think of a clever way later.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
495
diff
changeset
|
612 |
open_textbooks, ['Textbook', 'Chemical']), |
6386458d749b
List each department textbooks separately for now, think of a clever way later.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
495
diff
changeset
|
613 |
'computerscience_textbooks': TaggedItem.objects.get_by_model( |
6386458d749b
List each department textbooks separately for now, think of a clever way later.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
495
diff
changeset
|
614 |
open_textbooks, ['Textbook', 'ComputerScience']), |
6386458d749b
List each department textbooks separately for now, think of a clever way later.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
495
diff
changeset
|
615 |
'electrical_textbooks': TaggedItem.objects.get_by_model( |
6386458d749b
List each department textbooks separately for now, think of a clever way later.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
495
diff
changeset
|
616 |
open_textbooks, ['Textbook', 'Electrical']), |
6386458d749b
List each department textbooks separately for now, think of a clever way later.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
495
diff
changeset
|
617 |
'engineeringphysics_textbooks': TaggedItem.objects.get_by_model( |
6386458d749b
List each department textbooks separately for now, think of a clever way later.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
495
diff
changeset
|
618 |
open_textbooks, ['Textbook', 'EngineeringPhysics']), |
6386458d749b
List each department textbooks separately for now, think of a clever way later.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
495
diff
changeset
|
619 |
'mechanical_textbooks': TaggedItem.objects.get_by_model( |
6386458d749b
List each department textbooks separately for now, think of a clever way later.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
495
diff
changeset
|
620 |
open_textbooks, ['Mechanical', 'Textbook']), |
6386458d749b
List each department textbooks separately for now, think of a clever way later.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
495
diff
changeset
|
621 |
'metallurgical_textbooks': TaggedItem.objects.get_by_model( |
6386458d749b
List each department textbooks separately for now, think of a clever way later.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
495
diff
changeset
|
622 |
open_textbooks, ['Textbook', 'Metallurgical']), |
6386458d749b
List each department textbooks separately for now, think of a clever way later.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
495
diff
changeset
|
623 |
} |
495
773e886d9b80
Textbooks list page should list all the tasks tagged with textbooks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
489
diff
changeset
|
624 |
|
773e886d9b80
Textbooks list page should list all the tasks tagged with textbooks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
489
diff
changeset
|
625 |
# Nothing |
773e886d9b80
Textbooks list page should list all the tasks tagged with textbooks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
489
diff
changeset
|
626 |
if user.is_authenticated() and (user.get_profile().role in |
773e886d9b80
Textbooks list page should list all the tasks tagged with textbooks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
489
diff
changeset
|
627 |
[profile_models.ROLES_CHOICES[0][0], profile_models.ROLES_CHOICES[1][0]]): |
773e886d9b80
Textbooks list page should list all the tasks tagged with textbooks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
489
diff
changeset
|
628 |
unpub_textbooks = taskapp_models.TextBook.objects.filter( |
773e886d9b80
Textbooks list page should list all the tasks tagged with textbooks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
489
diff
changeset
|
629 |
status=taskapp_models.TB_STATUS_CHOICES[0][0]) |
372
563fe356947d
created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents:
370
diff
changeset
|
630 |
|
563fe356947d
created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents:
370
diff
changeset
|
631 |
context.update({"unpub_textbooks": unpub_textbooks}) |
563fe356947d
created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents:
370
diff
changeset
|
632 |
|
451
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
633 |
return shortcuts.render_to_response("task/browse_textbooks.html", |
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
634 |
RequestContext(request, context)) |
372
563fe356947d
created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents:
370
diff
changeset
|
635 |
|
366 | 636 |
@login_required |
408
0c12181e2c02
Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
387
diff
changeset
|
637 |
def edit_textbook(request, task_id): |
373
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
372
diff
changeset
|
638 |
|
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
372
diff
changeset
|
639 |
user = request.user |
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
372
diff
changeset
|
640 |
profile = user.get_profile() |
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
372
diff
changeset
|
641 |
|
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
642 |
textbook = shortcuts.get_object_or_404(taskapp_models.TextBook, pk=task_id) |
408
0c12181e2c02
Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
387
diff
changeset
|
643 |
textbook_url = reverse( |
0c12181e2c02
Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
387
diff
changeset
|
644 |
'view_textbook', kwargs={'task_id': textbook.id}) |
373
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
372
diff
changeset
|
645 |
|
440
56ea209e559f
Use the right form of names to be stored in the database.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
430
diff
changeset
|
646 |
can_edit = True if user == textbook.created_by and textbook.status == taskapp_models.TB_STATUS_CHOICES[0][0]\ |
373
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
372
diff
changeset
|
647 |
else False |
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
372
diff
changeset
|
648 |
|
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
372
diff
changeset
|
649 |
if not can_edit: |
425
e15749fab2e4
Restructured create form to use templatetags and use Javascript for autcomplete.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
422
diff
changeset
|
650 |
raise http.Http404 |
373
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
372
diff
changeset
|
651 |
|
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
372
diff
changeset
|
652 |
context = {"user": user, |
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
372
diff
changeset
|
653 |
"profile": profile, |
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
372
diff
changeset
|
654 |
"textbook": textbook, |
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
372
diff
changeset
|
655 |
} |
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
372
diff
changeset
|
656 |
|
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
372
diff
changeset
|
657 |
context.update(csrf(request)) |
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
372
diff
changeset
|
658 |
|
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
372
diff
changeset
|
659 |
if request.method == "POST": |
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
660 |
form = taskapp_forms.EditTextbookForm(request.POST, instance=textbook) |
373
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
372
diff
changeset
|
661 |
if form.is_valid(): |
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
372
diff
changeset
|
662 |
form.save() |
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
663 |
return shortcuts.redirect(textbook_url) |
373
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
372
diff
changeset
|
664 |
else: |
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
372
diff
changeset
|
665 |
context.update({"form": form}) |
451
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
666 |
return shortcuts.render_to_response( |
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
667 |
"task/edit.html", RequestContext(request, context)) |
373
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
372
diff
changeset
|
668 |
else: |
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
669 |
form = taskapp_forms.EditTextbookForm(instance=textbook) |
373
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
372
diff
changeset
|
670 |
context.update({"form": form}) |
451
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
671 |
return shortcuts.render_to_response("task/edit.html", |
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
672 |
RequestContext(request, context)) |
373
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
372
diff
changeset
|
673 |
|
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
372
diff
changeset
|
674 |
@login_required |
526
9c0c88d129dd
Add a view, form and related URL for chapter creation under textbook.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
515
diff
changeset
|
675 |
def create_chapter(request, book_id, template='task/chapter_edit.html'): |
9c0c88d129dd
Add a view, form and related URL for chapter creation under textbook.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
515
diff
changeset
|
676 |
"""View function to let Coordinators and TAs (Mentor in |
9c0c88d129dd
Add a view, form and related URL for chapter creation under textbook.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
515
diff
changeset
|
677 |
PyTask terminology) create chapters out of textbooks. |
9c0c88d129dd
Add a view, form and related URL for chapter creation under textbook.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
515
diff
changeset
|
678 |
|
9c0c88d129dd
Add a view, form and related URL for chapter creation under textbook.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
515
diff
changeset
|
679 |
Args: |
9c0c88d129dd
Add a view, form and related URL for chapter creation under textbook.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
515
diff
changeset
|
680 |
book_id: ID of the text book to which this chapter belongs to |
9c0c88d129dd
Add a view, form and related URL for chapter creation under textbook.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
515
diff
changeset
|
681 |
""" |
9c0c88d129dd
Add a view, form and related URL for chapter creation under textbook.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
515
diff
changeset
|
682 |
|
9c0c88d129dd
Add a view, form and related URL for chapter creation under textbook.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
515
diff
changeset
|
683 |
user = request.user |
9c0c88d129dd
Add a view, form and related URL for chapter creation under textbook.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
515
diff
changeset
|
684 |
profile = user.get_profile() |
9c0c88d129dd
Add a view, form and related URL for chapter creation under textbook.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
515
diff
changeset
|
685 |
|
9c0c88d129dd
Add a view, form and related URL for chapter creation under textbook.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
515
diff
changeset
|
686 |
if profile.role != profile_models.ROLES_CHOICES[3][0]: |
9c0c88d129dd
Add a view, form and related URL for chapter creation under textbook.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
515
diff
changeset
|
687 |
can_create = True |
9c0c88d129dd
Add a view, form and related URL for chapter creation under textbook.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
515
diff
changeset
|
688 |
else: |
9c0c88d129dd
Add a view, form and related URL for chapter creation under textbook.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
515
diff
changeset
|
689 |
can_create= False |
9c0c88d129dd
Add a view, form and related URL for chapter creation under textbook.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
515
diff
changeset
|
690 |
|
9c0c88d129dd
Add a view, form and related URL for chapter creation under textbook.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
515
diff
changeset
|
691 |
if not can_create: |
9c0c88d129dd
Add a view, form and related URL for chapter creation under textbook.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
515
diff
changeset
|
692 |
raise http.HttpResponseForbidden |
9c0c88d129dd
Add a view, form and related URL for chapter creation under textbook.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
515
diff
changeset
|
693 |
|
9c0c88d129dd
Add a view, form and related URL for chapter creation under textbook.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
515
diff
changeset
|
694 |
context = { |
9c0c88d129dd
Add a view, form and related URL for chapter creation under textbook.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
515
diff
changeset
|
695 |
'user': user, |
9c0c88d129dd
Add a view, form and related URL for chapter creation under textbook.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
515
diff
changeset
|
696 |
'profile': profile, |
9c0c88d129dd
Add a view, form and related URL for chapter creation under textbook.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
515
diff
changeset
|
697 |
} |
9c0c88d129dd
Add a view, form and related URL for chapter creation under textbook.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
515
diff
changeset
|
698 |
|
9c0c88d129dd
Add a view, form and related URL for chapter creation under textbook.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
515
diff
changeset
|
699 |
context.update(csrf(request)) |
9c0c88d129dd
Add a view, form and related URL for chapter creation under textbook.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
515
diff
changeset
|
700 |
|
9c0c88d129dd
Add a view, form and related URL for chapter creation under textbook.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
515
diff
changeset
|
701 |
textbook = shortcuts.get_object_or_404(taskapp_models.Task, pk=book_id) |
9c0c88d129dd
Add a view, form and related URL for chapter creation under textbook.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
515
diff
changeset
|
702 |
initial_tags = ', '.join([textbook.tags_field] + ['Chapter']) |
9c0c88d129dd
Add a view, form and related URL for chapter creation under textbook.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
515
diff
changeset
|
703 |
|
9c0c88d129dd
Add a view, form and related URL for chapter creation under textbook.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
515
diff
changeset
|
704 |
if request.method == 'POST': |
9c0c88d129dd
Add a view, form and related URL for chapter creation under textbook.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
515
diff
changeset
|
705 |
form = taskapp_forms.CreateChapterForm(request.POST) |
9c0c88d129dd
Add a view, form and related URL for chapter creation under textbook.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
515
diff
changeset
|
706 |
if form.is_valid(): |
9c0c88d129dd
Add a view, form and related URL for chapter creation under textbook.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
515
diff
changeset
|
707 |
data = form.cleaned_data.copy() |
9c0c88d129dd
Add a view, form and related URL for chapter creation under textbook.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
515
diff
changeset
|
708 |
|
9c0c88d129dd
Add a view, form and related URL for chapter creation under textbook.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
515
diff
changeset
|
709 |
data.update({ |
9c0c88d129dd
Add a view, form and related URL for chapter creation under textbook.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
515
diff
changeset
|
710 |
'created_by': user, |
9c0c88d129dd
Add a view, form and related URL for chapter creation under textbook.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
515
diff
changeset
|
711 |
'creation_datetime': datetime.now(), |
9c0c88d129dd
Add a view, form and related URL for chapter creation under textbook.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
515
diff
changeset
|
712 |
'parent': textbook, |
9c0c88d129dd
Add a view, form and related URL for chapter creation under textbook.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
515
diff
changeset
|
713 |
}) |
9c0c88d129dd
Add a view, form and related URL for chapter creation under textbook.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
515
diff
changeset
|
714 |
|
9c0c88d129dd
Add a view, form and related URL for chapter creation under textbook.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
515
diff
changeset
|
715 |
# TODO: remove hard coded default publish for chapters |
9c0c88d129dd
Add a view, form and related URL for chapter creation under textbook.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
515
diff
changeset
|
716 |
data['status'] = 'Open' |
9c0c88d129dd
Add a view, form and related URL for chapter creation under textbook.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
515
diff
changeset
|
717 |
new_chapter = taskapp_models.Task(**data) |
9c0c88d129dd
Add a view, form and related URL for chapter creation under textbook.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
515
diff
changeset
|
718 |
new_chapter.save() |
9c0c88d129dd
Add a view, form and related URL for chapter creation under textbook.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
515
diff
changeset
|
719 |
|
9c0c88d129dd
Add a view, form and related URL for chapter creation under textbook.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
515
diff
changeset
|
720 |
textbook_url = reverse( |
9c0c88d129dd
Add a view, form and related URL for chapter creation under textbook.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
515
diff
changeset
|
721 |
'view_textbook', kwargs={'task_id': textbook.id}) |
9c0c88d129dd
Add a view, form and related URL for chapter creation under textbook.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
515
diff
changeset
|
722 |
return shortcuts.redirect(textbook_url) |
9c0c88d129dd
Add a view, form and related URL for chapter creation under textbook.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
515
diff
changeset
|
723 |
else: |
9c0c88d129dd
Add a view, form and related URL for chapter creation under textbook.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
515
diff
changeset
|
724 |
context.update({"form": form}) |
9c0c88d129dd
Add a view, form and related URL for chapter creation under textbook.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
515
diff
changeset
|
725 |
return shortcuts.render_to_response( |
9c0c88d129dd
Add a view, form and related URL for chapter creation under textbook.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
515
diff
changeset
|
726 |
template, RequestContext(request, context)) |
9c0c88d129dd
Add a view, form and related URL for chapter creation under textbook.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
515
diff
changeset
|
727 |
else: |
9c0c88d129dd
Add a view, form and related URL for chapter creation under textbook.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
515
diff
changeset
|
728 |
form = taskapp_forms.CreateChapterForm( |
9c0c88d129dd
Add a view, form and related URL for chapter creation under textbook.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
515
diff
changeset
|
729 |
initial={'tags_field': initial_tags}) |
9c0c88d129dd
Add a view, form and related URL for chapter creation under textbook.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
515
diff
changeset
|
730 |
context.update({'form': form}) |
9c0c88d129dd
Add a view, form and related URL for chapter creation under textbook.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
515
diff
changeset
|
731 |
return shortcuts.render_to_response( |
9c0c88d129dd
Add a view, form and related URL for chapter creation under textbook.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
515
diff
changeset
|
732 |
template, RequestContext(request, context)) |
9c0c88d129dd
Add a view, form and related URL for chapter creation under textbook.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
515
diff
changeset
|
733 |
|
9c0c88d129dd
Add a view, form and related URL for chapter creation under textbook.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
515
diff
changeset
|
734 |
|
9c0c88d129dd
Add a view, form and related URL for chapter creation under textbook.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
515
diff
changeset
|
735 |
@login_required |
408
0c12181e2c02
Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
387
diff
changeset
|
736 |
def claim_task(request, task_id): |
353
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
737 |
|
507
1d4631fcebd0
Add uberbar messages not to claim the task. This must be disabled once claiming is possible.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
506
diff
changeset
|
738 |
context = {} |
1d4631fcebd0
Add uberbar messages not to claim the task. This must be disabled once claiming is possible.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
506
diff
changeset
|
739 |
|
1d4631fcebd0
Add uberbar messages not to claim the task. This must be disabled once claiming is possible.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
506
diff
changeset
|
740 |
# TODO(disable): Disable once the tasks can be claimed |
1d4631fcebd0
Add uberbar messages not to claim the task. This must be disabled once claiming is possible.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
506
diff
changeset
|
741 |
context['uberbar_message'] = DONT_CLAIM_TASK_MSG |
1d4631fcebd0
Add uberbar messages not to claim the task. This must be disabled once claiming is possible.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
506
diff
changeset
|
742 |
|
430
a11a778fca54
Use reverse function instead of hard coded URL.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
429
diff
changeset
|
743 |
claim_url = reverse('claim_task', kwargs={'task_id': task_id}) |
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
744 |
task = shortcuts.get_object_or_404(taskapp_models.Task, pk=task_id) |
353
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
745 |
|
440
56ea209e559f
Use the right form of names to be stored in the database.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
430
diff
changeset
|
746 |
if task.status == taskapp_models.TASK_STATUS_CHOICES[0][0]: |
425
e15749fab2e4
Restructured create form to use templatetags and use Javascript for autcomplete.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
422
diff
changeset
|
747 |
raise http.Http404 |
353
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
748 |
|
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
749 |
user = request.user |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
750 |
profile = user.get_profile() |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
751 |
|
506
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
752 |
context.update({ |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
753 |
'user': user, |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
754 |
'profile': profile, |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
755 |
'task': task, |
db2edf922849
Fix styling issues.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
501
diff
changeset
|
756 |
}) |
353
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
757 |
|
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
758 |
context.update(csrf(request)) |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
759 |
|
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
760 |
reviewers = task.reviewers.all() |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
761 |
claimed_users = task.claimed_users.all() |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
762 |
|
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
763 |
is_creator = True if user == task.created_by else False |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
764 |
is_reviewer = True if user in reviewers else False |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
765 |
has_claimed = True if user in claimed_users else False |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
766 |
|
440
56ea209e559f
Use the right form of names to be stored in the database.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
430
diff
changeset
|
767 |
task_claimable = True if task.status in [taskapp_models.TASK_STATUS_CHOICES[1][0], taskapp_models.TASK_STATUS_CHOICES[3][0]] else False |
353
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
768 |
can_claim = True if task_claimable and ( not has_claimed )\ |
357
ec7f2f4256f5
now the creator can select users
Nishanth Amuluru <nishanth@fossee.in>
parents:
356
diff
changeset
|
769 |
and ( not is_reviewer ) and (not is_creator ) \ |
ec7f2f4256f5
now the creator can select users
Nishanth Amuluru <nishanth@fossee.in>
parents:
356
diff
changeset
|
770 |
else False |
353
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
771 |
|
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
772 |
old_claims = task.claims.all() |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
773 |
|
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
774 |
context.update({"is_creator": is_creator, |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
775 |
"task_claimable": task_claimable, |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
776 |
"can_claim": can_claim, |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
777 |
"old_claims": old_claims}) |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
778 |
|
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
779 |
if request.method == "POST" and can_claim: |
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
780 |
form = taskapp_forms.ClaimTaskForm(request.POST) |
353
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
781 |
if form.is_valid(): |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
782 |
data = form.cleaned_data.copy() |
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
783 |
data.update({"task": task, |
353
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
784 |
"claim_datetime": datetime.now(), |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
785 |
"claimed_by": user,}) |
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
786 |
new_claim = taskapp_models.TaskClaim(**data) |
353
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
787 |
new_claim.save() |
355
c693def6510f
added the step of adding user to claimed users
Nishanth Amuluru <nishanth@fossee.in>
parents:
353
diff
changeset
|
788 |
|
c693def6510f
added the step of adding user to claimed users
Nishanth Amuluru <nishanth@fossee.in>
parents:
353
diff
changeset
|
789 |
task.claimed_users.add(user) |
c693def6510f
added the step of adding user to claimed users
Nishanth Amuluru <nishanth@fossee.in>
parents:
353
diff
changeset
|
790 |
task.save() |
c693def6510f
added the step of adding user to claimed users
Nishanth Amuluru <nishanth@fossee.in>
parents:
353
diff
changeset
|
791 |
|
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
792 |
return shortcuts.redirect(claim_url) |
353
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
793 |
|
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
794 |
else: |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
795 |
context.update({"form": form}) |
451
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
796 |
return shortcuts.render_to_response( |
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
797 |
"task/claim.html", RequestContext(request, context)) |
353
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
798 |
else: |
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
799 |
form = taskapp_forms.ClaimTaskForm() |
353
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
800 |
context.update({"form": form}) |
451
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
801 |
return shortcuts.render_to_response( |
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
802 |
"task/claim.html", RequestContext(request, context)) |
353
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
803 |
|
360 | 804 |
@login_required |
408
0c12181e2c02
Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
387
diff
changeset
|
805 |
def select_user(request, task_id): |
360 | 806 |
""" first get the status of the task and then select one of claimed users |
807 |
generate list of claimed users by passing it as an argument to a function. |
|
808 |
""" |
|
408
0c12181e2c02
Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
387
diff
changeset
|
809 |
|
0c12181e2c02
Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
387
diff
changeset
|
810 |
task_url = reverse('view_task', kwargs={'task_id': task_id}) |
0c12181e2c02
Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
387
diff
changeset
|
811 |
|
360 | 812 |
user = request.user |
813 |
profile = user.get_profile() |
|
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
814 |
task = shortcuts.get_object_or_404(taskapp_models.Task, pk=task_id) |
408
0c12181e2c02
Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
387
diff
changeset
|
815 |
|
360 | 816 |
context = {"user": user, |
817 |
"profile": profile, |
|
818 |
"task": task, |
|
819 |
} |
|
353
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
820 |
|
360 | 821 |
context.update(csrf(request)) |
822 |
||
823 |
claimed_users = task.claimed_users.all() |
|
362
070f01dd7d8e
Select user works completely fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
360
diff
changeset
|
824 |
task_claimed = True if claimed_users else False |
360 | 825 |
|
826 |
is_creator = True if user == task.created_by else False |
|
827 |
||
443
a13ea00c1a3f
Use the correct choices variable for the role and status.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
440
diff
changeset
|
828 |
if (is_creator or profile.role in [profile_models.ROLES_CHOICES[1][0], profile_models.ROLES_CHOICES[2][0]]) and \ |
440
56ea209e559f
Use the right form of names to be stored in the database.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
430
diff
changeset
|
829 |
task.status in [taskapp_models.TASK_STATUS_CHOICES[1][0], taskapp_models.TASK_STATUS_CHOICES[3][0]]: |
360 | 830 |
|
362
070f01dd7d8e
Select user works completely fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
360
diff
changeset
|
831 |
if task_claimed: |
360 | 832 |
|
833 |
user_list = ((user.id,user.username) for user in claimed_users) |
|
834 |
||
835 |
if request.method == "POST": |
|
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
836 |
form = taskapp_forms.ChoiceForm(user_list, request.POST) |
360 | 837 |
if form.is_valid(): |
838 |
uid = form.cleaned_data['choice'] |
|
839 |
selected_user = User.objects.get(id=uid) |
|
840 |
||
362
070f01dd7d8e
Select user works completely fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
360
diff
changeset
|
841 |
task.selected_users.add(selected_user) |
070f01dd7d8e
Select user works completely fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
360
diff
changeset
|
842 |
task.claimed_users.remove(selected_user) |
440
56ea209e559f
Use the right form of names to be stored in the database.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
430
diff
changeset
|
843 |
task.status = taskapp_models.TASK_STATUS_CHOICES[3][0] |
360 | 844 |
task.save() |
845 |
||
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
846 |
return shortcuts.redirect(task_url) |
360 | 847 |
else: |
848 |
context.update({"form": form}) |
|
451
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
849 |
return shortcuts.render_to_response( |
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
850 |
'task/select_user.html', |
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
851 |
RequestContext(request, context)) |
360 | 852 |
else: |
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
853 |
form = taskapp_forms.ChoiceForm(user_list) |
360 | 854 |
context.update({"form": form}) |
451
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
855 |
return shortcuts.render_to_response( |
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
856 |
'task/select_user.html', |
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
857 |
RequestContext(request, context)) |
360 | 858 |
else: |
859 |
return show_msg(user, 'There are no pending claims for this task', |
|
860 |
task_url, 'view the task') |
|
861 |
else: |
|
425
e15749fab2e4
Restructured create form to use templatetags and use Javascript for autcomplete.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
422
diff
changeset
|
862 |
raise http.Http404 |
360 | 863 |
|
380
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
377
diff
changeset
|
864 |
@login_required |
408
0c12181e2c02
Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
387
diff
changeset
|
865 |
def approve_textbook(request, task_id): |
380
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
377
diff
changeset
|
866 |
|
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
377
diff
changeset
|
867 |
user = request.user |
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
377
diff
changeset
|
868 |
profile = user.get_profile() |
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
377
diff
changeset
|
869 |
|
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
870 |
textbook = shortcuts.get_object_or_404(taskapp_models.TextBook, pk=task_id) |
380
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
377
diff
changeset
|
871 |
|
443
a13ea00c1a3f
Use the correct choices variable for the role and status.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
440
diff
changeset
|
872 |
if profile.role not in [profile_models.ROLES_CHOICES[0][0], profile_models.ROLES_CHOICES[1][0]] or textbook.status != taskapp_models.TB_STATUS_CHOICES[0][0]: |
425
e15749fab2e4
Restructured create form to use templatetags and use Javascript for autcomplete.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
422
diff
changeset
|
873 |
raise http.Http404 |
380
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
377
diff
changeset
|
874 |
|
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
377
diff
changeset
|
875 |
context = {"user": user, |
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
377
diff
changeset
|
876 |
"profile": profile, |
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
377
diff
changeset
|
877 |
"textbook": textbook, |
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
377
diff
changeset
|
878 |
} |
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
377
diff
changeset
|
879 |
|
451
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
880 |
return shortcuts.render_to_response( |
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
881 |
"task/confirm_textbook_approval.html", |
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
882 |
RequestContext(request, context)) |
380
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
377
diff
changeset
|
883 |
|
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
377
diff
changeset
|
884 |
@login_required |
408
0c12181e2c02
Make changes to the import styles, ids used and use reverse function for URL generation instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
387
diff
changeset
|
885 |
def approved_textbook(request, task_id): |
380
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
377
diff
changeset
|
886 |
|
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
377
diff
changeset
|
887 |
user = request.user |
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
377
diff
changeset
|
888 |
profile = user.get_profile() |
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
377
diff
changeset
|
889 |
|
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
890 |
textbook = shortcuts.get_object_or_404(taskapp_models.TextBook, pk=task_id) |
380
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
377
diff
changeset
|
891 |
|
443
a13ea00c1a3f
Use the correct choices variable for the role and status.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
440
diff
changeset
|
892 |
if profile.role not in [profile_models.ROLES_CHOICES[0][0], profile_models.ROLES_CHOICES[1][0]] or textbook.status != taskapp_models.TB_STATUS_CHOICES[0][0]: |
425
e15749fab2e4
Restructured create form to use templatetags and use Javascript for autcomplete.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
422
diff
changeset
|
893 |
raise http.Http404 |
380
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
377
diff
changeset
|
894 |
|
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
377
diff
changeset
|
895 |
textbook.approved_by = user |
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
377
diff
changeset
|
896 |
textbook.approval_datetime = datetime.now() |
440
56ea209e559f
Use the right form of names to be stored in the database.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
430
diff
changeset
|
897 |
textbook.status = taskapp_models.TB_STATUS_CHOICES[1][0] |
380
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
377
diff
changeset
|
898 |
textbook.save() |
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
377
diff
changeset
|
899 |
|
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
377
diff
changeset
|
900 |
context = {"user": user, |
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
377
diff
changeset
|
901 |
"profile": profile, |
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
377
diff
changeset
|
902 |
"textbook": textbook, |
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
377
diff
changeset
|
903 |
} |
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
377
diff
changeset
|
904 |
|
451
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
905 |
return shortcuts.render_to_response( |
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
906 |
"task/approved_textbook.html", RequestContext(request, context)) |
425
e15749fab2e4
Restructured create form to use templatetags and use Javascript for autcomplete.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
422
diff
changeset
|
907 |
|
e15749fab2e4
Restructured create form to use templatetags and use Javascript for autcomplete.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
422
diff
changeset
|
908 |
def suggest_task_tags(request): |
e15749fab2e4
Restructured create form to use templatetags and use Javascript for autcomplete.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
422
diff
changeset
|
909 |
"""Returns the tags matching the query for the AJAXy autocomplete |
e15749fab2e4
Restructured create form to use templatetags and use Javascript for autcomplete.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
422
diff
changeset
|
910 |
to get tags related to tasks. |
e15749fab2e4
Restructured create form to use templatetags and use Javascript for autcomplete.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
422
diff
changeset
|
911 |
""" |
e15749fab2e4
Restructured create form to use templatetags and use Javascript for autcomplete.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
422
diff
changeset
|
912 |
|
427
42156890006d
Move all the content from create form to edit form for tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
425
diff
changeset
|
913 |
term = request.GET.get('term', None) |
42156890006d
Move all the content from create form to edit form for tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
425
diff
changeset
|
914 |
response = [] |
42156890006d
Move all the content from create form to edit form for tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
425
diff
changeset
|
915 |
|
42156890006d
Move all the content from create form to edit form for tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
425
diff
changeset
|
916 |
if term: |
42156890006d
Move all the content from create form to edit form for tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
425
diff
changeset
|
917 |
tag_entities = Tag.objects.filter(name__icontains=term) |
42156890006d
Move all the content from create form to edit form for tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
425
diff
changeset
|
918 |
response = [tag.name for tag in tag_entities] |
42156890006d
Move all the content from create form to edit form for tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
425
diff
changeset
|
919 |
|
42156890006d
Move all the content from create form to edit form for tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
425
diff
changeset
|
920 |
json_response = json.dumps(response) |
42156890006d
Move all the content from create form to edit form for tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
425
diff
changeset
|
921 |
return http.HttpResponse(json_response) |