author | Madhusudan.C.S <madhusudancs@gmail.com> |
Tue, 18 Jan 2011 01:10:40 +0530 | |
changeset 451 | 09a1ee04a3f4 |
parent 443 | a13ea00c1a3f |
child 489 | 9cd090b8cd52 |
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 |
333
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
11 |
|
428
c9d8cd54195e
Remove the redundant function for suggesting tags and added the required import.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
427
diff
changeset
|
12 |
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
|
13 |
|
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
|
14 |
from pytask.views import show_msg |
333
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
15 |
|
440
56ea209e559f
Use the right form of names to be stored in the database.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
430
diff
changeset
|
16 |
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
|
17 |
|
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
18 |
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
|
19 |
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
|
20 |
|
339
bce480ff6ddc
used proper import for show_msg
Nishanth Amuluru <nishanth@fossee.in>
parents:
333
diff
changeset
|
21 |
|
333
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
22 |
@login_required |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
23 |
def create_task(request): |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
24 |
|
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
25 |
user = request.user |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
26 |
profile = user.get_profile() |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
27 |
|
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
28 |
context = {"user": user, |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
29 |
"profile": profile, |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
30 |
} |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
31 |
|
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
32 |
context.update(csrf(request)) |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
33 |
|
440
56ea209e559f
Use the right form of names to be stored in the database.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
430
diff
changeset
|
34 |
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
|
35 |
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
|
36 |
if can_create_task: |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
37 |
if request.method == "POST": |
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
38 |
form = taskapp_forms.CreateTaskForm(request.POST) |
333
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
39 |
if form.is_valid(): |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
40 |
data = form.cleaned_data.copy() |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
41 |
data.update({"created_by": user, |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
42 |
"creation_datetime": datetime.now(), |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
43 |
}) |
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
|
44 |
|
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
45 |
task = taskapp_models.Task(**data) |
333
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
46 |
task.save() |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
47 |
|
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
|
48 |
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
|
49 |
return shortcuts.redirect(task_url) |
333
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
50 |
else: |
340 | 51 |
context.update({'form':form}) |
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
52 |
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
|
53 |
'task/edit.html', RequestContext(request, context)) |
333
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
54 |
else: |
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
55 |
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
|
56 |
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
|
57 |
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
|
58 |
'task/edit.html', RequestContext(request, context)) |
333
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
59 |
else: |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
60 |
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
|
61 |
|
376
5a94c774473c
browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
374
diff
changeset
|
62 |
def browse_tasks(request): |
5a94c774473c
browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
374
diff
changeset
|
63 |
|
440
56ea209e559f
Use the right form of names to be stored in the database.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
430
diff
changeset
|
64 |
open_tasks = taskapp_models.Task.objects.filter(status=taskapp_models.TASK_STATUS_CHOICES[1][0]) |
56ea209e559f
Use the right form of names to be stored in the database.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
430
diff
changeset
|
65 |
working_tasks = taskapp_models.Task.objects.filter(status=taskapp_models.TASK_STATUS_CHOICES[3][0]) |
56ea209e559f
Use the right form of names to be stored in the database.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
430
diff
changeset
|
66 |
comp_tasks = taskapp_models.Task.objects.filter(status=taskapp_models.TASK_STATUS_CHOICES[6][0]) |
376
5a94c774473c
browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
374
diff
changeset
|
67 |
|
5a94c774473c
browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
374
diff
changeset
|
68 |
context = {"open_tasks": open_tasks, |
5a94c774473c
browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
374
diff
changeset
|
69 |
"working_tasks": working_tasks, |
5a94c774473c
browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
374
diff
changeset
|
70 |
"comp_tasks": comp_tasks, |
5a94c774473c
browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
374
diff
changeset
|
71 |
} |
5a94c774473c
browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
374
diff
changeset
|
72 |
|
5a94c774473c
browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
374
diff
changeset
|
73 |
user = request.user |
5a94c774473c
browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
374
diff
changeset
|
74 |
if not user.is_authenticated(): |
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
75 |
return shortcuts.render_to_response("task/browse.html") |
376
5a94c774473c
browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
374
diff
changeset
|
76 |
|
5a94c774473c
browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
374
diff
changeset
|
77 |
profile = user.get_profile() |
5a94c774473c
browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
374
diff
changeset
|
78 |
|
443
a13ea00c1a3f
Use the correct choices variable for the role and status.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
440
diff
changeset
|
79 |
can_approve = True if profile.role in [profile_models.ROLES_CHOICES[0][0], profile_models.ROLES_CHOICES[1][0]] 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
|
80 |
unpub_tasks = taskapp_models.Task.objects.filter(status=taskapp_models.TASK_STATUS_CHOICES[0][0]).exclude(status=taskapp_models.TASK_STATUS_CHOICES[5][0]) |
376
5a94c774473c
browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
374
diff
changeset
|
81 |
if can_approve: |
5a94c774473c
browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
374
diff
changeset
|
82 |
context.update({"unpub_tasks": unpub_tasks}) |
5a94c774473c
browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
374
diff
changeset
|
83 |
|
5a94c774473c
browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
374
diff
changeset
|
84 |
context.update({"user": user, |
5a94c774473c
browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
374
diff
changeset
|
85 |
"profile": profile, |
5a94c774473c
browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
374
diff
changeset
|
86 |
}) |
5a94c774473c
browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
374
diff
changeset
|
87 |
|
451
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
88 |
return shortcuts.render_to_response("task/browse.html", |
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
89 |
RequestContext(request, context)) |
376
5a94c774473c
browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
374
diff
changeset
|
90 |
|
5a94c774473c
browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
374
diff
changeset
|
91 |
|
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
|
92 |
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
|
93 |
""" 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
|
94 |
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
|
95 |
""" |
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
|
96 |
|
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
|
97 |
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
|
98 |
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
|
99 |
|
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
|
100 |
user = request.user |
350
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
349
diff
changeset
|
101 |
|
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
349
diff
changeset
|
102 |
if not user.is_authenticated(): |
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
103 |
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
|
104 |
|
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
|
105 |
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
|
106 |
|
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
|
107 |
context = {"user": user, |
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
|
108 |
"profile": 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
|
109 |
"task": task, |
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
|
110 |
} |
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
|
111 |
|
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
|
112 |
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
|
113 |
|
440
56ea209e559f
Use the right form of names to be stored in the database.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
430
diff
changeset
|
114 |
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
|
115 |
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
|
116 |
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
|
117 |
|
443
a13ea00c1a3f
Use the correct choices variable for the role and status.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
440
diff
changeset
|
118 |
task_viewable = True if ( task.status != taskapp_models.TASK_STATUS_CHOICES[0][0] ) or profile.role != profile_models.ROLES_CHOICES[3][0] \ |
350
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
349
diff
changeset
|
119 |
else False |
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
349
diff
changeset
|
120 |
if not task_viewable: |
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 |
return show_msg(user, "You are not authorised to view this task", |
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 |
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
|
123 |
|
350
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
349
diff
changeset
|
124 |
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
|
125 |
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
|
126 |
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
|
127 |
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
|
128 |
|
350
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
349
diff
changeset
|
129 |
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
|
130 |
'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
|
131 |
'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
|
132 |
}) |
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 |
|
350
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
349
diff
changeset
|
134 |
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
|
135 |
|
350
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
349
diff
changeset
|
136 |
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
|
137 |
|
365
32457bce3437
prettified a few pages
Nishanth Amuluru <nishanth@fossee.in>
parents:
363
diff
changeset
|
138 |
context['selected_users'] = selected_users |
350
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
349
diff
changeset
|
139 |
context['is_selected'] = True if user in selected_users 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
|
140 |
context['can_approve'] = True if task.status == taskapp_models.TASK_STATUS_CHOICES[0][0] and\ |
443
a13ea00c1a3f
Use the correct choices variable for the role and status.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
440
diff
changeset
|
141 |
profile.role in [profile_models.ROLES_CHOICES[0][0], profile_models.ROLES_CHOICES[1][0]]\ |
350
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
349
diff
changeset
|
142 |
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
|
143 |
context['can_edit'] = True if is_creator and task.status == taskapp_models.TASK_STATUS_CHOICES[0][0] else False |
56ea209e559f
Use the right form of names to be stored in the database.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
430
diff
changeset
|
144 |
context['can_close'] = True if task.status not in [taskapp_models.TASK_STATUS_CHOICES[0][0], taskapp_models.TASK_STATUS_CHOICES[4][0], taskapp_models.TASK_STATUS_CHOICES[6][0]] and is_reviewer else False |
56ea209e559f
Use the right form of names to be stored in the database.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
430
diff
changeset
|
145 |
context['can_delete'] = True if task.status == taskapp_models.TASK_STATUS_CHOICES[0][0] and is_creator 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
|
146 |
|
440
56ea209e559f
Use the right form of names to be stored in the database.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
430
diff
changeset
|
147 |
context['can_assign_pynts'] = True if task.status in [taskapp_models.TASK_STATUS_CHOICES[1][0], taskapp_models.TASK_STATUS_CHOICES[3][0]] and is_reviewer else False |
56ea209e559f
Use the right form of names to be stored in the database.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
430
diff
changeset
|
148 |
context['task_claimable'] = True if task.status in [taskapp_models.TASK_STATUS_CHOICES[1][0], taskapp_models.TASK_STATUS_CHOICES[3][0]] else False |
350
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
349
diff
changeset
|
149 |
|
440
56ea209e559f
Use the right form of names to be stored in the database.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
430
diff
changeset
|
150 |
context['can_comment'] = True if task.status != taskapp_models.TASK_STATUS_CHOICES[0][0] or\ |
443
a13ea00c1a3f
Use the correct choices variable for the role and status.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
440
diff
changeset
|
151 |
profile.role != profile_models.ROLES_CHOICES[3][0] 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
|
152 |
|
443
a13ea00c1a3f
Use the correct choices variable for the role and status.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
440
diff
changeset
|
153 |
context['can_mod_reviewers'] = True if profile.role in [profile_models.ROLES_CHOICES[0][0], profile_models.ROLES_CHOICES[1][0]] else\ |
381
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
380
diff
changeset
|
154 |
False |
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
380
diff
changeset
|
155 |
|
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
|
156 |
if request.method == 'POST': |
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
157 |
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
|
158 |
if form.is_valid(): |
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
349
diff
changeset
|
159 |
data = form.cleaned_data['data'] |
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
160 |
new_comment = taskapp_forms.TaskComment( |
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
161 |
task=task, data=data, commented_by=user, |
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
162 |
comment_datetime=datetime.now()) |
350
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
349
diff
changeset
|
163 |
new_comment.save() |
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
164 |
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
|
165 |
else: |
350
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
349
diff
changeset
|
166 |
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
|
167 |
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
|
168 |
'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
|
169 |
else: |
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
170 |
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
|
171 |
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
|
172 |
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
|
173 |
'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
|
174 |
|
353
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
175 |
@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
|
176 |
def edit_task(request, task_id): |
366 | 177 |
""" only creator gets to edit the task and that too only before it gets |
178 |
approved. |
|
179 |
""" |
|
180 |
||
181 |
user = request.user |
|
182 |
profile = user.get_profile() |
|
183 |
||
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
|
184 |
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
|
185 |
task = shortcuts.get_object_or_404(taskapp_models.Task, pk=task_id) |
366 | 186 |
|
187 |
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
|
188 |
can_edit = True if task.status == taskapp_models.TASK_STATUS_CHOICES[0][0] and is_creator else False |
366 | 189 |
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
|
190 |
raise http.Http404 |
366 | 191 |
|
192 |
context = {"user": user, |
|
193 |
"profile": profile, |
|
194 |
"task": task, |
|
195 |
} |
|
196 |
||
197 |
context.update(csrf(request)) |
|
198 |
||
199 |
if request.method == "POST": |
|
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
200 |
form = taskapp_forms.EditTaskForm(request.POST, instance=task) |
366 | 201 |
if form.is_valid(): |
202 |
form.save() |
|
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
203 |
return shortcuts.redirect(task_url) |
366 | 204 |
else: |
205 |
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
|
206 |
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
|
207 |
"task/edit.html", RequestContext(request, context)) |
366 | 208 |
else: |
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
209 |
form = taskapp_forms.EditTaskForm(instance=task) |
366 | 210 |
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
|
211 |
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
|
212 |
RequestContext(request, context)) |
366 | 213 |
|
368
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
366
diff
changeset
|
214 |
@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
|
215 |
def approve_task(request, task_id): |
374
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
373
diff
changeset
|
216 |
|
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
373
diff
changeset
|
217 |
user = request.user |
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
373
diff
changeset
|
218 |
profile = user.get_profile() |
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
373
diff
changeset
|
219 |
|
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
220 |
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
|
221 |
|
443
a13ea00c1a3f
Use the correct choices variable for the role and status.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
440
diff
changeset
|
222 |
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
|
223 |
raise http.Http404 |
374
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
373
diff
changeset
|
224 |
|
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
373
diff
changeset
|
225 |
context = {"user": user, |
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
373
diff
changeset
|
226 |
"profile": profile, |
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
373
diff
changeset
|
227 |
"task": task, |
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
373
diff
changeset
|
228 |
} |
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
373
diff
changeset
|
229 |
|
451
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
230 |
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
|
231 |
"task/confirm_approval.html", RequestContext(request, context)) |
374
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
373
diff
changeset
|
232 |
|
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
373
diff
changeset
|
233 |
@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
|
234 |
def approved_task(request, task_id): |
374
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
373
diff
changeset
|
235 |
|
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
373
diff
changeset
|
236 |
user = request.user |
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
373
diff
changeset
|
237 |
profile = user.get_profile() |
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
373
diff
changeset
|
238 |
|
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
239 |
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
|
240 |
|
443
a13ea00c1a3f
Use the correct choices variable for the role and status.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
440
diff
changeset
|
241 |
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
|
242 |
raise http.Http404 |
374
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
373
diff
changeset
|
243 |
|
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
373
diff
changeset
|
244 |
task.approved_by = user |
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
373
diff
changeset
|
245 |
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
|
246 |
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
|
247 |
task.save() |
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
373
diff
changeset
|
248 |
|
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
373
diff
changeset
|
249 |
context = {"user": user, |
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
373
diff
changeset
|
250 |
"profile": profile, |
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
373
diff
changeset
|
251 |
"task": task, |
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
373
diff
changeset
|
252 |
} |
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
373
diff
changeset
|
253 |
|
451
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
254 |
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
|
255 |
"task/approved_task.html", RequestContext(request, context)) |
374
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
373
diff
changeset
|
256 |
|
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
373
diff
changeset
|
257 |
@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
|
258 |
def addreviewer(request, task_id): |
381
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
380
diff
changeset
|
259 |
|
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
380
diff
changeset
|
260 |
user = request.user |
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
380
diff
changeset
|
261 |
profile = user.get_profile() |
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
380
diff
changeset
|
262 |
|
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
|
263 |
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
|
264 |
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
|
265 |
|
443
a13ea00c1a3f
Use the correct choices variable for the role and status.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
440
diff
changeset
|
266 |
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
|
267 |
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
|
268 |
raise http.Http404 |
381
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
380
diff
changeset
|
269 |
|
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
380
diff
changeset
|
270 |
context = {"user": user, |
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
380
diff
changeset
|
271 |
"profile": profile, |
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
380
diff
changeset
|
272 |
"task": task, |
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
380
diff
changeset
|
273 |
} |
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
380
diff
changeset
|
274 |
|
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
380
diff
changeset
|
275 |
context.update(csrf(request)) |
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
380
diff
changeset
|
276 |
|
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
380
diff
changeset
|
277 |
|
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
380
diff
changeset
|
278 |
# This part has to be made better |
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
380
diff
changeset
|
279 |
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
|
280 |
exclude(reviewing_tasks__id=task_id).\ |
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
281 |
exclude(claimed_tasks__id=task_id).\ |
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
282 |
exclude(selected_tasks__id=task_id).\ |
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
283 |
exclude(created_tasks__id=task_id) |
382
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
381
diff
changeset
|
284 |
|
381
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
380
diff
changeset
|
285 |
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
|
286 |
label = "Reviewer" |
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
380
diff
changeset
|
287 |
|
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
380
diff
changeset
|
288 |
if request.method == "POST": |
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
289 |
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
|
290 |
if form.is_valid(): |
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
380
diff
changeset
|
291 |
data = form.cleaned_data.copy() |
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
380
diff
changeset
|
292 |
uid = data['choice'] |
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
380
diff
changeset
|
293 |
reviewer = User.objects.get(id=uid) |
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
380
diff
changeset
|
294 |
|
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
380
diff
changeset
|
295 |
task.reviewers.add(reviewer) |
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
296 |
return shortcuts.redirect(task_url) |
381
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
380
diff
changeset
|
297 |
else: |
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
380
diff
changeset
|
298 |
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
|
299 |
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
|
300 |
"task/addreviewer.html", RequestContext(request, context)) |
381
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
380
diff
changeset
|
301 |
else: |
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
302 |
form = taskapp_forms.ChoiceForm(choices, label=label) |
381
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
380
diff
changeset
|
303 |
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
|
304 |
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
|
305 |
"task/addreviewer.html", RequestContext(request, context)) |
381
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
380
diff
changeset
|
306 |
|
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
|
307 |
def view_work(request, task_id): |
382
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
381
diff
changeset
|
308 |
|
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
309 |
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
|
310 |
|
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
381
diff
changeset
|
311 |
user = request.user |
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
381
diff
changeset
|
312 |
old_reports = task.reports.all() |
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
381
diff
changeset
|
313 |
|
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
381
diff
changeset
|
314 |
context = {"task": task, |
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
381
diff
changeset
|
315 |
"old_reports": old_reports, |
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
381
diff
changeset
|
316 |
} |
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
381
diff
changeset
|
317 |
|
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
381
diff
changeset
|
318 |
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
|
319 |
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
|
320 |
"task/view_work.html", RequestContext(request, context)) |
382
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
381
diff
changeset
|
321 |
|
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
381
diff
changeset
|
322 |
profile = user.get_profile() |
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
381
diff
changeset
|
323 |
|
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
381
diff
changeset
|
324 |
context.update({"user": user, |
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
381
diff
changeset
|
325 |
"profile": profile, |
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
381
diff
changeset
|
326 |
}) |
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
381
diff
changeset
|
327 |
|
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
381
diff
changeset
|
328 |
context.update(csrf(request)) |
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
381
diff
changeset
|
329 |
|
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
381
diff
changeset
|
330 |
working_users = task.selected_users.all() |
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
381
diff
changeset
|
331 |
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
|
332 |
|
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
381
diff
changeset
|
333 |
context.update({"is_working": is_working}) |
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
381
diff
changeset
|
334 |
|
451
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
335 |
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
|
336 |
RequestContext(request, context)) |
382
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
381
diff
changeset
|
337 |
|
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
381
diff
changeset
|
338 |
@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
|
339 |
def view_report(request, report_id): |
383
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
340 |
|
425
e15749fab2e4
Restructured create form to use templatetags and use Javascript for autcomplete.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
422
diff
changeset
|
341 |
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
|
342 |
pk=report_id) |
383
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
343 |
|
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
344 |
user = request.user |
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
345 |
context = {"report": report, |
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
346 |
"user": user, |
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
347 |
} |
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
348 |
|
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
349 |
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
|
350 |
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
|
351 |
"task/view_report.html", RequestContext(request, context)) |
383
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
352 |
|
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
353 |
profile = user.get_profile() |
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
354 |
|
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
355 |
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
|
356 |
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
|
357 |
RequestContext(request, context)) |
383
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
358 |
|
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
359 |
@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
|
360 |
def submit_report(request, task_id): |
383
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
361 |
""" 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
|
362 |
""" |
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
|
363 |
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
|
364 |
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
|
365 |
|
383
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
366 |
user = request.user |
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
367 |
old_reports = task.reports.all() |
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
368 |
|
440
56ea209e559f
Use the right form of names to be stored in the database.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
430
diff
changeset
|
369 |
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
|
370 |
raise http.Http404 |
383
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
371 |
|
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
372 |
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
|
373 |
|
383
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
374 |
context = { |
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
375 |
'user': user, |
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
376 |
'task': task, |
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
377 |
'can_upload': can_upload, |
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
378 |
} |
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
379 |
|
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
380 |
context.update(csrf(request)) |
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
381 |
|
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
382 |
if request.method == "POST": |
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
383 |
if not can_upload: |
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
384 |
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
|
385 |
|
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
386 |
form = taskapp_forms.WorkReportForm(request.POST, request.FILES) |
383
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
387 |
|
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
388 |
if form.is_valid(): |
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
389 |
data = form.cleaned_data.copy() |
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
390 |
data.update({"task":task, |
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
391 |
"revision": old_reports.count(), |
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
392 |
"submitted_by": user, |
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
393 |
"submitted_at": datetime.now(), |
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
394 |
}) |
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
395 |
r = taskapp_models.WorkReport(**data) |
383
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
396 |
r.save() |
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
397 |
|
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
|
398 |
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
|
399 |
return shortcuts.redirect(report_url) |
383
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
400 |
|
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
401 |
else: |
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
402 |
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
|
403 |
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
|
404 |
'task/submit_report.html', RequestContext(request, context)) |
383
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
405 |
|
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
406 |
else: |
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
407 |
form = taskapp_forms.WorkReportForm() |
383
4252da60a4ef
submit report works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
382
diff
changeset
|
408 |
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
|
409 |
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
|
410 |
'task/submit_report.html', RequestContext(request, context)) |
382
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
381
diff
changeset
|
411 |
|
381
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
380
diff
changeset
|
412 |
@login_required |
368
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
366
diff
changeset
|
413 |
def create_textbook(request): |
366 | 414 |
|
368
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
366
diff
changeset
|
415 |
user = request.user |
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
366
diff
changeset
|
416 |
profile = user.get_profile() |
366 | 417 |
|
443
a13ea00c1a3f
Use the correct choices variable for the role and status.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
440
diff
changeset
|
418 |
can_create = True if profile.role != profile_models.ROLES_CHOICES[3][0] else False |
368
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
366
diff
changeset
|
419 |
if not can_create: |
425
e15749fab2e4
Restructured create form to use templatetags and use Javascript for autcomplete.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
422
diff
changeset
|
420 |
raise http.Http404 |
368
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
366
diff
changeset
|
421 |
|
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
366
diff
changeset
|
422 |
context = {"user": user, |
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
366
diff
changeset
|
423 |
"profile": profile, |
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
366
diff
changeset
|
424 |
} |
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
366
diff
changeset
|
425 |
|
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
366
diff
changeset
|
426 |
context.update(csrf(request)) |
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
366
diff
changeset
|
427 |
|
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
366
diff
changeset
|
428 |
if request.method == "POST": |
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
429 |
form = taskapp_forms.CreateTextbookForm(request.POST) |
368
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
366
diff
changeset
|
430 |
if form.is_valid(): |
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
366
diff
changeset
|
431 |
data = form.cleaned_data.copy() |
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
432 |
data.update({"created_by": user, |
368
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
366
diff
changeset
|
433 |
"creation_datetime": datetime.now()}) |
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
366
diff
changeset
|
434 |
del data['chapters'] |
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
435 |
new_textbook = taskapp_models.TextBook(**data) |
368
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
366
diff
changeset
|
436 |
new_textbook.save() |
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
366
diff
changeset
|
437 |
|
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
366
diff
changeset
|
438 |
new_textbook.chapters = form.cleaned_data['chapters'] |
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
366
diff
changeset
|
439 |
|
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
|
440 |
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
|
441 |
'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
|
442 |
return shortcuts.redirect(textbook_url) |
368
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
366
diff
changeset
|
443 |
else: |
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
366
diff
changeset
|
444 |
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
|
445 |
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
|
446 |
"task/edit.html", RequestContext(request, context)) |
368
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
366
diff
changeset
|
447 |
else: |
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
448 |
form = taskapp_forms.CreateTextbookForm() |
368
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
366
diff
changeset
|
449 |
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
|
450 |
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
|
451 |
"task/edit.html", RequestContext(request, context)) |
366 | 452 |
|
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
|
453 |
def view_textbook(request, task_id): |
370
1be4a3c09a47
view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
368
diff
changeset
|
454 |
|
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
455 |
textbook = shortcuts.get_object_or_404(taskapp_models.TextBook, pk=task_id) |
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
|
456 |
chapters = textbook.chapters.all() |
370
1be4a3c09a47
view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
368
diff
changeset
|
457 |
|
1be4a3c09a47
view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
368
diff
changeset
|
458 |
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
|
459 |
|
32dd15eaf9d0
fixed a bug where guest users were not able to view the page correctly
Nishanth Amuluru <nishanth@fossee.in>
parents:
386
diff
changeset
|
460 |
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
|
461 |
"textbook": textbook, |
32dd15eaf9d0
fixed a bug where guest users were not able to view the page correctly
Nishanth Amuluru <nishanth@fossee.in>
parents:
386
diff
changeset
|
462 |
"chapters": chapters, |
32dd15eaf9d0
fixed a bug where guest users were not able to view the page correctly
Nishanth Amuluru <nishanth@fossee.in>
parents:
386
diff
changeset
|
463 |
} |
32dd15eaf9d0
fixed a bug where guest users were not able to view the page correctly
Nishanth Amuluru <nishanth@fossee.in>
parents:
386
diff
changeset
|
464 |
|
370
1be4a3c09a47
view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
368
diff
changeset
|
465 |
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
|
466 |
return shortcuts.render_to_response("task/view_textbook.html", |
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
467 |
RequestContext(request, context)) |
370
1be4a3c09a47
view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
368
diff
changeset
|
468 |
|
1be4a3c09a47
view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
368
diff
changeset
|
469 |
profile = user.get_profile() |
1be4a3c09a47
view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
368
diff
changeset
|
470 |
|
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
|
471 |
context.update({"profile": profile, |
32dd15eaf9d0
fixed a bug where guest users were not able to view the page correctly
Nishanth Amuluru <nishanth@fossee.in>
parents:
386
diff
changeset
|
472 |
"textbook": textbook, |
32dd15eaf9d0
fixed a bug where guest users were not able to view the page correctly
Nishanth Amuluru <nishanth@fossee.in>
parents:
386
diff
changeset
|
473 |
}) |
370
1be4a3c09a47
view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
368
diff
changeset
|
474 |
|
1be4a3c09a47
view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
368
diff
changeset
|
475 |
context.update(csrf(request)) |
1be4a3c09a47
view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
368
diff
changeset
|
476 |
|
440
56ea209e559f
Use the right form of names to be stored in the database.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
430
diff
changeset
|
477 |
can_edit = True if user == textbook.created_by and textbook.status == taskapp_models.TB_STATUS_CHOICES[0][0]\ |
370
1be4a3c09a47
view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
368
diff
changeset
|
478 |
else False |
1be4a3c09a47
view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
368
diff
changeset
|
479 |
|
443
a13ea00c1a3f
Use the correct choices variable for the role and status.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
440
diff
changeset
|
480 |
can_approve = True if profile.role in [profile_models.ROLES_CHOICES[0][0], profile_models.ROLES_CHOICES[1][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
|
481 |
textbook.status == taskapp_models.TB_STATUS_CHOICES[0][0] else False |
370
1be4a3c09a47
view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
368
diff
changeset
|
482 |
|
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
|
483 |
context.update({"can_edit": can_edit, |
370
1be4a3c09a47
view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
368
diff
changeset
|
484 |
"can_approve": can_approve}) |
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("task/view_textbook.html", |
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
486 |
RequestContext(request, context)) |
370
1be4a3c09a47
view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
368
diff
changeset
|
487 |
|
372
563fe356947d
created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents:
370
diff
changeset
|
488 |
def browse_textbooks(request): |
563fe356947d
created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents:
370
diff
changeset
|
489 |
|
563fe356947d
created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents:
370
diff
changeset
|
490 |
user = request.user |
563fe356947d
created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents:
370
diff
changeset
|
491 |
|
440
56ea209e559f
Use the right form of names to be stored in the database.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
430
diff
changeset
|
492 |
open_textbooks = taskapp_models.TextBook.objects.filter(status=taskapp_models.TB_STATUS_CHOICES[1][0]).\ |
372
563fe356947d
created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents:
370
diff
changeset
|
493 |
order_by("creation_datetime") |
440
56ea209e559f
Use the right form of names to be stored in the database.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
430
diff
changeset
|
494 |
comp_textbooks = taskapp_models.TextBook.objects.filter(status=taskapp_models.TB_STATUS_CHOICES[3][0]).\ |
372
563fe356947d
created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents:
370
diff
changeset
|
495 |
order_by("creation_datetime") |
563fe356947d
created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents:
370
diff
changeset
|
496 |
context = {"user": user, |
563fe356947d
created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents:
370
diff
changeset
|
497 |
"open_textbooks": open_textbooks, |
563fe356947d
created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents:
370
diff
changeset
|
498 |
"comp_textbooks": comp_textbooks, |
563fe356947d
created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents:
370
diff
changeset
|
499 |
} |
563fe356947d
created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents:
370
diff
changeset
|
500 |
|
443
a13ea00c1a3f
Use the correct choices variable for the role and status.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
440
diff
changeset
|
501 |
if user.is_authenticated() and user.get_profile().role in [profile_models.ROLES_CHOICES[0][0], profile_models.ROLES_CHOICES[1][0]]: |
440
56ea209e559f
Use the right form of names to be stored in the database.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
430
diff
changeset
|
502 |
unpub_textbooks = taskapp_models.TextBook.objects.filter(status=taskapp_models.TB_STATUS_CHOICES[0][0]) |
372
563fe356947d
created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents:
370
diff
changeset
|
503 |
|
563fe356947d
created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents:
370
diff
changeset
|
504 |
context.update({"unpub_textbooks": unpub_textbooks}) |
563fe356947d
created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents:
370
diff
changeset
|
505 |
|
451
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
506 |
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
|
507 |
RequestContext(request, context)) |
372
563fe356947d
created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents:
370
diff
changeset
|
508 |
|
366 | 509 |
@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
|
510 |
def edit_textbook(request, task_id): |
373
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
372
diff
changeset
|
511 |
|
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
372
diff
changeset
|
512 |
user = request.user |
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
372
diff
changeset
|
513 |
profile = user.get_profile() |
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
372
diff
changeset
|
514 |
|
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
515 |
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
|
516 |
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
|
517 |
'view_textbook', kwargs={'task_id': textbook.id}) |
373
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
372
diff
changeset
|
518 |
|
440
56ea209e559f
Use the right form of names to be stored in the database.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
430
diff
changeset
|
519 |
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
|
520 |
else False |
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
372
diff
changeset
|
521 |
|
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
372
diff
changeset
|
522 |
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
|
523 |
raise http.Http404 |
373
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
372
diff
changeset
|
524 |
|
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
372
diff
changeset
|
525 |
context = {"user": user, |
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
372
diff
changeset
|
526 |
"profile": profile, |
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
372
diff
changeset
|
527 |
"textbook": textbook, |
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
372
diff
changeset
|
528 |
} |
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
372
diff
changeset
|
529 |
|
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
372
diff
changeset
|
530 |
context.update(csrf(request)) |
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
372
diff
changeset
|
531 |
|
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
372
diff
changeset
|
532 |
if request.method == "POST": |
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
533 |
form = taskapp_forms.EditTextbookForm(request.POST, instance=textbook) |
373
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
372
diff
changeset
|
534 |
if form.is_valid(): |
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
372
diff
changeset
|
535 |
form.save() |
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
536 |
return shortcuts.redirect(textbook_url) |
373
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
372
diff
changeset
|
537 |
else: |
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
372
diff
changeset
|
538 |
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
|
539 |
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
|
540 |
"task/edit.html", RequestContext(request, context)) |
373
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
372
diff
changeset
|
541 |
else: |
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
542 |
form = taskapp_forms.EditTextbookForm(instance=textbook) |
373
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
372
diff
changeset
|
543 |
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
|
544 |
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
|
545 |
RequestContext(request, context)) |
373
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
372
diff
changeset
|
546 |
|
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
372
diff
changeset
|
547 |
@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
|
548 |
def claim_task(request, task_id): |
353
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
549 |
|
430
a11a778fca54
Use reverse function instead of hard coded URL.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
429
diff
changeset
|
550 |
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
|
551 |
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
|
552 |
|
440
56ea209e559f
Use the right form of names to be stored in the database.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
430
diff
changeset
|
553 |
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
|
554 |
raise http.Http404 |
353
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
555 |
|
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
556 |
user = request.user |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
557 |
profile = user.get_profile() |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
558 |
|
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
559 |
context = {"user": user, |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
560 |
"profile": profile, |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
561 |
"task": task, |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
562 |
} |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
563 |
|
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
564 |
context.update(csrf(request)) |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
565 |
|
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
566 |
reviewers = task.reviewers.all() |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
567 |
claimed_users = task.claimed_users.all() |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
568 |
|
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
569 |
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
|
570 |
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
|
571 |
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
|
572 |
|
440
56ea209e559f
Use the right form of names to be stored in the database.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
430
diff
changeset
|
573 |
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
|
574 |
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
|
575 |
and ( not is_reviewer ) and (not is_creator ) \ |
ec7f2f4256f5
now the creator can select users
Nishanth Amuluru <nishanth@fossee.in>
parents:
356
diff
changeset
|
576 |
else False |
353
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
577 |
|
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
578 |
old_claims = task.claims.all() |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
579 |
|
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
580 |
context.update({"is_creator": is_creator, |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
581 |
"task_claimable": task_claimable, |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
582 |
"can_claim": can_claim, |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
583 |
"old_claims": old_claims}) |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
584 |
|
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
585 |
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
|
586 |
form = taskapp_forms.ClaimTaskForm(request.POST) |
353
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
587 |
if form.is_valid(): |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
588 |
data = form.cleaned_data.copy() |
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
589 |
data.update({"task": task, |
353
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
590 |
"claim_datetime": datetime.now(), |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
591 |
"claimed_by": user,}) |
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
592 |
new_claim = taskapp_models.TaskClaim(**data) |
353
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
593 |
new_claim.save() |
355
c693def6510f
added the step of adding user to claimed users
Nishanth Amuluru <nishanth@fossee.in>
parents:
353
diff
changeset
|
594 |
|
c693def6510f
added the step of adding user to claimed users
Nishanth Amuluru <nishanth@fossee.in>
parents:
353
diff
changeset
|
595 |
task.claimed_users.add(user) |
c693def6510f
added the step of adding user to claimed users
Nishanth Amuluru <nishanth@fossee.in>
parents:
353
diff
changeset
|
596 |
task.save() |
c693def6510f
added the step of adding user to claimed users
Nishanth Amuluru <nishanth@fossee.in>
parents:
353
diff
changeset
|
597 |
|
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
598 |
return shortcuts.redirect(claim_url) |
353
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
599 |
|
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
600 |
else: |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
601 |
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
|
602 |
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
|
603 |
"task/claim.html", RequestContext(request, context)) |
353
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
604 |
else: |
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
605 |
form = taskapp_forms.ClaimTaskForm() |
353
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
606 |
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
|
607 |
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
|
608 |
"task/claim.html", RequestContext(request, context)) |
353
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
609 |
|
360 | 610 |
@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
|
611 |
def select_user(request, task_id): |
360 | 612 |
""" first get the status of the task and then select one of claimed users |
613 |
generate list of claimed users by passing it as an argument to a function. |
|
614 |
""" |
|
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
|
615 |
|
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
|
616 |
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
|
617 |
|
360 | 618 |
user = request.user |
619 |
profile = user.get_profile() |
|
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
620 |
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
|
621 |
|
360 | 622 |
context = {"user": user, |
623 |
"profile": profile, |
|
624 |
"task": task, |
|
625 |
} |
|
353
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
350
diff
changeset
|
626 |
|
360 | 627 |
context.update(csrf(request)) |
628 |
||
629 |
claimed_users = task.claimed_users.all() |
|
362
070f01dd7d8e
Select user works completely fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
360
diff
changeset
|
630 |
task_claimed = True if claimed_users else False |
360 | 631 |
|
632 |
is_creator = True if user == task.created_by else False |
|
633 |
||
443
a13ea00c1a3f
Use the correct choices variable for the role and status.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
440
diff
changeset
|
634 |
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
|
635 |
task.status in [taskapp_models.TASK_STATUS_CHOICES[1][0], taskapp_models.TASK_STATUS_CHOICES[3][0]]: |
360 | 636 |
|
362
070f01dd7d8e
Select user works completely fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
360
diff
changeset
|
637 |
if task_claimed: |
360 | 638 |
|
639 |
user_list = ((user.id,user.username) for user in claimed_users) |
|
640 |
||
641 |
if request.method == "POST": |
|
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
642 |
form = taskapp_forms.ChoiceForm(user_list, request.POST) |
360 | 643 |
if form.is_valid(): |
644 |
uid = form.cleaned_data['choice'] |
|
645 |
selected_user = User.objects.get(id=uid) |
|
646 |
||
362
070f01dd7d8e
Select user works completely fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
360
diff
changeset
|
647 |
task.selected_users.add(selected_user) |
070f01dd7d8e
Select user works completely fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
360
diff
changeset
|
648 |
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
|
649 |
task.status = taskapp_models.TASK_STATUS_CHOICES[3][0] |
360 | 650 |
task.save() |
651 |
||
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
652 |
return shortcuts.redirect(task_url) |
360 | 653 |
else: |
654 |
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
|
655 |
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
|
656 |
'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
|
657 |
RequestContext(request, context)) |
360 | 658 |
else: |
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
659 |
form = taskapp_forms.ChoiceForm(user_list) |
360 | 660 |
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
|
661 |
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
|
662 |
'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
|
663 |
RequestContext(request, context)) |
360 | 664 |
else: |
665 |
return show_msg(user, 'There are no pending claims for this task', |
|
666 |
task_url, 'view the task') |
|
667 |
else: |
|
425
e15749fab2e4
Restructured create form to use templatetags and use Javascript for autcomplete.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
422
diff
changeset
|
668 |
raise http.Http404 |
360 | 669 |
|
380
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
377
diff
changeset
|
670 |
@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
|
671 |
def approve_textbook(request, task_id): |
380
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
377
diff
changeset
|
672 |
|
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
377
diff
changeset
|
673 |
user = request.user |
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
377
diff
changeset
|
674 |
profile = user.get_profile() |
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
377
diff
changeset
|
675 |
|
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
676 |
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
|
677 |
|
443
a13ea00c1a3f
Use the correct choices variable for the role and status.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
440
diff
changeset
|
678 |
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
|
679 |
raise http.Http404 |
380
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
377
diff
changeset
|
680 |
|
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
377
diff
changeset
|
681 |
context = {"user": user, |
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
377
diff
changeset
|
682 |
"profile": profile, |
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
377
diff
changeset
|
683 |
"textbook": textbook, |
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
377
diff
changeset
|
684 |
} |
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
377
diff
changeset
|
685 |
|
451
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
686 |
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
|
687 |
"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
|
688 |
RequestContext(request, context)) |
380
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
377
diff
changeset
|
689 |
|
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
377
diff
changeset
|
690 |
@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
|
691 |
def approved_textbook(request, task_id): |
380
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
377
diff
changeset
|
692 |
|
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
377
diff
changeset
|
693 |
user = request.user |
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
377
diff
changeset
|
694 |
profile = user.get_profile() |
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
377
diff
changeset
|
695 |
|
422
4bb891fc7a54
Change imports to be more readable.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
408
diff
changeset
|
696 |
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
|
697 |
|
443
a13ea00c1a3f
Use the correct choices variable for the role and status.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
440
diff
changeset
|
698 |
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
|
699 |
raise http.Http404 |
380
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
377
diff
changeset
|
700 |
|
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
377
diff
changeset
|
701 |
textbook.approved_by = user |
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
377
diff
changeset
|
702 |
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
|
703 |
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
|
704 |
textbook.save() |
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
377
diff
changeset
|
705 |
|
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
377
diff
changeset
|
706 |
context = {"user": user, |
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
377
diff
changeset
|
707 |
"profile": profile, |
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
377
diff
changeset
|
708 |
"textbook": textbook, |
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
377
diff
changeset
|
709 |
} |
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
377
diff
changeset
|
710 |
|
451
09a1ee04a3f4
Replace all occurences of context with RequestContext in taskapp views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
443
diff
changeset
|
711 |
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
|
712 |
"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
|
713 |
|
e15749fab2e4
Restructured create form to use templatetags and use Javascript for autcomplete.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
422
diff
changeset
|
714 |
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
|
715 |
"""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
|
716 |
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
|
717 |
""" |
e15749fab2e4
Restructured create form to use templatetags and use Javascript for autcomplete.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
422
diff
changeset
|
718 |
|
427
42156890006d
Move all the content from create form to edit form for tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
425
diff
changeset
|
719 |
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
|
720 |
response = [] |
42156890006d
Move all the content from create form to edit form for tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
425
diff
changeset
|
721 |
|
42156890006d
Move all the content from create form to edit form for tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
425
diff
changeset
|
722 |
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
|
723 |
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
|
724 |
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
|
725 |
|
42156890006d
Move all the content from create form to edit form for tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
425
diff
changeset
|
726 |
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
|
727 |
return http.HttpResponse(json_response) |