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