author | nishanth |
Sun, 28 Feb 2010 19:31:41 +0530 | |
changeset 151 | d0cb85ba462a |
parent 149 | 3395960549e8 |
child 153 | 925af1b4ee65 |
permissions | -rw-r--r-- |
17
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
1 |
from datetime import datetime |
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
2 |
|
151
d0cb85ba462a
no bogus post request can be made now in addmentor page.
nishanth
parents:
149
diff
changeset
|
3 |
from django.http import HttpResponse, Http404 |
17
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
4 |
from django.shortcuts import render_to_response, redirect |
18
a39549bd5b08
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
17
diff
changeset
|
5 |
|
149
3395960549e8
now a user cannot make two requests to another user for mentoring a task.
nishanth
parents:
141
diff
changeset
|
6 |
from pytask.taskapp.models import User, Task, Comment, Claim, Credit, Request |
120 | 7 |
from pytask.taskapp.utilities.task import getTask |
94 | 8 |
from pytask.taskapp.forms.task import TaskCreateForm, AddMentorForm, AddTaskForm, ChoiceForm, AssignCreditForm, RemoveUserForm |
126 | 9 |
from pytask.taskapp.events.task import createTask, reqMentor, publishTask, addSubTask, addDep, addClaim, assignTask, updateTask, removeTask, removeUser, assignCredits, completeTask, closeTask |
18
a39549bd5b08
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
17
diff
changeset
|
10 |
from pytask.taskapp.views.user import show_msg |
138
c452c699a8af
now all the pages show number of unread beside requests and notifications link in sidebar.
nishanth
parents:
136
diff
changeset
|
11 |
from pytask.taskapp.utilities.user import get_user |
17
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
12 |
|
21
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
13 |
## everywhere if there is no task, django should display 500 message.. but take care of that in sensitive views like add mentor and all |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
14 |
## do not create su user thro syncdb |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
15 |
|
17
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
16 |
def browse_tasks(request): |
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
17 |
""" display all the tasks """ |
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
18 |
|
141
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
19 |
user = get_user(request.user) if request.user.is_authenticated() else request.user |
124
6d92b7cd2a37
taking care if publish task post request is made again. added published_date field to task.
nishanth
parents:
120
diff
changeset
|
20 |
task_list = Task.objects.exclude(status="UP").exclude(status="DL").order_by('published_datetime').reverse() |
17
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
21 |
|
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
22 |
context = {'user':user, |
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
23 |
'task_list':task_list, |
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
24 |
} |
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
25 |
return render_to_response('task/browse.html', context) |
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
26 |
|
111 | 27 |
def publish_task(request, tid): |
28 |
""" check if user is the mentor and also if the task status is UP. |
|
29 |
""" |
|
30 |
||
31 |
task_url = "/task/view/tid=%s"%tid |
|
32 |
||
141
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
33 |
user = get_user(request.user) if request.user.is_authenticated() else request.user |
111 | 34 |
task = getTask(tid) |
35 |
||
36 |
is_guest = True if not user.is_authenticated() else False |
|
37 |
is_mentor = True if user in task.mentors.all() else False |
|
38 |
||
124
6d92b7cd2a37
taking care if publish task post request is made again. added published_date field to task.
nishanth
parents:
120
diff
changeset
|
39 |
if user == task.created_by: |
111 | 40 |
context = { |
41 |
'user':user, |
|
42 |
} |
|
124
6d92b7cd2a37
taking care if publish task post request is made again. added published_date field to task.
nishanth
parents:
120
diff
changeset
|
43 |
if task.status == "UP": |
6d92b7cd2a37
taking care if publish task post request is made again. added published_date field to task.
nishanth
parents:
120
diff
changeset
|
44 |
if request.method == "POST": |
6d92b7cd2a37
taking care if publish task post request is made again. added published_date field to task.
nishanth
parents:
120
diff
changeset
|
45 |
publishTask(task) |
6d92b7cd2a37
taking care if publish task post request is made again. added published_date field to task.
nishanth
parents:
120
diff
changeset
|
46 |
return show_msg(user, "The task has been published", task_url, "view the task") |
6d92b7cd2a37
taking care if publish task post request is made again. added published_date field to task.
nishanth
parents:
120
diff
changeset
|
47 |
else: |
6d92b7cd2a37
taking care if publish task post request is made again. added published_date field to task.
nishanth
parents:
120
diff
changeset
|
48 |
return render_to_response('task/publish.html', context) |
111 | 49 |
else: |
124
6d92b7cd2a37
taking care if publish task post request is made again. added published_date field to task.
nishanth
parents:
120
diff
changeset
|
50 |
return show_msg(user, "The task is already published", task_url, "view the task") |
111 | 51 |
else: |
52 |
return show_msg(user, "You are not authorised to do this", '/task/browse/', "browse tasks") |
|
53 |
||
17
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
54 |
def view_task(request, tid): |
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
55 |
""" get the task depending on its tid and display accordingly if it is a get. |
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
56 |
check for authentication and add a comment if it is a post request. |
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
57 |
""" |
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
58 |
|
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
59 |
task_url = "/task/view/tid=%s"%tid |
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
60 |
|
141
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
61 |
user = get_user(request.user) if request.user.is_authenticated() else request.user |
55
ca2486e29178
added a utility called getTask in task events and made changes in task views accordingly
nishanth
parents:
36
diff
changeset
|
62 |
task = getTask(tid) |
110 | 63 |
|
64 |
if task.status == "DL": |
|
65 |
return show_msg(user, 'This task no longer exists', '/task/browse/','browse the tasks') |
|
112
eadff01e395e
now task page displays only undeleted comments. and publish task removes previous comments.
nishanth
parents:
111
diff
changeset
|
66 |
comments = task.comment_set.filter(is_deleted=False) |
21
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
67 |
mentors = task.mentors.all() |
90
b2426897ff18
our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents:
89
diff
changeset
|
68 |
|
b2426897ff18
our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents:
89
diff
changeset
|
69 |
deps, subs = task.deps, task.subs |
b2426897ff18
our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents:
89
diff
changeset
|
70 |
|
17
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
71 |
errors = [] |
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
72 |
|
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
73 |
is_guest = True if not user.is_authenticated() else False |
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
74 |
is_mentor = True if user in task.mentors.all() else False |
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
75 |
context = {'user':user, |
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
76 |
'task':task, |
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
77 |
'comments':comments, |
21
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
78 |
'mentors':mentors, |
66
f670de53402b
modified view task template and view to suit new design.
nishanth
parents:
64
diff
changeset
|
79 |
'subs':subs, |
f670de53402b
modified view task template and view to suit new design.
nishanth
parents:
64
diff
changeset
|
80 |
'deps':deps, |
17
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
81 |
'is_guest':is_guest, |
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
82 |
'is_mentor':is_mentor, |
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
83 |
'errors':errors, |
66
f670de53402b
modified view task template and view to suit new design.
nishanth
parents:
64
diff
changeset
|
84 |
} |
f670de53402b
modified view task template and view to suit new design.
nishanth
parents:
64
diff
changeset
|
85 |
|
111 | 86 |
context['can_publish'] = True if task.status == "UP" and user == task.created_by else False |
126 | 87 |
context['task_viewable'] = True if ( task.status != "DL" ) or is_mentor else False |
66
f670de53402b
modified view task template and view to suit new design.
nishanth
parents:
64
diff
changeset
|
88 |
context['task_claimable'] = True if task.status in ["OP", "WR"] else False |
f670de53402b
modified view task template and view to suit new design.
nishanth
parents:
64
diff
changeset
|
89 |
|
f670de53402b
modified view task template and view to suit new design.
nishanth
parents:
64
diff
changeset
|
90 |
context['can_mod_mentors'] = True if task.status in ["UP", "OP", "LO", "WR"] and is_mentor else False |
f670de53402b
modified view task template and view to suit new design.
nishanth
parents:
64
diff
changeset
|
91 |
context['can_mod_tasks'] = True if task.status in ["UP", "OP", "LO"] and is_mentor else False |
f670de53402b
modified view task template and view to suit new design.
nishanth
parents:
64
diff
changeset
|
92 |
context['can_assign_credits'] = True if task.status in ["OP", "WR"] and is_mentor else False |
f670de53402b
modified view task template and view to suit new design.
nishanth
parents:
64
diff
changeset
|
93 |
|
f670de53402b
modified view task template and view to suit new design.
nishanth
parents:
64
diff
changeset
|
94 |
context['assigned_users'] = task.assigned_users.all() |
64
e743fe1f0f99
updated view task in views to suit the new design .
nishanth
parents:
55
diff
changeset
|
95 |
|
17
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
96 |
if request.method == 'POST': |
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
97 |
if not is_guest: |
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
98 |
data = request.POST["data"] |
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
99 |
new_comment = Comment(task=task, data=data, created_by=user, creation_datetime=datetime.now()) |
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
100 |
new_comment.save() |
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
101 |
return redirect(task_url) |
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
102 |
else: |
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
103 |
errors.append("You must be logged in to post a comment") |
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
104 |
return render_to_response('task/view.html', context) |
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
105 |
else: |
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
106 |
return render_to_response('task/view.html', context) |
18
a39549bd5b08
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
17
diff
changeset
|
107 |
|
a39549bd5b08
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
17
diff
changeset
|
108 |
def create_task(request): |
a39549bd5b08
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
17
diff
changeset
|
109 |
""" check for rights and create a task if applicable. |
a39549bd5b08
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
17
diff
changeset
|
110 |
if user cannot create a task, redirect to homepage. |
a39549bd5b08
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
17
diff
changeset
|
111 |
""" |
a39549bd5b08
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
17
diff
changeset
|
112 |
|
141
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
113 |
user = get_user(request.user) if request.user.is_authenticated() else request.user |
18
a39549bd5b08
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
17
diff
changeset
|
114 |
is_guest = True if not user.is_authenticated() else False |
a39549bd5b08
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
17
diff
changeset
|
115 |
|
a39549bd5b08
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
17
diff
changeset
|
116 |
if not is_guest: |
a39549bd5b08
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
17
diff
changeset
|
117 |
user_profile = user.get_profile() |
a39549bd5b08
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
17
diff
changeset
|
118 |
can_create_task = False if user_profile.rights == "CT" else True |
a39549bd5b08
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
17
diff
changeset
|
119 |
if can_create_task: |
a39549bd5b08
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
17
diff
changeset
|
120 |
if request.method == "POST": |
a39549bd5b08
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
17
diff
changeset
|
121 |
form = TaskCreateForm(request.POST) |
a39549bd5b08
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
17
diff
changeset
|
122 |
if form.is_valid(): |
a39549bd5b08
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
17
diff
changeset
|
123 |
data = form.cleaned_data |
a39549bd5b08
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
17
diff
changeset
|
124 |
title = data['title'] |
a39549bd5b08
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
17
diff
changeset
|
125 |
desc = data['desc'] |
a39549bd5b08
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
17
diff
changeset
|
126 |
credits = data['credits'] |
a39549bd5b08
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
17
diff
changeset
|
127 |
publish = data['publish'] |
a39549bd5b08
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
17
diff
changeset
|
128 |
task = createTask(title,desc,user,credits) |
a39549bd5b08
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
17
diff
changeset
|
129 |
|
a39549bd5b08
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
17
diff
changeset
|
130 |
if not task: |
a39549bd5b08
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
17
diff
changeset
|
131 |
error_msg = "Another task with the same title exists" |
a39549bd5b08
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
17
diff
changeset
|
132 |
return render_to_response('task/create.html',{'form':form, 'error_msg':error_msg}) |
a39549bd5b08
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
17
diff
changeset
|
133 |
|
a39549bd5b08
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
17
diff
changeset
|
134 |
addMentor(task, user) |
66
f670de53402b
modified view task template and view to suit new design.
nishanth
parents:
64
diff
changeset
|
135 |
updateTask(task,tags_field=data['tags_field']) |
18
a39549bd5b08
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
17
diff
changeset
|
136 |
if publish: publishTask(task) |
a39549bd5b08
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
17
diff
changeset
|
137 |
task_url = '/task/view/tid=%s'%task.id |
a39549bd5b08
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
17
diff
changeset
|
138 |
return redirect(task_url) |
a39549bd5b08
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
17
diff
changeset
|
139 |
else: |
a39549bd5b08
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
17
diff
changeset
|
140 |
return render_to_response('task/create.html',{'form':form}) |
a39549bd5b08
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
17
diff
changeset
|
141 |
else: |
a39549bd5b08
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
17
diff
changeset
|
142 |
form = TaskCreateForm() |
a39549bd5b08
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
17
diff
changeset
|
143 |
return render_to_response('task/create.html',{'form':form}) |
a39549bd5b08
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
17
diff
changeset
|
144 |
else: |
108
131554cc3434
updated show_msg method to also use the user variable in the context.
nishanth
parents:
105
diff
changeset
|
145 |
return show_msg(user, 'You are not authorised to create a task.') |
18
a39549bd5b08
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
17
diff
changeset
|
146 |
else: |
108
131554cc3434
updated show_msg method to also use the user variable in the context.
nishanth
parents:
105
diff
changeset
|
147 |
return show_msg(user, 'You are not authorised to create a task.') |
21
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
148 |
|
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
149 |
def add_mentor(request, tid): |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
150 |
""" check if the current user has the rights to edit the task and add him. |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
151 |
if user is not authenticated, redirect him to concerned page. """ |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
152 |
|
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
153 |
task_url = "/task/view/tid=%s"%tid |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
154 |
|
141
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
155 |
user = get_user(request.user) if request.user.is_authenticated() else request.user |
55
ca2486e29178
added a utility called getTask in task events and made changes in task views accordingly
nishanth
parents:
36
diff
changeset
|
156 |
task = getTask(tid) |
21
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
157 |
errors = [] |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
158 |
|
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
159 |
is_guest = True if not user.is_authenticated() else False |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
160 |
|
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
161 |
if (not is_guest) and user in task.mentors.all(): |
149
3395960549e8
now a user cannot make two requests to another user for mentoring a task.
nishanth
parents:
141
diff
changeset
|
162 |
|
3395960549e8
now a user cannot make two requests to another user for mentoring a task.
nishanth
parents:
141
diff
changeset
|
163 |
pending_requests = Request.objects.filter(is_replied=False,is_valid=True,role="MT",task=task).order_by('creation_date').reverse() |
3395960549e8
now a user cannot make two requests to another user for mentoring a task.
nishanth
parents:
141
diff
changeset
|
164 |
user_pending_requests = pending_requests.filter(sent_by=user) |
3395960549e8
now a user cannot make two requests to another user for mentoring a task.
nishanth
parents:
141
diff
changeset
|
165 |
|
21
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
166 |
## now iam going for a brute force method |
76 | 167 |
user_list = list(User.objects.filter(is_active=True)) |
21
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
168 |
for mentor in task.mentors.all(): |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
169 |
user_list.remove(mentor) |
34 | 170 |
|
171 |
for a_user in task.claimed_users.all(): |
|
172 |
user_list.remove(a_user) |
|
76 | 173 |
|
174 |
for a_user in task.assigned_users.all(): |
|
175 |
user_list.remove(a_user) |
|
149
3395960549e8
now a user cannot make two requests to another user for mentoring a task.
nishanth
parents:
141
diff
changeset
|
176 |
|
3395960549e8
now a user cannot make two requests to another user for mentoring a task.
nishanth
parents:
141
diff
changeset
|
177 |
for req in user_pending_requests: |
3395960549e8
now a user cannot make two requests to another user for mentoring a task.
nishanth
parents:
141
diff
changeset
|
178 |
user_list.remove(req.sent_to.all()[0]) |
34 | 179 |
|
151
d0cb85ba462a
no bogus post request can be made now in addmentor page.
nishanth
parents:
149
diff
changeset
|
180 |
non_mentors = ((_.id, _.username) for _ in user_list) |
d0cb85ba462a
no bogus post request can be made now in addmentor page.
nishanth
parents:
149
diff
changeset
|
181 |
non_mentor_ids = [ str(a_user.id) for a_user in user_list ] |
34 | 182 |
## code till must be made elegant and not brute force like above |
149
3395960549e8
now a user cannot make two requests to another user for mentoring a task.
nishanth
parents:
141
diff
changeset
|
183 |
|
21
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
184 |
form = AddMentorForm(non_mentors) |
151
d0cb85ba462a
no bogus post request can be made now in addmentor page.
nishanth
parents:
149
diff
changeset
|
185 |
|
d0cb85ba462a
no bogus post request can be made now in addmentor page.
nishanth
parents:
149
diff
changeset
|
186 |
context = { |
d0cb85ba462a
no bogus post request can be made now in addmentor page.
nishanth
parents:
149
diff
changeset
|
187 |
'user':user, |
d0cb85ba462a
no bogus post request can be made now in addmentor page.
nishanth
parents:
149
diff
changeset
|
188 |
'pending_requests':pending_requests, |
d0cb85ba462a
no bogus post request can be made now in addmentor page.
nishanth
parents:
149
diff
changeset
|
189 |
'form':form, |
d0cb85ba462a
no bogus post request can be made now in addmentor page.
nishanth
parents:
149
diff
changeset
|
190 |
} |
d0cb85ba462a
no bogus post request can be made now in addmentor page.
nishanth
parents:
149
diff
changeset
|
191 |
|
21
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
192 |
if request.method == "POST": |
151
d0cb85ba462a
no bogus post request can be made now in addmentor page.
nishanth
parents:
149
diff
changeset
|
193 |
data = request.POST |
d0cb85ba462a
no bogus post request can be made now in addmentor page.
nishanth
parents:
149
diff
changeset
|
194 |
uid = data.get('mentor', None) |
d0cb85ba462a
no bogus post request can be made now in addmentor page.
nishanth
parents:
149
diff
changeset
|
195 |
if uid in non_mentor_ids: |
d0cb85ba462a
no bogus post request can be made now in addmentor page.
nishanth
parents:
149
diff
changeset
|
196 |
new_mentor = User.objects.get(id=int(uid)) |
d0cb85ba462a
no bogus post request can be made now in addmentor page.
nishanth
parents:
149
diff
changeset
|
197 |
reqMentor(task, new_mentor, user) |
d0cb85ba462a
no bogus post request can be made now in addmentor page.
nishanth
parents:
149
diff
changeset
|
198 |
return redirect('/task/addmentor/tid=%s'%task.id) |
d0cb85ba462a
no bogus post request can be made now in addmentor page.
nishanth
parents:
149
diff
changeset
|
199 |
else: |
d0cb85ba462a
no bogus post request can be made now in addmentor page.
nishanth
parents:
149
diff
changeset
|
200 |
## bogus post request |
d0cb85ba462a
no bogus post request can be made now in addmentor page.
nishanth
parents:
149
diff
changeset
|
201 |
raise Http404 |
21
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
202 |
else: |
151
d0cb85ba462a
no bogus post request can be made now in addmentor page.
nishanth
parents:
149
diff
changeset
|
203 |
return render_to_response('task/addmentor.html', context) |
21
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
204 |
else: |
108
131554cc3434
updated show_msg method to also use the user variable in the context.
nishanth
parents:
105
diff
changeset
|
205 |
return show_msg(user, 'You are not authorised to add mentors for this task', task_url, 'view the task') |
21
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
206 |
|
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
207 |
def add_tasks(request, tid): |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
208 |
""" first display tasks which can be subtasks for the task and do the rest. |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
209 |
""" |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
210 |
|
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
211 |
task_url = "/task/view/tid=%s"%tid |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
212 |
|
141
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
213 |
user = get_user(request.user) if request.user.is_authenticated() else request.user |
55
ca2486e29178
added a utility called getTask in task events and made changes in task views accordingly
nishanth
parents:
36
diff
changeset
|
214 |
task = getTask(tid) |
89
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
215 |
|
90
b2426897ff18
our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents:
89
diff
changeset
|
216 |
deps, subs = task.deps, task.subs |
89
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
217 |
is_plain = False if deps or subs else True |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
218 |
|
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
219 |
## again a brute force method |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
220 |
valid_tasks = [] |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
221 |
for a_task in Task.objects.all(): |
90
b2426897ff18
our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents:
89
diff
changeset
|
222 |
if not ( a_task in deps or a_task in subs or a_task.status=="CD" or a_task==task ): |
89
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
223 |
valid_tasks.append(a_task) |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
224 |
|
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
225 |
task_choices = [ (_.id,_.title) for _ in valid_tasks ] |
21
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
226 |
errors = [] |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
227 |
|
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
228 |
is_guest = True if not user.is_authenticated() else False |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
229 |
|
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
230 |
if (not is_guest) and user in task.mentors.all(): |
89
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
231 |
if task.status in ["UP", "OP", "LO"]: |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
232 |
form = AddTaskForm(task_choices, is_plain) |
21
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
233 |
if request.method == "POST": |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
234 |
## first decide if adding subs and deps can be in same page |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
235 |
## only exclude tasks with status deleted |
89
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
236 |
data = request.POST |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
237 |
if is_plain and not data.get('type', None): errors.append('Please choose which type of task(s) do you want to add.') |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
238 |
if not data.get('task', None): errors.append('Please choose a one task') |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
239 |
|
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
240 |
if not errors: |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
241 |
if is_plain: |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
242 |
update_method = addDep if data['type'] == "D" else addSubTask |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
243 |
elif deps: |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
244 |
update_method = addDep |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
245 |
elif subs: |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
246 |
update_method = addSubTask |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
247 |
else: |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
248 |
print "Screw you" |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
249 |
|
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
250 |
## we might iterate over a task list later on |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
251 |
task_id = data['task'] |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
252 |
sub_or_dep = getTask(task_id) |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
253 |
update_method(task, sub_or_dep) |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
254 |
|
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
255 |
return redirect(task_url) |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
256 |
else: |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
257 |
return render_to_response('task/addtask.html', {'user':user, 'form':form, 'errors':errors}) |
21
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
258 |
else: |
89
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
259 |
return render_to_response('task/addtask.html', {'user':user, 'form':form, 'errors':errors}) |
21
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
260 |
else: |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
261 |
errors = ["The task cannot be added subtasks or dependencies in this state"] |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
262 |
# return render_to_response('task/add.html', {'form':form, 'errors':errors}) |
108
131554cc3434
updated show_msg method to also use the user variable in the context.
nishanth
parents:
105
diff
changeset
|
263 |
return show_msg(user, 'The task cannot be added subtasks or dependencies now', task_url, 'view the task') |
21
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
264 |
else: |
108
131554cc3434
updated show_msg method to also use the user variable in the context.
nishanth
parents:
105
diff
changeset
|
265 |
return show_msg(user, 'You are not authorised to add subtasks or dependencies for this task', task_url, 'view the task') |
21
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
266 |
|
89
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
267 |
def remove_task(request, tid): |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
268 |
""" display a list of tasks and remove the selectes ones. |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
269 |
""" |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
270 |
|
92
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
271 |
task_url = "/task/view/tid=%s"%tid |
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
272 |
|
141
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
273 |
user = get_user(request.user) if request.user.is_authenticated() else request.user |
92
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
274 |
task = getTask(tid) |
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
275 |
|
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
276 |
is_guest = True if not user.is_authenticated() else False |
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
277 |
if (not is_guest) and user in task.mentors.all(): |
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
278 |
|
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
279 |
deps, subs = task.deps, task.subs |
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
280 |
task_list = deps if task.sub_type == "D" else subs |
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
281 |
|
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
282 |
if task_list: |
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
283 |
choices = [(_.id,_.title) for _ in task_list ] |
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
284 |
form = ChoiceForm(choices) |
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
285 |
|
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
286 |
errors = [] |
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
287 |
|
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
288 |
if request.method == "POST": |
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
289 |
data = request.POST |
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
290 |
if not data.get('choice', None): errors.append("Please choose a task to remove.") |
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
291 |
if not errors: |
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
292 |
tid = data['choice'] |
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
293 |
sub_task = getTask(tid) |
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
294 |
removeTask(task, sub_task) |
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
295 |
return redirect(task_url) |
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
296 |
else: |
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
297 |
return render_to_response('task/removetask.html', {'user':user, 'form':form, 'errors':errors}) |
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
298 |
else: |
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
299 |
return render_to_response('task/removetask.html', {'user':user, 'form':form, 'errors':errors}) |
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
300 |
else: |
108
131554cc3434
updated show_msg method to also use the user variable in the context.
nishanth
parents:
105
diff
changeset
|
301 |
return show_msg(user, "The task has no subtasks/dependencies to be removed", task_url, "view the task") |
92
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
302 |
else: |
108
131554cc3434
updated show_msg method to also use the user variable in the context.
nishanth
parents:
105
diff
changeset
|
303 |
return show_msg(user, "You are not authorised to do this", task_url, "view the task") |
92
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
304 |
|
21
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
305 |
def claim_task(request, tid): |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
306 |
""" display a list of claims for get and display submit only if claimable """ |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
307 |
|
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
308 |
## create claims model and create a new database with required tables for it |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
309 |
## see if that "one to n" or "n to one" relationship has a special field |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
310 |
|
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
311 |
task_url = "/task/view/tid=%s"%tid |
25
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
312 |
claim_url = "/task/claim/tid=%s"%tid |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
313 |
|
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
314 |
errors = [] |
21
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
315 |
|
141
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
316 |
user = get_user(request.user) if request.user.is_authenticated() else request.user |
55
ca2486e29178
added a utility called getTask in task events and made changes in task views accordingly
nishanth
parents:
36
diff
changeset
|
317 |
task = getTask(tid) |
22 | 318 |
claims = Claim.objects.filter(task=task) |
72 | 319 |
|
320 |
mentors = task.mentors.all() |
|
321 |
claimed_users = task.claimed_users.all() |
|
76 | 322 |
assigned_users = task.assigned_users.all() |
22 | 323 |
|
324 |
is_guest = True if not user.is_authenticated() else False |
|
72 | 325 |
is_mentor = True if user in mentors else False |
22 | 326 |
|
72 | 327 |
task_claimable = True if task.status in ["OP", "WR"] else False |
76 | 328 |
user_can_claim = True if task_claimable and not ( is_guest or is_mentor ) and ( user not in claimed_users ) and ( user not in assigned_users ) else False |
72 | 329 |
task_claimed = True if claimed_users else False |
25
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
330 |
|
72 | 331 |
context = {'user':user, |
332 |
'is_mentor':is_mentor, |
|
25
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
333 |
'task':task, |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
334 |
'claims':claims, |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
335 |
'user_can_claim':user_can_claim, |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
336 |
'task_claimable':task_claimable, |
33
0d0ea7b188d5
fixed a bug in templates/task/claim.html which required modification of views/task.py; also changed the no.of char limit on task title .
nishanth
parents:
25
diff
changeset
|
337 |
'task_claimed':task_claimed, |
25
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
338 |
'errors':errors} |
22 | 339 |
|
340 |
if not is_guest: |
|
25
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
341 |
if request.method == "POST": |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
342 |
claim_proposal = request.POST['message'] |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
343 |
if claim_proposal: |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
344 |
addClaim(task, claim_proposal, user) |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
345 |
return redirect(claim_url) |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
346 |
else: |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
347 |
errors.append('Please fill up proposal in the field below') |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
348 |
return render_to_response('task/claim.html', context) |
22 | 349 |
else: |
25
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
350 |
return render_to_response('task/claim.html', context) |
22 | 351 |
else: |
108
131554cc3434
updated show_msg method to also use the user variable in the context.
nishanth
parents:
105
diff
changeset
|
352 |
return show_msg(user, 'You are not logged in to view claims for this task', task_url, 'view the task') |
18
a39549bd5b08
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
17
diff
changeset
|
353 |
|
94 | 354 |
def rem_user(request, tid): |
355 |
""" show a list of working users and ask for a message/reason for removing user. |
|
356 |
""" |
|
18
a39549bd5b08
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
17
diff
changeset
|
357 |
|
94 | 358 |
task_url = "/task/view/tid=%s"%tid |
359 |
||
141
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
360 |
user = get_user(request.user) if request.user.is_authenticated() else request.user |
94 | 361 |
task = getTask(tid) |
362 |
||
363 |
is_guest = True if not user.is_authenticated() else False |
|
364 |
is_mentor = True if user in task.mentors.all() else False |
|
365 |
||
366 |
if (not is_guest) and is_mentor: |
|
367 |
||
368 |
assigned_users = task.assigned_users.all() |
|
369 |
choices = [ (_.id,_.username) for _ in assigned_users ] |
|
370 |
context = { |
|
371 |
'user':user, |
|
372 |
'task':task, |
|
373 |
} |
|
374 |
||
375 |
if assigned_users: |
|
376 |
form = RemoveUserForm(choices) |
|
377 |
context['form'] = form |
|
378 |
if request.method == "POST": |
|
379 |
data = request.POST |
|
380 |
form = RemoveUserForm(choices, data) |
|
381 |
if form.is_valid(): |
|
382 |
data = form.cleaned_data |
|
383 |
uid = data['user'] |
|
384 |
rem_user = User.objects.get(id=uid) |
|
385 |
removeUser(task, rem_user) |
|
386 |
print data['reason'] |
|
387 |
return redirect(task_url) |
|
388 |
else: |
|
389 |
context['form'] = form |
|
390 |
return render_to_response('task/remove_user.html', context) |
|
391 |
else: |
|
392 |
return render_to_response('task/remove_user.html',context) |
|
393 |
else: |
|
108
131554cc3434
updated show_msg method to also use the user variable in the context.
nishanth
parents:
105
diff
changeset
|
394 |
return show_msg(user, "There is no one working on this task to be kicked off", task_url, "view the task") |
94 | 395 |
else: |
108
131554cc3434
updated show_msg method to also use the user variable in the context.
nishanth
parents:
105
diff
changeset
|
396 |
return show_msg(user, "You are not authorised to do this", task_url, "view the task") |
94 | 397 |
|
25
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
398 |
def assign_task(request, tid): |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
399 |
""" first get the status of the task and then assign it to one of claimed users |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
400 |
generate list of claimed users by passing it as an argument to a function. |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
401 |
""" |
18
a39549bd5b08
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
17
diff
changeset
|
402 |
|
25
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
403 |
task_url = "/task/view/tid=%s"%tid |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
404 |
|
141
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
405 |
user = get_user(request.user) if request.user.is_authenticated() else request.user |
55
ca2486e29178
added a utility called getTask in task events and made changes in task views accordingly
nishanth
parents:
36
diff
changeset
|
406 |
task = getTask(tid) |
25
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
407 |
|
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
408 |
is_guest = True if not user.is_authenticated() else False |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
409 |
is_mentor = True if user in task.mentors.all() else False |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
410 |
|
75
fa59955a340b
modified the assign task view to suit the new design
nishanth
parents:
72
diff
changeset
|
411 |
claimed_users = task.claimed_users.all() |
fa59955a340b
modified the assign task view to suit the new design
nishanth
parents:
72
diff
changeset
|
412 |
assigned_users = task.assigned_users.all() |
fa59955a340b
modified the assign task view to suit the new design
nishanth
parents:
72
diff
changeset
|
413 |
|
fa59955a340b
modified the assign task view to suit the new design
nishanth
parents:
72
diff
changeset
|
414 |
task_claimed = True if claimed_users else False |
18
a39549bd5b08
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
17
diff
changeset
|
415 |
|
25
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
416 |
if (not is_guest) and is_mentor: |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
417 |
if task_claimed: |
75
fa59955a340b
modified the assign task view to suit the new design
nishanth
parents:
72
diff
changeset
|
418 |
user_list = ((user.id,user.username) for user in claimed_users) |
91
1b5ad4b7c40e
modified the name of assign_task_form to choice form since all it does is return a form with choices and made change accordingly.
nishanth
parents:
90
diff
changeset
|
419 |
form = ChoiceForm(user_list) |
18
a39549bd5b08
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
nishanth
parents:
17
diff
changeset
|
420 |
|
25
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
421 |
if request.method == "POST": |
92
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
422 |
uid = request.POST['choice'] |
25
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
423 |
assigned_user = User.objects.get(id=uid) |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
424 |
assignTask(task, assigned_user) |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
425 |
return redirect(task_url) |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
426 |
else: |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
427 |
return render_to_response('task/assign.html',{'form':form}) |
75
fa59955a340b
modified the assign task view to suit the new design
nishanth
parents:
72
diff
changeset
|
428 |
elif assigned_users: |
108
131554cc3434
updated show_msg method to also use the user variable in the context.
nishanth
parents:
105
diff
changeset
|
429 |
return show_msg(user, 'When the no of users you need for the task is more than the no of users willing to do the task, I\'d say please re consider the task :P',task_url, 'view the task') |
25
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
430 |
else: |
108
131554cc3434
updated show_msg method to also use the user variable in the context.
nishanth
parents:
105
diff
changeset
|
431 |
return show_msg(user, 'Wait for ppl to claim dude... slow and steady wins the race :)', task_url, 'view the task') |
25
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
432 |
else: |
108
131554cc3434
updated show_msg method to also use the user variable in the context.
nishanth
parents:
105
diff
changeset
|
433 |
return show_msg(user, 'You are not authorised to perform this action', task_url, 'view the task') |
93
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
434 |
|
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
435 |
def assign_credits(request, tid): |
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
436 |
""" Check if the user is a mentor and credits can be assigned. |
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
437 |
Then display all the approved credits. |
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
438 |
Then see if mentor can assign credits to users also or only mentors. |
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
439 |
Then put up a form for mentor to assign credits accordingly. |
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
440 |
""" |
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
441 |
|
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
442 |
task_url = "/task/view/tid=%s"%tid |
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
443 |
|
141
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
444 |
user = get_user(request.user) if request.user.is_authenticated() else request.user |
93
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
445 |
task = getTask(tid) |
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
446 |
|
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
447 |
is_guest = True if not user.is_authenticated() else False |
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
448 |
is_mentor = True if (not is_guest) and user in task.mentors.all() else False |
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
449 |
|
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
450 |
if is_mentor: |
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
451 |
if task.status in ["OP", "WR"]: |
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
452 |
choices = [(_.id,_.username) for _ in task.mentors.all()] |
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
453 |
if task.status == "WR": |
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
454 |
choices.extend([(_.id, _.username) for _ in task.assigned_users.all() ]) |
136
8632a44b743d
deducing previous credits for a task using the request model. with a few changes, we can ditchax the credits model.
nishanth
parents:
135
diff
changeset
|
455 |
prev_credits = task.request_task.filter(role="PY",is_valid=True,is_replied=True,reply=True).count() |
135
0ede6b2c5cd1
now view credits page shows all the credits.. including the pending and rejected ones.
nishanth
parents:
131
diff
changeset
|
456 |
credit_requests = task.request_task.filter(role="PY",is_valid=True).order_by('creation_date').reverse() |
93
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
457 |
form = AssignCreditForm(choices) |
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
458 |
|
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
459 |
context = { |
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
460 |
'user':user, |
96
2881ed1c52b0
added events addCredits and assignCredits and modified assign_credits view accordingly.
nishanth
parents:
94
diff
changeset
|
461 |
'task':task, |
93
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
462 |
'prev_credits':prev_credits, |
135
0ede6b2c5cd1
now view credits page shows all the credits.. including the pending and rejected ones.
nishanth
parents:
131
diff
changeset
|
463 |
'credit_requests':credit_requests, |
93
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
464 |
'form':form, |
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
465 |
} |
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
466 |
|
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
467 |
if request.method == "POST": |
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
468 |
data = request.POST |
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
469 |
form = AssignCreditForm(choices, data) |
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
470 |
if form.is_valid(): |
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
471 |
data = form.cleaned_data |
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
472 |
uid = data['user'] |
136
8632a44b743d
deducing previous credits for a task using the request model. with a few changes, we can ditchax the credits model.
nishanth
parents:
135
diff
changeset
|
473 |
points = data['pynts'] |
93
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
474 |
given_to = User.objects.get(id=uid) |
96
2881ed1c52b0
added events addCredits and assignCredits and modified assign_credits view accordingly.
nishanth
parents:
94
diff
changeset
|
475 |
assignCredits(task=task, given_by=user, given_to=given_to, points=points) |
93
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
476 |
return redirect('/task/assigncredits/tid=%s'%task.id) |
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
477 |
else: |
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
478 |
context['form'] = form |
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
479 |
return render_to_response('task/assigncredits.html', context) |
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
480 |
else: |
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
481 |
return render_to_response('task/assigncredits.html', context) |
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
482 |
else: |
108
131554cc3434
updated show_msg method to also use the user variable in the context.
nishanth
parents:
105
diff
changeset
|
483 |
return show_msg(user, "Credits cannot be assigned at this stage", task_url, "view the task") |
93
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
484 |
else: |
108
131554cc3434
updated show_msg method to also use the user variable in the context.
nishanth
parents:
105
diff
changeset
|
485 |
return show_msg(user, "You are not authorised to perform this action", task_url, "view the task") |
93
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
486 |
|
36
0f10deac0a9b
made urls.py look better and added an empty method edit_task to taskViews .
nishanth
parents:
34
diff
changeset
|
487 |
def edit_task(request, tid): |
0f10deac0a9b
made urls.py look better and added an empty method edit_task to taskViews .
nishanth
parents:
34
diff
changeset
|
488 |
""" see what are the attributes that can be edited depending on the current status |
0f10deac0a9b
made urls.py look better and added an empty method edit_task to taskViews .
nishanth
parents:
34
diff
changeset
|
489 |
and then give the user fields accordingly. |
0f10deac0a9b
made urls.py look better and added an empty method edit_task to taskViews .
nishanth
parents:
34
diff
changeset
|
490 |
""" |
25
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
491 |
|
72 | 492 |
task = Task.objects.get(id=tid) |
141
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
493 |
user = get_user(request.user) if request.user.is_authenticated() else request.user |
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
494 |
|
114 | 495 |
|
496 |
def complete_task(request, tid): |
|
497 |
||
498 |
""" call the event called complete task. |
|
499 |
and also pass it the current user to know who marked it as complete. |
|
500 |
""" |
|
501 |
||
502 |
task_url = "/task/view/tid=%s"%tid |
|
503 |
||
141
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
504 |
user = get_user(request.user) if request.user.is_authenticated() else request.user |
114 | 505 |
task = getTask(tid) |
506 |
||
507 |
is_guest = True if not user.is_authenticated() else False |
|
508 |
is_mentor = True if user in task.mentors.all() else False |
|
509 |
||
510 |
claimed_users = task.claimed_users.all() |
|
511 |
assigned_users = task.assigned_users.all() |
|
512 |
||
513 |
assign_credits_url = '/task/assigncredits/tid=%s'%task.id |
|
514 |
task_assigned_credits = task.credit_set.all() |
|
515 |
||
516 |
||
517 |
if is_mentor: |
|
518 |
if task.status in ["OP", "WR"]: |
|
519 |
||
520 |
context = { |
|
521 |
'user':user, |
|
522 |
'task':task, |
|
523 |
} |
|
524 |
||
525 |
if task_assigned_credits: |
|
526 |
if request.method=="POST": |
|
527 |
completeTask(task, user) |
|
528 |
return redirect(task_url) |
|
529 |
else: |
|
530 |
return render_to_response('task/complete.html', context) |
|
531 |
else: |
|
532 |
return show_msg(user, "Nobody has been credited for doing this task.", assign_credits_url, "assign credits") |
|
533 |
else: |
|
534 |
return show_msg(user, "The task cannot be marked as completed at this stage", task_url, "view the task") |
|
535 |
else: |
|
536 |
return show_msg(user, "You are not authorised to do this", task_url, "view the task") |
|
537 |
||
126 | 538 |
def close_task(request, tid): |
539 |
""" task can be closed only if task is published. |
|
540 |
call the event close task if everything is fine. |
|
541 |
""" |
|
542 |
||
543 |
task_url = "/task/view/tid=%s"%tid |
|
544 |
||
141
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
545 |
user = get_user(request.user) if request.user.is_authenticated() else request.user |
126 | 546 |
task = getTask(tid) |
547 |
||
548 |
is_guest = True if not user.is_authenticated() else False |
|
549 |
is_mentor = True if user in task.mentors.all() else False |
|
550 |
||
551 |
if is_mentor: |
|
552 |
||
553 |
context = { |
|
554 |
'user':user, |
|
555 |
'task':task, |
|
556 |
} |
|
557 |
||
558 |
if not task.status in ["UP", "CD", "DL", "CM"]: |
|
559 |
if request.method == "POST": |
|
560 |
data = request.POST |
|
561 |
if not data.get("reason", None): |
|
562 |
context["error"] = "Please enter a reason for closing the task" |
|
563 |
return render_to_response('task/close.html', context) |
|
564 |
else: |
|
565 |
closeTask(task, user) |
|
566 |
return show_msg(user, "The task has been closed.", task_url, "view the task.") |
|
567 |
else: |
|
568 |
return render_to_response('task/close.html', context) |
|
569 |
else: |
|
570 |
return show_msg(user, "The task is already closed or the task cannot be closed at this stage", task_url, "view the task") |
|
571 |
else: |
|
572 |
return show_msg(user, "You are not authorised to do this", task_url, "view the task") |