author | Nishanth Amuluru <nishanth@fossee.in> |
Sun, 09 Jan 2011 19:45:42 +0530 | |
changeset 129 | 13e171f09941 |
parent 128 | 4c349f310dfc |
child 130 | a4fa11b2cb5c |
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 |
|
118
f88135529c74
claim task works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
117
diff
changeset
|
15 |
from pytask.taskapp.models import Task, TaskComment, TaskClaim |
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, \ |
128 | 18 |
ChoiceForm, EditTaskForm |
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
|
19 |
from pytask.taskapp.utils import getTask |
95
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
20 |
from pytask.profile.utils import get_notification |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
21 |
|
101
bce480ff6ddc
used proper import for show_msg
Nishanth Amuluru <nishanth@fossee.in>
parents:
95
diff
changeset
|
22 |
|
95
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
23 |
@login_required |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
24 |
def create_task(request): |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
25 |
|
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
26 |
user = request.user |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
27 |
profile = user.get_profile() |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
28 |
|
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
29 |
context = {"user": user, |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
30 |
"profile": profile, |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
31 |
} |
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 |
context.update(csrf(request)) |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
34 |
|
102 | 35 |
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
|
36 |
if can_create_task: |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
37 |
if request.method == "POST": |
102 | 38 |
form = CreateTaskForm(request.POST) |
95
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
39 |
if form.is_valid(): |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
40 |
data = form.cleaned_data.copy() |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
41 |
data.update({"created_by": user, |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
42 |
"creation_datetime": datetime.now(), |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
43 |
"uniq_key": make_key(Task), |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
44 |
}) |
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 |
task = Task(**data) |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
47 |
task.save() |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
48 |
|
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
49 |
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
|
50 |
return redirect(task_url) |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
51 |
else: |
102 | 52 |
context.update({'form':form}) |
53 |
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
|
54 |
else: |
102 | 55 |
form = CreateTaskForm() |
56 |
context.update({'form':form}) |
|
57 |
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
|
58 |
else: |
eb3a191850a1
created a view for create task
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
59 |
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
|
60 |
|
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 |
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
|
62 |
""" 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
|
63 |
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
|
64 |
""" |
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
|
65 |
|
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
|
66 |
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
|
67 |
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
|
68 |
|
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
|
69 |
user = request.user |
112
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
111
diff
changeset
|
70 |
|
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
111
diff
changeset
|
71 |
if not user.is_authenticated(): |
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
111
diff
changeset
|
72 |
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
|
73 |
|
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
|
74 |
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
|
75 |
|
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
|
76 |
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
|
77 |
"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
|
78 |
"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
|
79 |
} |
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
|
80 |
|
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
|
81 |
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
|
82 |
|
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
|
83 |
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
|
84 |
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
|
85 |
|
112
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
111
diff
changeset
|
86 |
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
|
87 |
else False |
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
111
diff
changeset
|
88 |
if not task_viewable: |
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
111
diff
changeset
|
89 |
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
|
90 |
|
112
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
111
diff
changeset
|
91 |
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
|
92 |
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
|
93 |
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
|
94 |
|
112
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
111
diff
changeset
|
95 |
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
|
96 |
'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
|
97 |
'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
|
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 |
|
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 |
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
|
101 |
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
|
102 |
|
112
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
111
diff
changeset
|
103 |
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
|
104 |
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
|
105 |
|
127
32457bce3437
prettified a few pages
Nishanth Amuluru <nishanth@fossee.in>
parents:
125
diff
changeset
|
106 |
context['selected_users'] = selected_users |
112
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
111
diff
changeset
|
107 |
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
|
108 |
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
|
109 |
profile.rights in ["MG", "DC"]\ |
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
111
diff
changeset
|
110 |
else False |
128 | 111 |
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
|
112 |
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
|
113 |
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
|
114 |
|
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 |
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
|
116 |
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
|
117 |
|
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
111
diff
changeset
|
118 |
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
|
119 |
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
|
120 |
|
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 |
# 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
|
122 |
# 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
|
123 |
# 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
|
124 |
# 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
|
125 |
# 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
|
126 |
# 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
|
127 |
|
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 |
if request.method == 'POST': |
112
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
111
diff
changeset
|
129 |
form = TaskCommentForm(request.POST) |
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
111
diff
changeset
|
130 |
if form.is_valid(): |
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
111
diff
changeset
|
131 |
data = form.cleaned_data['data'] |
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
111
diff
changeset
|
132 |
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
|
133 |
uniq_key=make_key(TaskComment), |
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
111
diff
changeset
|
134 |
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
|
135 |
new_comment.save() |
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
111
diff
changeset
|
136 |
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
|
137 |
else: |
112
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
111
diff
changeset
|
138 |
context['form'] = form |
4cc40503bf3c
view task is now in some shape atleast
Nishanth Amuluru <nishanth@fossee.in>
parents:
111
diff
changeset
|
139 |
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
|
140 |
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
|
141 |
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
|
142 |
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
|
143 |
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
|
144 |
|
115
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
145 |
@login_required |
128 | 146 |
def edit_task(request, tid): |
147 |
""" only creator gets to edit the task and that too only before it gets |
|
148 |
approved. |
|
149 |
""" |
|
150 |
||
151 |
user = request.user |
|
152 |
profile = user.get_profile() |
|
153 |
||
154 |
task_url = "/task/view/tid=%s"%tid |
|
155 |
task = getTask(tid) |
|
156 |
||
157 |
is_creator = True if user == task.created_by else False |
|
158 |
can_edit = True if task.status == "UP" and is_creator else False |
|
159 |
if not can_edit: |
|
160 |
raise Http404 |
|
161 |
||
162 |
context = {"user": user, |
|
163 |
"profile": profile, |
|
164 |
"task": task, |
|
165 |
} |
|
166 |
||
167 |
context.update(csrf(request)) |
|
168 |
||
169 |
if request.method == "POST": |
|
170 |
form = EditTaskForm(request.POST, instance=task) |
|
171 |
if form.is_valid(): |
|
172 |
form.save() |
|
173 |
return redirect(task_url) |
|
174 |
else: |
|
175 |
context.update({"form": form}) |
|
176 |
return render_to_response("task/edit.html", context) |
|
177 |
else: |
|
178 |
form = EditTaskForm(instance=task) |
|
179 |
context.update({"form": form}) |
|
180 |
return render_to_response("task/edit.html", context) |
|
181 |
||
182 |
||
183 |
||
184 |
||
185 |
@login_required |
|
118
f88135529c74
claim task works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
117
diff
changeset
|
186 |
def claim_task(request, tid): |
115
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
187 |
|
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
188 |
task_url = "/task/view/tid=%s"%tid |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
189 |
claim_url = "/task/claim/tid=%s"%tid |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
190 |
task = getTask(tid) |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
191 |
|
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
192 |
if task.status == "UP": |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
193 |
raise Http404 |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
194 |
|
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
195 |
user = request.user |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
196 |
profile = user.get_profile() |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
197 |
|
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
198 |
context = {"user": user, |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
199 |
"profile": profile, |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
200 |
"task": task, |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
201 |
} |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
202 |
|
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
203 |
context.update(csrf(request)) |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
204 |
|
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
205 |
reviewers = task.reviewers.all() |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
206 |
claimed_users = task.claimed_users.all() |
118
f88135529c74
claim task works fine now
Nishanth Amuluru <nishanth@fossee.in>
parents:
117
diff
changeset
|
207 |
selected_users = task.selected_users.all() |
115
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
208 |
|
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
209 |
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
|
210 |
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
|
211 |
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
|
212 |
|
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
213 |
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
|
214 |
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
|
215 |
and ( not is_reviewer ) and (not is_creator ) \ |
ec7f2f4256f5
now the creator can select users
Nishanth Amuluru <nishanth@fossee.in>
parents:
118
diff
changeset
|
216 |
else False |
115
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
217 |
|
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
218 |
old_claims = task.claims.all() |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
219 |
|
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
220 |
context.update({"is_creator": is_creator, |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
221 |
"task_claimable": task_claimable, |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
222 |
"can_claim": can_claim, |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
223 |
"old_claims": old_claims}) |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
224 |
|
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
225 |
if request.method == "POST" and can_claim: |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
226 |
form = ClaimTaskForm(request.POST) |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
227 |
if form.is_valid(): |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
228 |
data = form.cleaned_data.copy() |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
229 |
data.update({"uniq_key": make_key(TaskClaim), |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
230 |
"task": task, |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
231 |
"claim_datetime": datetime.now(), |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
232 |
"claimed_by": user,}) |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
233 |
new_claim = TaskClaim(**data) |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
234 |
new_claim.save() |
117
c693def6510f
added the step of adding user to claimed users
Nishanth Amuluru <nishanth@fossee.in>
parents:
115
diff
changeset
|
235 |
|
c693def6510f
added the step of adding user to claimed users
Nishanth Amuluru <nishanth@fossee.in>
parents:
115
diff
changeset
|
236 |
task.claimed_users.add(user) |
c693def6510f
added the step of adding user to claimed users
Nishanth Amuluru <nishanth@fossee.in>
parents:
115
diff
changeset
|
237 |
task.save() |
c693def6510f
added the step of adding user to claimed users
Nishanth Amuluru <nishanth@fossee.in>
parents:
115
diff
changeset
|
238 |
|
115
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
239 |
return redirect(claim_url) |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
240 |
|
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
241 |
else: |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
242 |
context.update({"form": form}) |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
243 |
return render_to_response("task/claim.html", context) |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
244 |
else: |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
245 |
form = ClaimTaskForm() |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
246 |
context.update({"form": form}) |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
247 |
return render_to_response("task/claim.html", context) |
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
248 |
|
122 | 249 |
@login_required |
250 |
def select_user(request, tid): |
|
251 |
""" first get the status of the task and then select one of claimed users |
|
252 |
generate list of claimed users by passing it as an argument to a function. |
|
253 |
""" |
|
254 |
||
255 |
task_url = "/task/view/tid=%s"%tid |
|
256 |
||
257 |
user = request.user |
|
258 |
profile = user.get_profile() |
|
259 |
task = getTask(tid) |
|
260 |
||
261 |
context = {"user": user, |
|
262 |
"profile": profile, |
|
263 |
"task": task, |
|
264 |
} |
|
115
181d4eb9f419
created a view for making claim
Nishanth Amuluru <nishanth@fossee.in>
parents:
112
diff
changeset
|
265 |
|
122 | 266 |
context.update(csrf(request)) |
267 |
||
268 |
claimed_users = task.claimed_users.all() |
|
269 |
selected_users = task.selected_users.all() |
|
124
070f01dd7d8e
Select user works completely fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
122
diff
changeset
|
270 |
task_claimed = True if claimed_users else False |
122 | 271 |
|
272 |
is_creator = True if user == task.created_by else False |
|
273 |
||
274 |
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
|
275 |
task.status in ["OP", "WR"]: |
122 | 276 |
|
124
070f01dd7d8e
Select user works completely fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
122
diff
changeset
|
277 |
if task_claimed: |
122 | 278 |
|
279 |
user_list = ((user.id,user.username) for user in claimed_users) |
|
280 |
||
281 |
if request.method == "POST": |
|
282 |
form = ChoiceForm(user_list, request.POST) |
|
283 |
if form.is_valid(): |
|
284 |
uid = form.cleaned_data['choice'] |
|
285 |
selected_user = User.objects.get(id=uid) |
|
286 |
||
124
070f01dd7d8e
Select user works completely fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
122
diff
changeset
|
287 |
task.selected_users.add(selected_user) |
070f01dd7d8e
Select user works completely fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
122
diff
changeset
|
288 |
task.claimed_users.remove(selected_user) |
125
9b0812962133
created the home page
Nishanth Amuluru <nishanth@fossee.in>
parents:
124
diff
changeset
|
289 |
task.status = "WR" |
122 | 290 |
task.save() |
291 |
||
292 |
return redirect(task_url) |
|
293 |
else: |
|
294 |
context.update({"form": form}) |
|
295 |
return render_to_response('task/select_user.html', context) |
|
296 |
else: |
|
297 |
form = ChoiceForm(user_list) |
|
298 |
context.update({"form": form}) |
|
299 |
return render_to_response('task/select_user.html', context) |
|
300 |
else: |
|
301 |
return show_msg(user, 'There are no pending claims for this task', |
|
302 |
task_url, 'view the task') |
|
303 |
else: |
|
304 |
raise Http404 |
|
305 |