author | Nishanth Amuluru <nishanth@fossee.in> |
Tue, 11 Jan 2011 16:51:07 +0530 | |
changeset 144 | daca865314e7 |
parent 143 | da4c6b1cec7d |
child 145 | 4252da60a4ef |
permissions | -rwxr-xr-x |
95
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
1 |
from datetime import datetime |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
2 |
|
124
070f01dd7d8e
Select user works completely fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
122
diff
changeset
|
3 |
from django.contrib.auth.models import User |
070f01dd7d8e
Select user works completely fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
122
diff
changeset
|
4 |
|
95
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
5 |
from django.shortcuts import render_to_response, redirect |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
6 |
from django.http import Http404 |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
7 |
|
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
8 |
from django.contrib.auth.decorators import login_required |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
9 |
from django.core.context_processors import csrf |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
10 |
from django.views.decorators.csrf import csrf_protect |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
11 |
|
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
12 |
from pytask.utils import make_key |
101
bce480ff6ddc
used proper import for show_msg
Nishanth Amuluru <nishanth@fossee.in>
parents:
95
diff
changeset
|
13 |
from pytask.views import show_msg |
95
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
14 |
|
130
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
128
diff
changeset
|
15 |
from pytask.taskapp.models import Task, TaskComment, TaskClaim, TextBook |
124
070f01dd7d8e
Select user works completely fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
122
diff
changeset
|
16 |
from pytask.taskapp.forms import CreateTaskForm, EditTaskForm, \ |
070f01dd7d8e
Select user works completely fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
122
diff
changeset
|
17 |
TaskCommentForm, ClaimTaskForm, \ |
135
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
134
diff
changeset
|
18 |
ChoiceForm, EditTaskForm, CreateTextbookForm,\ |
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
134
diff
changeset
|
19 |
EditTextbookForm |
132
1be4a3c09a47
view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
130
diff
changeset
|
20 |
from pytask.taskapp.utils import getTask, getTextBook |
95
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
21 |
from pytask.profile.utils import get_notification |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
22 |
|
101
bce480ff6ddc
used proper import for show_msg
Nishanth Amuluru <nishanth@fossee.in>
parents:
95
diff
changeset
|
23 |
|
95
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
24 |
@login_required |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
25 |
def create_task(request): |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
26 |
|
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
27 |
user = request.user |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
28 |
profile = user.get_profile() |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
29 |
|
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
30 |
context = {"user": user, |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
31 |
"profile": profile, |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
32 |
} |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
33 |
|
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
34 |
context.update(csrf(request)) |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
35 |
|
102 | 36 |
can_create_task = False if profile.rights == "CT" else True |
95
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
37 |
if can_create_task: |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
38 |
if request.method == "POST": |
102 | 39 |
form = CreateTaskForm(request.POST) |
95
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
40 |
if form.is_valid(): |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
41 |
data = form.cleaned_data.copy() |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
42 |
data.update({"created_by": user, |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
43 |
"creation_datetime": datetime.now(), |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
44 |
"uniq_key": make_key(Task), |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
45 |
}) |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
46 |
|
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
47 |
task = Task(**data) |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
48 |
task.save() |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
49 |
|
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
50 |
task_url = '/task/view/tid=%s'%task.uniq_key |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
51 |
return redirect(task_url) |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
52 |
else: |
102 | 53 |
context.update({'form':form}) |
54 |
return render_to_response('task/create.html', context) |
|
95
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
55 |
else: |
102 | 56 |
form = CreateTaskForm() |
57 |
context.update({'form':form}) |
|
58 |
return render_to_response('task/create.html', context) |
|
95
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
59 |
else: |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
60 |
return show_msg(user, 'You are not authorised to create a task.') |
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:
102
diff
changeset
|
61 |
|
138
5a94c774473c
browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
136
diff
changeset
|
62 |
def browse_tasks(request): |
5a94c774473c
browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
136
diff
changeset
|
63 |
|
5a94c774473c
browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
136
diff
changeset
|
64 |
open_tasks = Task.objects.filter(status="OP") |
5a94c774473c
browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
136
diff
changeset
|
65 |
working_tasks = Task.objects.filter(status="WR") |
5a94c774473c
browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
136
diff
changeset
|
66 |
comp_tasks = Task.objects.filter(status="CM") |
5a94c774473c
browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
136
diff
changeset
|
67 |
|
5a94c774473c
browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
136
diff
changeset
|
68 |
context = {"open_tasks": open_tasks, |
5a94c774473c
browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
136
diff
changeset
|
69 |
"working_tasks": working_tasks, |
5a94c774473c
browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
136
diff
changeset
|
70 |
"comp_tasks": comp_tasks, |
5a94c774473c
browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
136
diff
changeset
|
71 |
} |
5a94c774473c
browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
136
diff
changeset
|
72 |
|
5a94c774473c
browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
136
diff
changeset
|
73 |
user = request.user |
5a94c774473c
browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
136
diff
changeset
|
74 |
if not user.is_authenticated(): |
5a94c774473c
browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
136
diff
changeset
|
75 |
return render_to_response("task/browse.html") |
5a94c774473c
browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
136
diff
changeset
|
76 |
|
5a94c774473c
browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
136
diff
changeset
|
77 |
profile = user.get_profile() |
5a94c774473c
browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
136
diff
changeset
|
78 |
|
5a94c774473c
browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
136
diff
changeset
|
79 |
can_approve = True if profile.rights in ["MG", "DC"] else False |
5a94c774473c
browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
136
diff
changeset
|
80 |
unpub_tasks = Task.objects.filter(status="UP").exclude(status="DL") |
5a94c774473c
browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
136
diff
changeset
|
81 |
if can_approve: |
5a94c774473c
browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
136
diff
changeset
|
82 |
context.update({"unpub_tasks": unpub_tasks}) |
5a94c774473c
browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
136
diff
changeset
|
83 |
|
5a94c774473c
browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
136
diff
changeset
|
84 |
context.update({"user": user, |
5a94c774473c
browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
136
diff
changeset
|
85 |
"profile": profile, |
5a94c774473c
browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
136
diff
changeset
|
86 |
}) |
5a94c774473c
browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
136
diff
changeset
|
87 |
|
5a94c774473c
browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
136
diff
changeset
|
88 |
return render_to_response("task/browse.html", context) |
5a94c774473c
browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
136
diff
changeset
|
89 |
|
5a94c774473c
browse tasks works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
136
diff
changeset
|
90 |
|
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:
102
diff
changeset
|
91 |
def view_task(request, tid): |
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:
102
diff
changeset
|
92 |
""" get the task depending on its tid and display accordingly if it is a get. |
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:
102
diff
changeset
|
93 |
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:
102
diff
changeset
|
94 |
""" |
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:
102
diff
changeset
|
95 |
|
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:
102
diff
changeset
|
96 |
task_url = "/task/view/tid=%s"%tid |
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:
102
diff
changeset
|
97 |
task = getTask(tid) |
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:
102
diff
changeset
|
98 |
|
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:
102
diff
changeset
|
99 |
user = request.user |
112
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
111
diff
changeset
|
100 |
|
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
111
diff
changeset
|
101 |
if not user.is_authenticated(): |
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
111
diff
changeset
|
102 |
return render_to_response("/task/view.html", {"task": task}) |
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
111
diff
changeset
|
103 |
|
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:
102
diff
changeset
|
104 |
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:
102
diff
changeset
|
105 |
|
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:
102
diff
changeset
|
106 |
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:
102
diff
changeset
|
107 |
"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:
102
diff
changeset
|
108 |
"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:
102
diff
changeset
|
109 |
} |
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:
102
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:
102
diff
changeset
|
111 |
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:
102
diff
changeset
|
112 |
|
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:
102
diff
changeset
|
113 |
if task.status == "DL": |
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:
102
diff
changeset
|
114 |
return show_msg(user, 'This task no longer exists', '/task/browse/','browse the tasks') |
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:
102
diff
changeset
|
115 |
|
112
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
111
diff
changeset
|
116 |
task_viewable = True if ( task.status != "UP" ) or profile.rights != "CT"\ |
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
111
diff
changeset
|
117 |
else False |
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
111
diff
changeset
|
118 |
if not task_viewable: |
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
111
diff
changeset
|
119 |
return show_msg(user, "You are not authorised to view this task", "/task/browse/", "browse the tasks") |
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:
102
diff
changeset
|
120 |
|
112
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
111
diff
changeset
|
121 |
reviewers = task.reviewers.all() |
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:
102
diff
changeset
|
122 |
is_reviewer = True if user in task.reviewers.all() else False |
112
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
111
diff
changeset
|
123 |
comments = task.comments.filter(is_deleted=False).order_by('comment_datetime') |
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:
102
diff
changeset
|
124 |
|
112
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
111
diff
changeset
|
125 |
context.update({'is_reviewer':is_reviewer, |
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:
102
diff
changeset
|
126 |
'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:
102
diff
changeset
|
127 |
'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:
102
diff
changeset
|
128 |
}) |
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:
102
diff
changeset
|
129 |
|
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:
102
diff
changeset
|
130 |
claimed_users = task.claimed_users.all() |
112
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
111
diff
changeset
|
131 |
selected_users = task.selected_users.all() |
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:
102
diff
changeset
|
132 |
|
112
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
111
diff
changeset
|
133 |
is_creator = True if user == task.created_by else False |
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
111
diff
changeset
|
134 |
has_claimed = True if user in claimed_users else False |
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:
102
diff
changeset
|
135 |
|
127
32457bce3437
prettified a few pages
Nishanth Amuluru <nishanth@fossee.in>
parents:
125
diff
changeset
|
136 |
context['selected_users'] = selected_users |
112
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
111
diff
changeset
|
137 |
context['is_selected'] = True if user in selected_users else False |
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
111
diff
changeset
|
138 |
context['can_approve'] = True if task.status == "UP" and\ |
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
111
diff
changeset
|
139 |
profile.rights in ["MG", "DC"]\ |
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
111
diff
changeset
|
140 |
else False |
128 | 141 |
context['can_edit'] = True if is_creator and task.status == "UP" else False |
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:
102
diff
changeset
|
142 |
context['can_close'] = True if task.status not in ["UP", "CD", "CM"] and is_reviewer else False |
112
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
111
diff
changeset
|
143 |
context['can_delete'] = True if task.status == "UP" and is_creator else False |
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:
102
diff
changeset
|
144 |
|
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:
102
diff
changeset
|
145 |
context['can_assign_pynts'] = True if task.status in ["OP", "WR"] and is_reviewer else False |
112
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
111
diff
changeset
|
146 |
context['task_claimable'] = True if task.status in ["OP", "WR"] else False |
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
111
diff
changeset
|
147 |
|
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
111
diff
changeset
|
148 |
context['can_comment'] = True if task.status != "UP" or\ |
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
111
diff
changeset
|
149 |
profile.rights!="CT" else False |
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:
102
diff
changeset
|
150 |
|
143
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
142
diff
changeset
|
151 |
context['can_mod_reviewers'] = True if profile.rights in ["MG", "DC"] else\ |
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
142
diff
changeset
|
152 |
False |
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
142
diff
changeset
|
153 |
|
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:
102
diff
changeset
|
154 |
# if task.status == "CD": |
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:
102
diff
changeset
|
155 |
# context['closing_notification'] = Notification.objects.filter(task=task,role="CD")[0] |
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:
102
diff
changeset
|
156 |
# elif task.status == "CM": |
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:
102
diff
changeset
|
157 |
# context['completed_notification'] = Notifications.objects.filter(task=task,role="CM")[0] |
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:
102
diff
changeset
|
158 |
# elif task.status == "WR": |
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:
102
diff
changeset
|
159 |
# context['assigned_users'] = task.assigned_users.all() |
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:
102
diff
changeset
|
160 |
|
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:
102
diff
changeset
|
161 |
if request.method == 'POST': |
112
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
111
diff
changeset
|
162 |
form = TaskCommentForm(request.POST) |
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
111
diff
changeset
|
163 |
if form.is_valid(): |
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
111
diff
changeset
|
164 |
data = form.cleaned_data['data'] |
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
111
diff
changeset
|
165 |
new_comment = TaskComment(task=task, data=data, |
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
111
diff
changeset
|
166 |
uniq_key=make_key(TaskComment), |
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
111
diff
changeset
|
167 |
commented_by=user, comment_datetime=datetime.now()) |
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
111
diff
changeset
|
168 |
new_comment.save() |
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
111
diff
changeset
|
169 |
return redirect(task_url) |
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:
102
diff
changeset
|
170 |
else: |
112
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
111
diff
changeset
|
171 |
context['form'] = form |
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
111
diff
changeset
|
172 |
return render_to_response('task/view.html', context) |
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:
102
diff
changeset
|
173 |
else: |
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:
102
diff
changeset
|
174 |
form = TaskCommentForm() |
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:
102
diff
changeset
|
175 |
context['form'] = form |
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:
102
diff
changeset
|
176 |
return render_to_response('task/view.html', context) |
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:
102
diff
changeset
|
177 |
|
115
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
178 |
@login_required |
128 | 179 |
def edit_task(request, tid): |
180 |
""" only creator gets to edit the task and that too only before it gets |
|
181 |
approved. |
|
182 |
""" |
|
183 |
||
184 |
user = request.user |
|
185 |
profile = user.get_profile() |
|
186 |
||
187 |
task_url = "/task/view/tid=%s"%tid |
|
188 |
task = getTask(tid) |
|
189 |
||
190 |
is_creator = True if user == task.created_by else False |
|
191 |
can_edit = True if task.status == "UP" and is_creator else False |
|
192 |
if not can_edit: |
|
193 |
raise Http404 |
|
194 |
||
195 |
context = {"user": user, |
|
196 |
"profile": profile, |
|
197 |
"task": task, |
|
198 |
} |
|
199 |
||
200 |
context.update(csrf(request)) |
|
201 |
||
202 |
if request.method == "POST": |
|
203 |
form = EditTaskForm(request.POST, instance=task) |
|
204 |
if form.is_valid(): |
|
205 |
form.save() |
|
206 |
return redirect(task_url) |
|
207 |
else: |
|
208 |
context.update({"form": form}) |
|
209 |
return render_to_response("task/edit.html", context) |
|
210 |
else: |
|
211 |
form = EditTaskForm(instance=task) |
|
212 |
context.update({"form": form}) |
|
213 |
return render_to_response("task/edit.html", context) |
|
214 |
||
130
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
128
diff
changeset
|
215 |
@login_required |
136
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
135
diff
changeset
|
216 |
def approve_task(request, tid): |
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
135
diff
changeset
|
217 |
|
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
135
diff
changeset
|
218 |
user = request.user |
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
135
diff
changeset
|
219 |
profile = user.get_profile() |
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
135
diff
changeset
|
220 |
|
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
135
diff
changeset
|
221 |
task_url = "/task/view/tid=%s"%tid |
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
135
diff
changeset
|
222 |
task = getTask(tid) |
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
135
diff
changeset
|
223 |
|
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
135
diff
changeset
|
224 |
if profile.rights not in ["MG", "DC"] or task.status != "UP": |
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
135
diff
changeset
|
225 |
raise Http404 |
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
135
diff
changeset
|
226 |
|
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
135
diff
changeset
|
227 |
context = {"user": user, |
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
135
diff
changeset
|
228 |
"profile": profile, |
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
135
diff
changeset
|
229 |
"task": task, |
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
135
diff
changeset
|
230 |
} |
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
135
diff
changeset
|
231 |
|
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
135
diff
changeset
|
232 |
return render_to_response("task/confirm_approval.html", context) |
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
135
diff
changeset
|
233 |
|
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
135
diff
changeset
|
234 |
@login_required |
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
135
diff
changeset
|
235 |
def approved_task(request, tid): |
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
135
diff
changeset
|
236 |
|
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
135
diff
changeset
|
237 |
user = request.user |
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
135
diff
changeset
|
238 |
profile = user.get_profile() |
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
135
diff
changeset
|
239 |
|
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
135
diff
changeset
|
240 |
task_url = "/task/view/tid=%s"%tid |
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
135
diff
changeset
|
241 |
task = getTask(tid) |
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
135
diff
changeset
|
242 |
|
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
135
diff
changeset
|
243 |
if profile.rights not in ["MG", "DC"] or task.status != "UP": |
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
135
diff
changeset
|
244 |
raise Http404 |
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
135
diff
changeset
|
245 |
|
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
135
diff
changeset
|
246 |
task.approved_by = user |
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
135
diff
changeset
|
247 |
task.approval_datetime = datetime.now() |
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
135
diff
changeset
|
248 |
task.status = "OP" |
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
135
diff
changeset
|
249 |
task.save() |
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
135
diff
changeset
|
250 |
|
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
135
diff
changeset
|
251 |
context = {"user": user, |
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
135
diff
changeset
|
252 |
"profile": profile, |
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
135
diff
changeset
|
253 |
"task": task, |
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
135
diff
changeset
|
254 |
} |
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
135
diff
changeset
|
255 |
|
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
135
diff
changeset
|
256 |
return render_to_response("task/approved_task.html", context) |
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
135
diff
changeset
|
257 |
|
cdd8026ee60e
task approval is fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
135
diff
changeset
|
258 |
@login_required |
143
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
142
diff
changeset
|
259 |
def addreviewer(request, tid): |
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
142
diff
changeset
|
260 |
|
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
142
diff
changeset
|
261 |
user = request.user |
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
142
diff
changeset
|
262 |
profile = user.get_profile() |
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
142
diff
changeset
|
263 |
|
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
142
diff
changeset
|
264 |
task_url = "/task/view/tid=%s"%tid |
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
142
diff
changeset
|
265 |
task = getTask(tid) |
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
142
diff
changeset
|
266 |
|
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
142
diff
changeset
|
267 |
can_mod_reviewers = True if profile.rights in ["MG", "DC"] else False |
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
142
diff
changeset
|
268 |
if not can_mod_reviewers: |
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
142
diff
changeset
|
269 |
raise Http404 |
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
142
diff
changeset
|
270 |
|
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
142
diff
changeset
|
271 |
context = {"user": user, |
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
142
diff
changeset
|
272 |
"profile": profile, |
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
142
diff
changeset
|
273 |
"task": task, |
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
142
diff
changeset
|
274 |
} |
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
142
diff
changeset
|
275 |
|
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
142
diff
changeset
|
276 |
context.update(csrf(request)) |
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
142
diff
changeset
|
277 |
|
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
142
diff
changeset
|
278 |
|
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
142
diff
changeset
|
279 |
# This part has to be made better |
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
142
diff
changeset
|
280 |
reviewer_choices = User.objects.filter(is_active=True).\ |
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
142
diff
changeset
|
281 |
exclude(reviewing_tasks__uniq_key=tid).\ |
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
142
diff
changeset
|
282 |
exclude(claimed_tasks__uniq_key=tid).\ |
144
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
143
diff
changeset
|
283 |
exclude(selected_tasks__uniq_key=tid).\ |
143
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
142
diff
changeset
|
284 |
exclude(created_tasks__uniq_key=tid) |
144
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
143
diff
changeset
|
285 |
|
143
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
142
diff
changeset
|
286 |
choices = ((a_user.id,a_user.username) for a_user in reviewer_choices) |
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
142
diff
changeset
|
287 |
label = "Reviewer" |
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
142
diff
changeset
|
288 |
|
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
142
diff
changeset
|
289 |
if request.method == "POST": |
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
142
diff
changeset
|
290 |
form = ChoiceForm(choices, data=request.POST, label=label) |
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
142
diff
changeset
|
291 |
if form.is_valid(): |
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
142
diff
changeset
|
292 |
data = form.cleaned_data.copy() |
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
142
diff
changeset
|
293 |
uid = data['choice'] |
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
142
diff
changeset
|
294 |
reviewer = User.objects.get(id=uid) |
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
142
diff
changeset
|
295 |
|
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
142
diff
changeset
|
296 |
task.reviewers.add(reviewer) |
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
142
diff
changeset
|
297 |
return redirect(task_url) |
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
142
diff
changeset
|
298 |
else: |
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
142
diff
changeset
|
299 |
context.update({"form": form}) |
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
142
diff
changeset
|
300 |
return render_to_response("task/addreviewer.html", context) |
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
142
diff
changeset
|
301 |
else: |
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
142
diff
changeset
|
302 |
form = ChoiceForm(choices, label=label) |
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
142
diff
changeset
|
303 |
context.update({"form": form}) |
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
142
diff
changeset
|
304 |
return render_to_response("task/addreviewer.html", context) |
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
142
diff
changeset
|
305 |
|
144
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
143
diff
changeset
|
306 |
def view_work(request, tid): |
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
143
diff
changeset
|
307 |
|
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
143
diff
changeset
|
308 |
task_url = "/task/view/tid=%s"%tid |
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
143
diff
changeset
|
309 |
task = getTask(tid) |
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
143
diff
changeset
|
310 |
|
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
143
diff
changeset
|
311 |
user = request.user |
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
143
diff
changeset
|
312 |
old_reports = task.reports.all() |
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
143
diff
changeset
|
313 |
|
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
143
diff
changeset
|
314 |
context = {"task": task, |
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
143
diff
changeset
|
315 |
"old_reports": old_reports, |
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
143
diff
changeset
|
316 |
} |
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
143
diff
changeset
|
317 |
|
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
143
diff
changeset
|
318 |
if not user.is_authenticated(): |
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
143
diff
changeset
|
319 |
return render_to_response("/task/view_work.html", context) |
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
143
diff
changeset
|
320 |
|
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
143
diff
changeset
|
321 |
profile = user.get_profile() |
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
143
diff
changeset
|
322 |
|
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
143
diff
changeset
|
323 |
context.update({"user": user, |
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
143
diff
changeset
|
324 |
"profile": profile, |
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
143
diff
changeset
|
325 |
}) |
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
143
diff
changeset
|
326 |
|
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
143
diff
changeset
|
327 |
context.update(csrf(request)) |
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
143
diff
changeset
|
328 |
|
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
143
diff
changeset
|
329 |
working_users = task.selected_users.all() |
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
143
diff
changeset
|
330 |
is_working = True if user in working_users else False |
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
143
diff
changeset
|
331 |
|
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
143
diff
changeset
|
332 |
context.update({"is_working": is_working}) |
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
143
diff
changeset
|
333 |
|
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
143
diff
changeset
|
334 |
return render_to_response("task/view_work.html", context) |
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
143
diff
changeset
|
335 |
|
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
143
diff
changeset
|
336 |
@login_required |
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
143
diff
changeset
|
337 |
def view_report(request, rid): |
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
143
diff
changeset
|
338 |
pass |
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
143
diff
changeset
|
339 |
|
daca865314e7
view_work is now working
Nishanth Amuluru <nishanth@fossee.in>
parents:
143
diff
changeset
|
340 |
|
143
da4c6b1cec7d
add reviewer works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
142
diff
changeset
|
341 |
@login_required |
130
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
128
diff
changeset
|
342 |
def create_textbook(request): |
128 | 343 |
|
130
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
128
diff
changeset
|
344 |
user = request.user |
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
128
diff
changeset
|
345 |
profile = user.get_profile() |
128 | 346 |
|
130
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
128
diff
changeset
|
347 |
can_create = True if profile.rights != "CT" else False |
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
128
diff
changeset
|
348 |
if not can_create: |
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
128
diff
changeset
|
349 |
raise Http404 |
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
128
diff
changeset
|
350 |
|
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
128
diff
changeset
|
351 |
context = {"user": user, |
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
128
diff
changeset
|
352 |
"profile": profile, |
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
128
diff
changeset
|
353 |
} |
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
128
diff
changeset
|
354 |
|
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
128
diff
changeset
|
355 |
context.update(csrf(request)) |
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
128
diff
changeset
|
356 |
|
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
128
diff
changeset
|
357 |
if request.method == "POST": |
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
128
diff
changeset
|
358 |
form = CreateTextbookForm(request.POST) |
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
128
diff
changeset
|
359 |
if form.is_valid(): |
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
128
diff
changeset
|
360 |
data = form.cleaned_data.copy() |
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
128
diff
changeset
|
361 |
data.update({"uniq_key": make_key(TextBook), |
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
128
diff
changeset
|
362 |
"created_by": user, |
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
128
diff
changeset
|
363 |
"creation_datetime": datetime.now()}) |
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
128
diff
changeset
|
364 |
del data['chapters'] |
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
128
diff
changeset
|
365 |
new_textbook = TextBook(**data) |
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
128
diff
changeset
|
366 |
new_textbook.save() |
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
128
diff
changeset
|
367 |
|
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
128
diff
changeset
|
368 |
new_textbook.chapters = form.cleaned_data['chapters'] |
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
128
diff
changeset
|
369 |
|
132
1be4a3c09a47
view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
130
diff
changeset
|
370 |
textbook_url = "/task/textbook/view/tid=%s"%new_textbook.uniq_key |
130
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
128
diff
changeset
|
371 |
return redirect(textbook_url) |
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
128
diff
changeset
|
372 |
else: |
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
128
diff
changeset
|
373 |
context.update({"form": form}) |
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
128
diff
changeset
|
374 |
return render_to_response("task/create_textbook.html", context) |
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
128
diff
changeset
|
375 |
else: |
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
128
diff
changeset
|
376 |
form = CreateTextbookForm() |
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
128
diff
changeset
|
377 |
context.update({"form": form}) |
a4fa11b2cb5c
add textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
128
diff
changeset
|
378 |
return render_to_response("task/create_textbook.html", context) |
128 | 379 |
|
132
1be4a3c09a47
view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
130
diff
changeset
|
380 |
def view_textbook(request, tid): |
1be4a3c09a47
view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
130
diff
changeset
|
381 |
|
1be4a3c09a47
view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
130
diff
changeset
|
382 |
textbook = getTextBook(tid) |
1be4a3c09a47
view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
130
diff
changeset
|
383 |
textbook_url = "/task/textbook/view/tid=%s"%textbook.uniq_key |
1be4a3c09a47
view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
130
diff
changeset
|
384 |
|
1be4a3c09a47
view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
130
diff
changeset
|
385 |
user = request.user |
1be4a3c09a47
view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
130
diff
changeset
|
386 |
if not user.is_authenticated(): |
134
563fe356947d
created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents:
132
diff
changeset
|
387 |
return render_to_response("task/view_textbook.html", {"user": user}) |
132
1be4a3c09a47
view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
130
diff
changeset
|
388 |
|
1be4a3c09a47
view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
130
diff
changeset
|
389 |
profile = user.get_profile() |
1be4a3c09a47
view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
130
diff
changeset
|
390 |
|
1be4a3c09a47
view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
130
diff
changeset
|
391 |
context = {"user": user, |
1be4a3c09a47
view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
130
diff
changeset
|
392 |
"profile": profile, |
1be4a3c09a47
view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
130
diff
changeset
|
393 |
"textbook": textbook, |
1be4a3c09a47
view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
130
diff
changeset
|
394 |
} |
1be4a3c09a47
view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
130
diff
changeset
|
395 |
|
1be4a3c09a47
view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
130
diff
changeset
|
396 |
context.update(csrf(request)) |
1be4a3c09a47
view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
130
diff
changeset
|
397 |
|
1be4a3c09a47
view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
130
diff
changeset
|
398 |
chapters = Task.objects.filter(status="UP") |
1be4a3c09a47
view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
130
diff
changeset
|
399 |
|
1be4a3c09a47
view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
130
diff
changeset
|
400 |
can_edit = True if user == textbook.created_by and textbook.status == "UP"\ |
1be4a3c09a47
view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
130
diff
changeset
|
401 |
else False |
1be4a3c09a47
view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
130
diff
changeset
|
402 |
|
1be4a3c09a47
view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
130
diff
changeset
|
403 |
can_approve = True if profile.rights in ["MG", "DC"] and \ |
1be4a3c09a47
view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
130
diff
changeset
|
404 |
textbook.status == "UP" else False |
1be4a3c09a47
view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
130
diff
changeset
|
405 |
|
1be4a3c09a47
view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
130
diff
changeset
|
406 |
context.update({"chapters": chapters, |
1be4a3c09a47
view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
130
diff
changeset
|
407 |
"can_edit": can_edit, |
1be4a3c09a47
view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
130
diff
changeset
|
408 |
"can_approve": can_approve}) |
1be4a3c09a47
view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
130
diff
changeset
|
409 |
return render_to_response("task/view_textbook.html", context) |
1be4a3c09a47
view textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
130
diff
changeset
|
410 |
|
134
563fe356947d
created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents:
132
diff
changeset
|
411 |
def browse_textbooks(request): |
563fe356947d
created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents:
132
diff
changeset
|
412 |
|
563fe356947d
created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents:
132
diff
changeset
|
413 |
user = request.user |
563fe356947d
created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents:
132
diff
changeset
|
414 |
|
563fe356947d
created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents:
132
diff
changeset
|
415 |
open_textbooks = TextBook.objects.filter(status="OP").\ |
563fe356947d
created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents:
132
diff
changeset
|
416 |
order_by("creation_datetime") |
563fe356947d
created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents:
132
diff
changeset
|
417 |
comp_textbooks = TextBook.objects.filter(status="CM").\ |
563fe356947d
created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents:
132
diff
changeset
|
418 |
order_by("creation_datetime") |
563fe356947d
created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents:
132
diff
changeset
|
419 |
context = {"user": user, |
563fe356947d
created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents:
132
diff
changeset
|
420 |
"open_textbooks": open_textbooks, |
563fe356947d
created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents:
132
diff
changeset
|
421 |
"comp_textbooks": comp_textbooks, |
563fe356947d
created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents:
132
diff
changeset
|
422 |
} |
563fe356947d
created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents:
132
diff
changeset
|
423 |
|
139
4f0cfd486d9b
approve text book is meaningful now
Nishanth Amuluru <nishanth@fossee.in>
parents:
138
diff
changeset
|
424 |
if user.is_authenticated() and user.get_profile().rights in ["DC", "MG"]: |
134
563fe356947d
created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents:
132
diff
changeset
|
425 |
unpub_textbooks = TextBook.objects.filter(status="UP") |
563fe356947d
created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents:
132
diff
changeset
|
426 |
|
563fe356947d
created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents:
132
diff
changeset
|
427 |
context.update({"unpub_textbooks": unpub_textbooks}) |
563fe356947d
created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents:
132
diff
changeset
|
428 |
|
563fe356947d
created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents:
132
diff
changeset
|
429 |
return render_to_response("task/browse_textbooks.html", context) |
563fe356947d
created browse textbooks page
Nishanth Amuluru <nishanth@fossee.in>
parents:
132
diff
changeset
|
430 |
|
128 | 431 |
@login_required |
135
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
134
diff
changeset
|
432 |
def edit_textbook(request, tid): |
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
134
diff
changeset
|
433 |
|
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
134
diff
changeset
|
434 |
user = request.user |
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
134
diff
changeset
|
435 |
profile = user.get_profile() |
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
134
diff
changeset
|
436 |
|
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
134
diff
changeset
|
437 |
textbook = getTextBook(tid) |
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
134
diff
changeset
|
438 |
textbook_url = "/task/textbook/view/tid=%s"%textbook.uniq_key |
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
134
diff
changeset
|
439 |
|
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
134
diff
changeset
|
440 |
can_edit = True if user == textbook.created_by and textbook.status == "UP"\ |
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
134
diff
changeset
|
441 |
else False |
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
134
diff
changeset
|
442 |
|
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
134
diff
changeset
|
443 |
if not can_edit: |
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
134
diff
changeset
|
444 |
raise Http404 |
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
134
diff
changeset
|
445 |
|
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
134
diff
changeset
|
446 |
context = {"user": user, |
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
134
diff
changeset
|
447 |
"profile": profile, |
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
134
diff
changeset
|
448 |
"textbook": textbook, |
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
134
diff
changeset
|
449 |
} |
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
134
diff
changeset
|
450 |
|
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
134
diff
changeset
|
451 |
context.update(csrf(request)) |
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
134
diff
changeset
|
452 |
|
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
134
diff
changeset
|
453 |
if request.method == "POST": |
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
134
diff
changeset
|
454 |
form = EditTextbookForm(request.POST, instance=textbook) |
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
134
diff
changeset
|
455 |
if form.is_valid(): |
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
134
diff
changeset
|
456 |
form.save() |
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
134
diff
changeset
|
457 |
return redirect(textbook_url) |
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
134
diff
changeset
|
458 |
else: |
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
134
diff
changeset
|
459 |
context.update({"form": form}) |
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
134
diff
changeset
|
460 |
return render_to_response("task/edit_textbook.html", context) |
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
134
diff
changeset
|
461 |
else: |
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
134
diff
changeset
|
462 |
form = EditTextbookForm(instance=textbook) |
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
134
diff
changeset
|
463 |
context.update({"form": form}) |
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
134
diff
changeset
|
464 |
return render_to_response("task/edit_textbook.html", context) |
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
134
diff
changeset
|
465 |
|
014d812e625e
edit textbook works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
134
diff
changeset
|
466 |
@login_required |
118
f88135529c74
claim task works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
117
diff
changeset
|
467 |
def claim_task(request, tid): |
115
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
468 |
|
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
469 |
task_url = "/task/view/tid=%s"%tid |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
470 |
claim_url = "/task/claim/tid=%s"%tid |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
471 |
task = getTask(tid) |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
472 |
|
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
473 |
if task.status == "UP": |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
474 |
raise Http404 |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
475 |
|
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
476 |
user = request.user |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
477 |
profile = user.get_profile() |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
478 |
|
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
479 |
context = {"user": user, |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
480 |
"profile": profile, |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
481 |
"task": task, |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
482 |
} |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
483 |
|
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
484 |
context.update(csrf(request)) |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
485 |
|
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
486 |
reviewers = task.reviewers.all() |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
487 |
claimed_users = task.claimed_users.all() |
118
f88135529c74
claim task works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
117
diff
changeset
|
488 |
selected_users = task.selected_users.all() |
115
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
489 |
|
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
490 |
is_creator = True if user == task.created_by else False |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
491 |
is_reviewer = True if user in reviewers else False |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
492 |
has_claimed = True if user in claimed_users else False |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
493 |
|
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
494 |
task_claimable = True if task.status in ["OP", "WR"] else False |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
495 |
can_claim = True if task_claimable and ( not has_claimed )\ |
119
ec7f2f4256f5
now the creator can select users
Nishanth Amuluru <nishanth@fossee.in>
parents:
118
diff
changeset
|
496 |
and ( not is_reviewer ) and (not is_creator ) \ |
ec7f2f4256f5
now the creator can select users
Nishanth Amuluru <nishanth@fossee.in>
parents:
118
diff
changeset
|
497 |
else False |
115
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
498 |
|
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
499 |
old_claims = task.claims.all() |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
500 |
|
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
501 |
context.update({"is_creator": is_creator, |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
502 |
"task_claimable": task_claimable, |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
503 |
"can_claim": can_claim, |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
504 |
"old_claims": old_claims}) |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
505 |
|
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
506 |
if request.method == "POST" and can_claim: |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
507 |
form = ClaimTaskForm(request.POST) |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
508 |
if form.is_valid(): |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
509 |
data = form.cleaned_data.copy() |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
510 |
data.update({"uniq_key": make_key(TaskClaim), |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
511 |
"task": task, |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
512 |
"claim_datetime": datetime.now(), |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
513 |
"claimed_by": user,}) |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
514 |
new_claim = TaskClaim(**data) |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
515 |
new_claim.save() |
117
c693def6510f
added the step of adding user to claimed users
Nishanth Amuluru <nishanth@fossee.in>
parents:
115
diff
changeset
|
516 |
|
c693def6510f
added the step of adding user to claimed users
Nishanth Amuluru <nishanth@fossee.in>
parents:
115
diff
changeset
|
517 |
task.claimed_users.add(user) |
c693def6510f
added the step of adding user to claimed users
Nishanth Amuluru <nishanth@fossee.in>
parents:
115
diff
changeset
|
518 |
task.save() |
c693def6510f
added the step of adding user to claimed users
Nishanth Amuluru <nishanth@fossee.in>
parents:
115
diff
changeset
|
519 |
|
115
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
520 |
return redirect(claim_url) |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
521 |
|
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
522 |
else: |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
523 |
context.update({"form": form}) |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
524 |
return render_to_response("task/claim.html", context) |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
525 |
else: |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
526 |
form = ClaimTaskForm() |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
527 |
context.update({"form": form}) |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
528 |
return render_to_response("task/claim.html", context) |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
529 |
|
122 | 530 |
@login_required |
531 |
def select_user(request, tid): |
|
532 |
""" first get the status of the task and then select one of claimed users |
|
533 |
generate list of claimed users by passing it as an argument to a function. |
|
534 |
""" |
|
535 |
||
536 |
task_url = "/task/view/tid=%s"%tid |
|
537 |
||
538 |
user = request.user |
|
539 |
profile = user.get_profile() |
|
540 |
task = getTask(tid) |
|
541 |
||
542 |
context = {"user": user, |
|
543 |
"profile": profile, |
|
544 |
"task": task, |
|
545 |
} |
|
115
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
546 |
|
122 | 547 |
context.update(csrf(request)) |
548 |
||
549 |
claimed_users = task.claimed_users.all() |
|
550 |
selected_users = task.selected_users.all() |
|
124
070f01dd7d8e
Select user works completely fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
122
diff
changeset
|
551 |
task_claimed = True if claimed_users else False |
122 | 552 |
|
553 |
is_creator = True if user == task.created_by else False |
|
554 |
||
555 |
if ( is_creator or profile.rights in ["CR", "DC"] ) and \ |
|
124
070f01dd7d8e
Select user works completely fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
122
diff
changeset
|
556 |
task.status in ["OP", "WR"]: |
122 | 557 |
|
124
070f01dd7d8e
Select user works completely fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
122
diff
changeset
|
558 |
if task_claimed: |
122 | 559 |
|
560 |
user_list = ((user.id,user.username) for user in claimed_users) |
|
561 |
||
562 |
if request.method == "POST": |
|
563 |
form = ChoiceForm(user_list, request.POST) |
|
564 |
if form.is_valid(): |
|
565 |
uid = form.cleaned_data['choice'] |
|
566 |
selected_user = User.objects.get(id=uid) |
|
567 |
||
124
070f01dd7d8e
Select user works completely fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
122
diff
changeset
|
568 |
task.selected_users.add(selected_user) |
070f01dd7d8e
Select user works completely fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
122
diff
changeset
|
569 |
task.claimed_users.remove(selected_user) |
125
9b0812962133
created the home page
Nishanth Amuluru <nishanth@fossee.in>
parents:
124
diff
changeset
|
570 |
task.status = "WR" |
122 | 571 |
task.save() |
572 |
||
573 |
return redirect(task_url) |
|
574 |
else: |
|
575 |
context.update({"form": form}) |
|
576 |
return render_to_response('task/select_user.html', context) |
|
577 |
else: |
|
578 |
form = ChoiceForm(user_list) |
|
579 |
context.update({"form": form}) |
|
580 |
return render_to_response('task/select_user.html', context) |
|
581 |
else: |
|
582 |
return show_msg(user, 'There are no pending claims for this task', |
|
583 |
task_url, 'view the task') |
|
584 |
else: |
|
585 |
raise Http404 |
|
586 |
||
142
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
139
diff
changeset
|
587 |
@login_required |
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
139
diff
changeset
|
588 |
def approve_textbook(request, tid): |
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
139
diff
changeset
|
589 |
|
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
139
diff
changeset
|
590 |
user = request.user |
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
139
diff
changeset
|
591 |
profile = user.get_profile() |
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
139
diff
changeset
|
592 |
|
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
139
diff
changeset
|
593 |
textbook_url = "/task/view/tid=%s"%tid |
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
139
diff
changeset
|
594 |
textbook = getTextBook(tid) |
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
139
diff
changeset
|
595 |
|
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
139
diff
changeset
|
596 |
if profile.rights not in ["MG", "DC"] or textbook.status != "UP": |
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
139
diff
changeset
|
597 |
raise Http404 |
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
139
diff
changeset
|
598 |
|
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
139
diff
changeset
|
599 |
context = {"user": user, |
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
139
diff
changeset
|
600 |
"profile": profile, |
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
139
diff
changeset
|
601 |
"textbook": textbook, |
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
139
diff
changeset
|
602 |
} |
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
139
diff
changeset
|
603 |
|
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
139
diff
changeset
|
604 |
return render_to_response("task/confirm_textbook_approval.html", context) |
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
139
diff
changeset
|
605 |
|
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
139
diff
changeset
|
606 |
@login_required |
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
139
diff
changeset
|
607 |
def approved_textbook(request, tid): |
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
139
diff
changeset
|
608 |
|
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
139
diff
changeset
|
609 |
user = request.user |
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
139
diff
changeset
|
610 |
profile = user.get_profile() |
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
139
diff
changeset
|
611 |
|
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
139
diff
changeset
|
612 |
textbook_url = "/task/view/tid=%s"%tid |
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
139
diff
changeset
|
613 |
textbook = getTextBook(tid) |
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
139
diff
changeset
|
614 |
|
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
139
diff
changeset
|
615 |
if profile.rights not in ["MG", "DC"] or textbook.status != "UP": |
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
139
diff
changeset
|
616 |
raise Http404 |
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
139
diff
changeset
|
617 |
|
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
139
diff
changeset
|
618 |
textbook.approved_by = user |
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
139
diff
changeset
|
619 |
textbook.approval_datetime = datetime.now() |
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
139
diff
changeset
|
620 |
textbook.status = "OP" |
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
139
diff
changeset
|
621 |
textbook.save() |
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
139
diff
changeset
|
622 |
|
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
139
diff
changeset
|
623 |
context = {"user": user, |
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
139
diff
changeset
|
624 |
"profile": profile, |
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
139
diff
changeset
|
625 |
"textbook": textbook, |
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
139
diff
changeset
|
626 |
} |
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
139
diff
changeset
|
627 |
|
e848bd3ad41f
approval of textbooks works now
Nishanth Amuluru <nishanth@fossee.in>
parents:
139
diff
changeset
|
628 |
return render_to_response("task/approved_textbook.html", context) |