author | nishanth |
Tue, 02 Mar 2010 14:46:05 +0530 | |
changeset 174 | d034cd77cfa6 |
parent 167 | b61e45074ba1 |
child 176 | 13ceb76fd0a3 |
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 |
|
156 | 6 |
from pytask.taskapp.models import User, Task, Comment, Claim, Request, Notification |
120 | 7 |
from pytask.taskapp.utilities.task import getTask |
165 | 8 |
from pytask.taskapp.forms.task import TaskCreateForm, AddMentorForm, AddTaskForm, ChoiceForm, AssignCreditForm, RemoveUserForm, EditTaskForm |
167 | 9 |
from pytask.taskapp.events.task import createTask, reqMentor, publishTask, addSubTask, addDep, addClaim, assignTask, updateTask, removeTask, removeUser, assignCredits, completeTask, closeTask, addMentor, deleteTask |
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') |
|
155
52958289d81f
now if a task has subs, it will remain locked forever.
nishanth
parents:
154
diff
changeset
|
66 |
comments = task.comment_set.filter(is_deleted=False).order_by('creation_datetime') |
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 |
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
|
72 |
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
|
73 |
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
|
74 |
'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
|
75 |
'comments':comments, |
21
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
76 |
'mentors':mentors, |
66
f670de53402b
modified view task template and view to suit new design.
nishanth
parents:
64
diff
changeset
|
77 |
'subs':subs, |
f670de53402b
modified view task template and view to suit new design.
nishanth
parents:
64
diff
changeset
|
78 |
'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
|
79 |
'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
|
80 |
'is_mentor':is_mentor, |
66
f670de53402b
modified view task template and view to suit new design.
nishanth
parents:
64
diff
changeset
|
81 |
} |
f670de53402b
modified view task template and view to suit new design.
nishanth
parents:
64
diff
changeset
|
82 |
|
160
05157d35d66f
imposed a constraint that edit_task url is not displayed if task is OP and has claimed_users.
nishanth
parents:
159
diff
changeset
|
83 |
claimed_users = task.claimed_users.all() |
05157d35d66f
imposed a constraint that edit_task url is not displayed if task is OP and has claimed_users.
nishanth
parents:
159
diff
changeset
|
84 |
|
156 | 85 |
context['task_viewable'] = True if ( task.status != "UP" ) or is_mentor else False |
86 |
||
111 | 87 |
context['can_publish'] = True if task.status == "UP" and user == task.created_by else False |
167 | 88 |
context['can_edit'] = True if task.status == "UP" and is_mentor else False |
156 | 89 |
context['can_close'] = True if task.status not in ["UP", "CD", "CM"] and is_mentor else False |
167 | 90 |
context['can_delete'] = True if task.status == "UP" and user == task.created_by else False |
66
f670de53402b
modified view task template and view to suit new design.
nishanth
parents:
64
diff
changeset
|
91 |
|
f670de53402b
modified view task template and view to suit new design.
nishanth
parents:
64
diff
changeset
|
92 |
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
|
93 |
context['can_mod_tasks'] = True if task.status in ["UP", "OP", "LO"] and is_mentor else False |
156 | 94 |
|
66
f670de53402b
modified view task template and view to suit new design.
nishanth
parents:
64
diff
changeset
|
95 |
context['can_assign_credits'] = True if task.status in ["OP", "WR"] and is_mentor else False |
156 | 96 |
context['task_claimable'] = True if task.status in ["OP", "WR"] and not is_guest else False |
97 |
||
98 |
if task.status == "CD": |
|
99 |
context['closing_notification'] = Notification.objects.filter(task=task,role="CD")[0] |
|
100 |
elif task.status == "CM": |
|
101 |
context['completed_notification'] = Notifications.objects.filter(task=task,role="CM")[0] |
|
102 |
elif task.status == "WR": |
|
103 |
context['assigned_users'] = task.assigned_users.all() |
|
64
e743fe1f0f99
updated view task in views to suit the new design .
nishanth
parents:
55
diff
changeset
|
104 |
|
17
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
105 |
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
|
106 |
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
|
107 |
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
|
108 |
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
|
109 |
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
|
110 |
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
|
111 |
else: |
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
112 |
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
|
113 |
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
|
114 |
else: |
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
115 |
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
|
116 |
|
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 |
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
|
118 |
""" 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
|
119 |
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
|
120 |
""" |
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 |
|
141
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
122 |
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
|
123 |
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
|
124 |
|
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 |
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
|
126 |
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
|
127 |
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
|
128 |
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
|
129 |
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
|
130 |
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
|
131 |
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
|
132 |
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
|
133 |
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
|
134 |
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
|
135 |
credits = data['credits'] |
166 | 136 |
#publish = data['publish'] # just in case if we have to show the option |
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
|
137 |
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
|
138 |
|
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 |
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
|
140 |
error_msg = "Another task with the same title exists" |
165 | 141 |
return render_to_response('task/create.html',{'user':user, 'form':form, 'error_msg':error_msg}) |
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
|
142 |
|
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 |
addMentor(task, user) |
66
f670de53402b
modified view task template and view to suit new design.
nishanth
parents:
64
diff
changeset
|
144 |
updateTask(task,tags_field=data['tags_field']) |
165 | 145 |
# if publish: publishTask(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 |
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
|
147 |
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
|
148 |
else: |
165 | 149 |
return render_to_response('task/create.html',{'user':user, 'form':form}) |
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
|
150 |
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
|
151 |
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
|
152 |
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
|
153 |
else: |
108
131554cc3434
updated show_msg method to also use the user variable in the context.
nishanth
parents:
105
diff
changeset
|
154 |
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
|
155 |
else: |
108
131554cc3434
updated show_msg method to also use the user variable in the context.
nishanth
parents:
105
diff
changeset
|
156 |
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
|
157 |
|
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
158 |
def add_mentor(request, tid): |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
159 |
""" 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
|
160 |
if user is not authenticated, redirect him to concerned page. """ |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
161 |
|
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
162 |
task_url = "/task/view/tid=%s"%tid |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
163 |
|
141
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
164 |
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
|
165 |
task = getTask(tid) |
21
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
166 |
errors = [] |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
167 |
|
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
168 |
is_guest = True if not user.is_authenticated() else False |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
169 |
|
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
170 |
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
|
171 |
|
3395960549e8
now a user cannot make two requests to another user for mentoring a task.
nishanth
parents:
141
diff
changeset
|
172 |
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
|
173 |
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
|
174 |
|
21
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
175 |
## now iam going for a brute force method |
76 | 176 |
user_list = list(User.objects.filter(is_active=True)) |
21
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
177 |
for mentor in task.mentors.all(): |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
178 |
user_list.remove(mentor) |
34 | 179 |
|
180 |
for a_user in task.claimed_users.all(): |
|
181 |
user_list.remove(a_user) |
|
76 | 182 |
|
183 |
for a_user in task.assigned_users.all(): |
|
184 |
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
|
185 |
|
3395960549e8
now a user cannot make two requests to another user for mentoring a task.
nishanth
parents:
141
diff
changeset
|
186 |
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
|
187 |
user_list.remove(req.sent_to.all()[0]) |
34 | 188 |
|
151
d0cb85ba462a
no bogus post request can be made now in addmentor page.
nishanth
parents:
149
diff
changeset
|
189 |
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
|
190 |
non_mentor_ids = [ str(a_user.id) for a_user in user_list ] |
34 | 191 |
## 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
|
192 |
|
21
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
193 |
form = AddMentorForm(non_mentors) |
151
d0cb85ba462a
no bogus post request can be made now in addmentor page.
nishanth
parents:
149
diff
changeset
|
194 |
|
d0cb85ba462a
no bogus post request can be made now in addmentor page.
nishanth
parents:
149
diff
changeset
|
195 |
context = { |
d0cb85ba462a
no bogus post request can be made now in addmentor page.
nishanth
parents:
149
diff
changeset
|
196 |
'user':user, |
156 | 197 |
'task':task, |
151
d0cb85ba462a
no bogus post request can be made now in addmentor page.
nishanth
parents:
149
diff
changeset
|
198 |
'pending_requests':pending_requests, |
d0cb85ba462a
no bogus post request can be made now in addmentor page.
nishanth
parents:
149
diff
changeset
|
199 |
'form':form, |
d0cb85ba462a
no bogus post request can be made now in addmentor page.
nishanth
parents:
149
diff
changeset
|
200 |
} |
d0cb85ba462a
no bogus post request can be made now in addmentor page.
nishanth
parents:
149
diff
changeset
|
201 |
|
21
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
202 |
if request.method == "POST": |
151
d0cb85ba462a
no bogus post request can be made now in addmentor page.
nishanth
parents:
149
diff
changeset
|
203 |
data = request.POST |
d0cb85ba462a
no bogus post request can be made now in addmentor page.
nishanth
parents:
149
diff
changeset
|
204 |
uid = data.get('mentor', None) |
d0cb85ba462a
no bogus post request can be made now in addmentor page.
nishanth
parents:
149
diff
changeset
|
205 |
if uid in non_mentor_ids: |
d0cb85ba462a
no bogus post request can be made now in addmentor page.
nishanth
parents:
149
diff
changeset
|
206 |
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
|
207 |
reqMentor(task, new_mentor, user) |
d0cb85ba462a
no bogus post request can be made now in addmentor page.
nishanth
parents:
149
diff
changeset
|
208 |
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
|
209 |
else: |
d0cb85ba462a
no bogus post request can be made now in addmentor page.
nishanth
parents:
149
diff
changeset
|
210 |
## bogus post request |
d0cb85ba462a
no bogus post request can be made now in addmentor page.
nishanth
parents:
149
diff
changeset
|
211 |
raise Http404 |
21
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
212 |
else: |
151
d0cb85ba462a
no bogus post request can be made now in addmentor page.
nishanth
parents:
149
diff
changeset
|
213 |
return render_to_response('task/addmentor.html', context) |
21
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
214 |
else: |
108
131554cc3434
updated show_msg method to also use the user variable in the context.
nishanth
parents:
105
diff
changeset
|
215 |
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
|
216 |
|
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
217 |
def add_tasks(request, tid): |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
218 |
""" 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
|
219 |
""" |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
220 |
|
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
221 |
task_url = "/task/view/tid=%s"%tid |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
222 |
|
141
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
223 |
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
|
224 |
task = getTask(tid) |
89
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
225 |
|
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
|
226 |
deps, subs = task.deps, task.subs |
89
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
227 |
is_plain = False if deps or subs else True |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
228 |
|
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
229 |
## again a brute force method |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
230 |
valid_tasks = [] |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
231 |
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
|
232 |
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
|
233 |
valid_tasks.append(a_task) |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
234 |
|
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
235 |
task_choices = [ (_.id,_.title) for _ in valid_tasks ] |
21
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
236 |
errors = [] |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
237 |
|
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
238 |
is_guest = True if not user.is_authenticated() else False |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
239 |
|
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
240 |
if (not is_guest) and user in task.mentors.all(): |
89
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
241 |
if task.status in ["UP", "OP", "LO"]: |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
242 |
form = AddTaskForm(task_choices, is_plain) |
21
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
243 |
if request.method == "POST": |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
244 |
## 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
|
245 |
## only exclude tasks with status deleted |
89
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
246 |
data = request.POST |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
247 |
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
|
248 |
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
|
249 |
|
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
250 |
if not errors: |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
251 |
if is_plain: |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
252 |
update_method = addDep if data['type'] == "D" else addSubTask |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
253 |
elif deps: |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
254 |
update_method = addDep |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
255 |
elif subs: |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
256 |
update_method = addSubTask |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
257 |
else: |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
258 |
print "Screw you" |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
259 |
|
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
260 |
## we might iterate over a task list later on |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
261 |
task_id = data['task'] |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
262 |
sub_or_dep = getTask(task_id) |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
263 |
update_method(task, sub_or_dep) |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
264 |
|
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
265 |
return redirect(task_url) |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
266 |
else: |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
267 |
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
|
268 |
else: |
89
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
269 |
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
|
270 |
else: |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
271 |
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
|
272 |
# 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
|
273 |
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
|
274 |
else: |
108
131554cc3434
updated show_msg method to also use the user variable in the context.
nishanth
parents:
105
diff
changeset
|
275 |
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
|
276 |
|
89
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
277 |
def remove_task(request, tid): |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
278 |
""" display a list of tasks and remove the selectes ones. |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
279 |
""" |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
280 |
|
92
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
281 |
task_url = "/task/view/tid=%s"%tid |
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
282 |
|
141
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
283 |
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
|
284 |
task = getTask(tid) |
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 |
is_guest = True if not user.is_authenticated() else False |
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
287 |
if (not is_guest) and user in task.mentors.all(): |
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
288 |
|
159 | 289 |
if task.status in ["UP", "LO", "OP"]: |
290 |
||
291 |
deps, subs = task.deps, task.subs |
|
292 |
task_list = deps if task.sub_type == "D" else subs |
|
92
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
293 |
|
159 | 294 |
if task_list: |
295 |
choices = [(_.id,_.title) for _ in task_list ] |
|
296 |
form = ChoiceForm(choices) |
|
92
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
297 |
|
159 | 298 |
errors = [] |
299 |
||
300 |
context = { |
|
301 |
'user':user, |
|
302 |
'task':task, |
|
303 |
'form':form, |
|
304 |
} |
|
92
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
305 |
|
159 | 306 |
if request.method == "POST": |
307 |
data = request.POST |
|
308 |
if not data.get('choice', None): |
|
309 |
errors.append("Please choose a task to remove.") |
|
310 |
context['errors'] = errors |
|
311 |
if not errors: |
|
312 |
tid = data['choice'] |
|
313 |
sub_task = getTask(tid) |
|
314 |
removeTask(task, sub_task) |
|
315 |
return redirect(task_url) |
|
316 |
else: |
|
317 |
return render_to_response('task/removetask.html', context) |
|
92
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
318 |
else: |
159 | 319 |
return render_to_response('task/removetask.html', context) |
92
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
320 |
else: |
159 | 321 |
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
|
322 |
else: |
159 | 323 |
return show_msg(user, "subtasks/dependencies cannot be removed at this stage", task_url, "view the task") |
92
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
324 |
else: |
108
131554cc3434
updated show_msg method to also use the user variable in the context.
nishanth
parents:
105
diff
changeset
|
325 |
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
|
326 |
|
21
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
327 |
def claim_task(request, tid): |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
328 |
""" 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
|
329 |
|
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
330 |
## 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
|
331 |
## 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
|
332 |
|
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
333 |
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
|
334 |
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
|
335 |
|
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
336 |
errors = [] |
21
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
337 |
|
141
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
338 |
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
|
339 |
task = getTask(tid) |
22 | 340 |
claims = Claim.objects.filter(task=task) |
72 | 341 |
|
342 |
mentors = task.mentors.all() |
|
343 |
claimed_users = task.claimed_users.all() |
|
76 | 344 |
assigned_users = task.assigned_users.all() |
22 | 345 |
|
346 |
is_guest = True if not user.is_authenticated() else False |
|
72 | 347 |
is_mentor = True if user in mentors else False |
22 | 348 |
|
72 | 349 |
task_claimable = True if task.status in ["OP", "WR"] else False |
76 | 350 |
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 | 351 |
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
|
352 |
|
72 | 353 |
context = {'user':user, |
354 |
'is_mentor':is_mentor, |
|
25
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
355 |
'task':task, |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
356 |
'claims':claims, |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
357 |
'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
|
358 |
'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
|
359 |
'task_claimed':task_claimed, |
25
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
360 |
'errors':errors} |
22 | 361 |
|
362 |
if not is_guest: |
|
25
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
363 |
if request.method == "POST": |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
364 |
claim_proposal = request.POST['message'] |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
365 |
if claim_proposal: |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
366 |
addClaim(task, claim_proposal, user) |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
367 |
return redirect(claim_url) |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
368 |
else: |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
369 |
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
|
370 |
return render_to_response('task/claim.html', context) |
22 | 371 |
else: |
25
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
372 |
return render_to_response('task/claim.html', context) |
22 | 373 |
else: |
108
131554cc3434
updated show_msg method to also use the user variable in the context.
nishanth
parents:
105
diff
changeset
|
374 |
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
|
375 |
|
94 | 376 |
def rem_user(request, tid): |
377 |
""" show a list of working users and ask for a message/reason for removing user. |
|
378 |
""" |
|
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
|
379 |
|
94 | 380 |
task_url = "/task/view/tid=%s"%tid |
381 |
||
141
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
382 |
user = get_user(request.user) if request.user.is_authenticated() else request.user |
94 | 383 |
task = getTask(tid) |
384 |
||
385 |
is_guest = True if not user.is_authenticated() else False |
|
386 |
is_mentor = True if user in task.mentors.all() else False |
|
387 |
||
388 |
if (not is_guest) and is_mentor: |
|
389 |
||
390 |
assigned_users = task.assigned_users.all() |
|
391 |
choices = [ (_.id,_.username) for _ in assigned_users ] |
|
392 |
context = { |
|
393 |
'user':user, |
|
394 |
'task':task, |
|
395 |
} |
|
158
c43e0114e593
removing user deletes all the pending requests that request giving him pynts.
nishanth
parents:
157
diff
changeset
|
396 |
|
162 | 397 |
if task.status in ["WR"]: |
158
c43e0114e593
removing user deletes all the pending requests that request giving him pynts.
nishanth
parents:
157
diff
changeset
|
398 |
if assigned_users: |
c43e0114e593
removing user deletes all the pending requests that request giving him pynts.
nishanth
parents:
157
diff
changeset
|
399 |
form = RemoveUserForm(choices) |
c43e0114e593
removing user deletes all the pending requests that request giving him pynts.
nishanth
parents:
157
diff
changeset
|
400 |
context['form'] = form |
c43e0114e593
removing user deletes all the pending requests that request giving him pynts.
nishanth
parents:
157
diff
changeset
|
401 |
if request.method == "POST": |
c43e0114e593
removing user deletes all the pending requests that request giving him pynts.
nishanth
parents:
157
diff
changeset
|
402 |
data = request.POST |
c43e0114e593
removing user deletes all the pending requests that request giving him pynts.
nishanth
parents:
157
diff
changeset
|
403 |
form = RemoveUserForm(choices, data) |
c43e0114e593
removing user deletes all the pending requests that request giving him pynts.
nishanth
parents:
157
diff
changeset
|
404 |
if form.is_valid(): |
c43e0114e593
removing user deletes all the pending requests that request giving him pynts.
nishanth
parents:
157
diff
changeset
|
405 |
data = form.cleaned_data |
c43e0114e593
removing user deletes all the pending requests that request giving him pynts.
nishanth
parents:
157
diff
changeset
|
406 |
uid = data['user'] |
c43e0114e593
removing user deletes all the pending requests that request giving him pynts.
nishanth
parents:
157
diff
changeset
|
407 |
reason = data['reason'] |
c43e0114e593
removing user deletes all the pending requests that request giving him pynts.
nishanth
parents:
157
diff
changeset
|
408 |
rem_user = User.objects.get(id=uid) |
c43e0114e593
removing user deletes all the pending requests that request giving him pynts.
nishanth
parents:
157
diff
changeset
|
409 |
removeUser(task, rem_user, user, reason) |
c43e0114e593
removing user deletes all the pending requests that request giving him pynts.
nishanth
parents:
157
diff
changeset
|
410 |
return redirect(task_url) |
c43e0114e593
removing user deletes all the pending requests that request giving him pynts.
nishanth
parents:
157
diff
changeset
|
411 |
else: |
c43e0114e593
removing user deletes all the pending requests that request giving him pynts.
nishanth
parents:
157
diff
changeset
|
412 |
context['form'] = form |
c43e0114e593
removing user deletes all the pending requests that request giving him pynts.
nishanth
parents:
157
diff
changeset
|
413 |
return render_to_response('task/remove_user.html', context) |
94 | 414 |
else: |
158
c43e0114e593
removing user deletes all the pending requests that request giving him pynts.
nishanth
parents:
157
diff
changeset
|
415 |
return render_to_response('task/remove_user.html',context) |
94 | 416 |
else: |
158
c43e0114e593
removing user deletes all the pending requests that request giving him pynts.
nishanth
parents:
157
diff
changeset
|
417 |
return show_msg(user, "There is no one working on this task to be kicked off", task_url, "view the task") |
94 | 418 |
else: |
158
c43e0114e593
removing user deletes all the pending requests that request giving him pynts.
nishanth
parents:
157
diff
changeset
|
419 |
return show_msg(user, "This is not the stage to remove users", task_url, "view the task") |
94 | 420 |
else: |
108
131554cc3434
updated show_msg method to also use the user variable in the context.
nishanth
parents:
105
diff
changeset
|
421 |
return show_msg(user, "You are not authorised to do this", task_url, "view the task") |
94 | 422 |
|
25
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
423 |
def assign_task(request, tid): |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
424 |
""" 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
|
425 |
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
|
426 |
""" |
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
|
427 |
|
25
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
428 |
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
|
429 |
|
141
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
430 |
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
|
431 |
task = getTask(tid) |
25
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
432 |
|
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
433 |
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
|
434 |
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
|
435 |
|
75
fa59955a340b
modified the assign task view to suit the new design
nishanth
parents:
72
diff
changeset
|
436 |
claimed_users = task.claimed_users.all() |
fa59955a340b
modified the assign task view to suit the new design
nishanth
parents:
72
diff
changeset
|
437 |
assigned_users = task.assigned_users.all() |
fa59955a340b
modified the assign task view to suit the new design
nishanth
parents:
72
diff
changeset
|
438 |
|
fa59955a340b
modified the assign task view to suit the new design
nishanth
parents:
72
diff
changeset
|
439 |
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
|
440 |
|
25
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
441 |
if (not is_guest) and is_mentor: |
157
65d5e9737d1c
fixed assign_task method to display a not_allowed message if task status not in OP WR.
nishanth
parents:
156
diff
changeset
|
442 |
if task.status in ["OP", "WR"]: |
65d5e9737d1c
fixed assign_task method to display a not_allowed message if task status not in OP WR.
nishanth
parents:
156
diff
changeset
|
443 |
if task_claimed: |
65d5e9737d1c
fixed assign_task method to display a not_allowed message if task status not in OP WR.
nishanth
parents:
156
diff
changeset
|
444 |
user_list = ((user.id,user.username) for user in claimed_users) |
65d5e9737d1c
fixed assign_task method to display a not_allowed message if task status not in OP WR.
nishanth
parents:
156
diff
changeset
|
445 |
form = ChoiceForm(user_list) |
65d5e9737d1c
fixed assign_task method to display a not_allowed message if task status not in OP WR.
nishanth
parents:
156
diff
changeset
|
446 |
|
65d5e9737d1c
fixed assign_task method to display a not_allowed message if task status not in OP WR.
nishanth
parents:
156
diff
changeset
|
447 |
if request.method == "POST": |
65d5e9737d1c
fixed assign_task method to display a not_allowed message if task status not in OP WR.
nishanth
parents:
156
diff
changeset
|
448 |
uid = request.POST['choice'] |
65d5e9737d1c
fixed assign_task method to display a not_allowed message if task status not in OP WR.
nishanth
parents:
156
diff
changeset
|
449 |
assigned_user = User.objects.get(id=uid) |
65d5e9737d1c
fixed assign_task method to display a not_allowed message if task status not in OP WR.
nishanth
parents:
156
diff
changeset
|
450 |
assignTask(task, assigned_user, user) |
65d5e9737d1c
fixed assign_task method to display a not_allowed message if task status not in OP WR.
nishanth
parents:
156
diff
changeset
|
451 |
return redirect(task_url) |
65d5e9737d1c
fixed assign_task method to display a not_allowed message if task status not in OP WR.
nishanth
parents:
156
diff
changeset
|
452 |
else: |
65d5e9737d1c
fixed assign_task method to display a not_allowed message if task status not in OP WR.
nishanth
parents:
156
diff
changeset
|
453 |
return render_to_response('task/assign.html',{'user':user, 'task':task,'form':form}) |
65d5e9737d1c
fixed assign_task method to display a not_allowed message if task status not in OP WR.
nishanth
parents:
156
diff
changeset
|
454 |
elif assigned_users: |
65d5e9737d1c
fixed assign_task method to display a not_allowed message if task status not in OP WR.
nishanth
parents:
156
diff
changeset
|
455 |
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
|
456 |
else: |
157
65d5e9737d1c
fixed assign_task method to display a not_allowed message if task status not in OP WR.
nishanth
parents:
156
diff
changeset
|
457 |
return show_msg(user, 'Wait for ppl to claim dude... slow and steady wins the race :)', task_url, 'view the task') |
65d5e9737d1c
fixed assign_task method to display a not_allowed message if task status not in OP WR.
nishanth
parents:
156
diff
changeset
|
458 |
else: |
65d5e9737d1c
fixed assign_task method to display a not_allowed message if task status not in OP WR.
nishanth
parents:
156
diff
changeset
|
459 |
return show_msg(user, "The task cannot be assigned to users at this stage", 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
|
460 |
else: |
108
131554cc3434
updated show_msg method to also use the user variable in the context.
nishanth
parents:
105
diff
changeset
|
461 |
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
|
462 |
|
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
463 |
def assign_credits(request, tid): |
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
464 |
""" 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
|
465 |
Then display all the approved credits. |
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
466 |
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
|
467 |
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
|
468 |
""" |
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
469 |
|
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
470 |
task_url = "/task/view/tid=%s"%tid |
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
471 |
|
141
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
472 |
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
|
473 |
task = getTask(tid) |
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
474 |
|
157
65d5e9737d1c
fixed assign_task method to display a not_allowed message if task status not in OP WR.
nishanth
parents:
156
diff
changeset
|
475 |
## the moment we see that user had requested credits, it means he had worked and hence we change the status to WR |
158
c43e0114e593
removing user deletes all the pending requests that request giving him pynts.
nishanth
parents:
157
diff
changeset
|
476 |
## we have to discuss on this since, credits may also be given to mentor |
157
65d5e9737d1c
fixed assign_task method to display a not_allowed message if task status not in OP WR.
nishanth
parents:
156
diff
changeset
|
477 |
task.status = "WR" |
65d5e9737d1c
fixed assign_task method to display a not_allowed message if task status not in OP WR.
nishanth
parents:
156
diff
changeset
|
478 |
task.save() |
65d5e9737d1c
fixed assign_task method to display a not_allowed message if task status not in OP WR.
nishanth
parents:
156
diff
changeset
|
479 |
|
93
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
480 |
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
|
481 |
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
|
482 |
|
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
483 |
if is_mentor: |
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
484 |
if task.status in ["OP", "WR"]: |
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
485 |
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
|
486 |
if task.status == "WR": |
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
487 |
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
|
488 |
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
|
489 |
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
|
490 |
form = AssignCreditForm(choices) |
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
491 |
|
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
492 |
context = { |
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
493 |
'user':user, |
96
2881ed1c52b0
added events addCredits and assignCredits and modified assign_credits view accordingly.
nishanth
parents:
94
diff
changeset
|
494 |
'task':task, |
93
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
495 |
'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
|
496 |
'credit_requests':credit_requests, |
93
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
497 |
'form':form, |
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
498 |
} |
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
499 |
|
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
500 |
if request.method == "POST": |
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
501 |
data = request.POST |
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
502 |
form = AssignCreditForm(choices, data) |
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
503 |
if form.is_valid(): |
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
504 |
data = form.cleaned_data |
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
505 |
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
|
506 |
points = data['pynts'] |
93
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
507 |
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
|
508 |
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
|
509 |
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
|
510 |
else: |
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
511 |
context['form'] = form |
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
512 |
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
|
513 |
else: |
1a1e712e60fd
finished assign_credits view. hav to integrate it with requests now.
nishanth
parents:
92
diff
changeset
|
514 |
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
|
515 |
else: |
108
131554cc3434
updated show_msg method to also use the user variable in the context.
nishanth
parents:
105
diff
changeset
|
516 |
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
|
517 |
else: |
108
131554cc3434
updated show_msg method to also use the user variable in the context.
nishanth
parents:
105
diff
changeset
|
518 |
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
|
519 |
|
36
0f10deac0a9b
made urls.py look better and added an empty method edit_task to taskViews .
nishanth
parents:
34
diff
changeset
|
520 |
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
|
521 |
""" 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
|
522 |
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
|
523 |
""" |
25
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
524 |
|
165 | 525 |
task = Task.objects.get(id=tid) |
526 |
task_url = "/task/view/tid=%s"%tid |
|
141
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
527 |
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
|
528 |
|
165 | 529 |
is_mentor = True if user in task.mentors.all() else False |
530 |
can_edit = True if is_mentor and task.status == "UP" else False |
|
531 |
||
532 |
if can_edit: |
|
533 |
form = EditTaskForm(task) |
|
534 |
if request.method=="POST": |
|
535 |
data = request.POST |
|
536 |
form = EditTaskForm(task, data) |
|
537 |
if form.is_valid(): |
|
538 |
data = form.cleaned_data |
|
539 |
title = data['title'] |
|
540 |
try: |
|
166 | 541 |
prev_task = Task.objects.exclude(status="DL").get(title=title) |
165 | 542 |
if prev_task != task: |
543 |
error_msg = "Another task exists with the same title" |
|
544 |
return render_to_response('task/edittask.html',{'user':user, 'form':form, 'error_msg':error_msg}) |
|
545 |
except Task.DoesNotExist: |
|
546 |
pass |
|
547 |
task.title = title |
|
548 |
task.desc = data['desc'] |
|
549 |
task.tags_field = data['tags_field'] |
|
550 |
task.credits = data['credits'] |
|
551 |
task.save() |
|
552 |
return redirect(task_url) |
|
553 |
else: |
|
554 |
return render_to_response('task/edittask.html',{'user':user, 'form':form}) |
|
555 |
else: |
|
556 |
return render_to_response('task/edittask.html',{'user':user, 'form':form}) |
|
557 |
else: |
|
558 |
return show_msg(user, "You cannot edit the task at this stage", task_url, "view the task") |
|
559 |
||
114 | 560 |
def complete_task(request, tid): |
561 |
""" call the event called complete task. |
|
562 |
and also pass it the current user to know who marked it as complete. |
|
563 |
""" |
|
564 |
||
565 |
task_url = "/task/view/tid=%s"%tid |
|
566 |
||
141
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
567 |
user = get_user(request.user) if request.user.is_authenticated() else request.user |
114 | 568 |
task = getTask(tid) |
569 |
||
570 |
is_guest = True if not user.is_authenticated() else False |
|
571 |
is_mentor = True if user in task.mentors.all() else False |
|
572 |
||
573 |
claimed_users = task.claimed_users.all() |
|
574 |
assigned_users = task.assigned_users.all() |
|
575 |
||
576 |
assign_credits_url = '/task/assigncredits/tid=%s'%task.id |
|
577 |
task_assigned_credits = task.credit_set.all() |
|
578 |
||
579 |
||
580 |
if is_mentor: |
|
581 |
if task.status in ["OP", "WR"]: |
|
582 |
||
583 |
context = { |
|
584 |
'user':user, |
|
585 |
'task':task, |
|
586 |
} |
|
587 |
||
588 |
if task_assigned_credits: |
|
589 |
if request.method=="POST": |
|
590 |
completeTask(task, user) |
|
591 |
return redirect(task_url) |
|
592 |
else: |
|
593 |
return render_to_response('task/complete.html', context) |
|
594 |
else: |
|
595 |
return show_msg(user, "Nobody has been credited for doing this task.", assign_credits_url, "assign credits") |
|
596 |
else: |
|
597 |
return show_msg(user, "The task cannot be marked as completed at this stage", task_url, "view the task") |
|
598 |
else: |
|
599 |
return show_msg(user, "You are not authorised to do this", task_url, "view the task") |
|
600 |
||
126 | 601 |
def close_task(request, tid): |
602 |
""" task can be closed only if task is published. |
|
603 |
call the event close task if everything is fine. |
|
604 |
""" |
|
605 |
||
606 |
task_url = "/task/view/tid=%s"%tid |
|
607 |
||
141
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
138
diff
changeset
|
608 |
user = get_user(request.user) if request.user.is_authenticated() else request.user |
126 | 609 |
task = getTask(tid) |
610 |
||
611 |
is_guest = True if not user.is_authenticated() else False |
|
612 |
is_mentor = True if user in task.mentors.all() else False |
|
613 |
||
614 |
if is_mentor: |
|
615 |
||
616 |
context = { |
|
617 |
'user':user, |
|
618 |
'task':task, |
|
619 |
} |
|
620 |
||
621 |
if not task.status in ["UP", "CD", "DL", "CM"]: |
|
622 |
if request.method == "POST": |
|
623 |
data = request.POST |
|
624 |
if not data.get("reason", None): |
|
625 |
context["error"] = "Please enter a reason for closing the task" |
|
626 |
return render_to_response('task/close.html', context) |
|
627 |
else: |
|
153 | 628 |
closeTask(task, user, data['reason']) |
126 | 629 |
return show_msg(user, "The task has been closed.", task_url, "view the task.") |
630 |
else: |
|
631 |
return render_to_response('task/close.html', context) |
|
632 |
else: |
|
159 | 633 |
return show_msg(user, "The task is either already closed or cannot be closed at this stage", task_url, "view the task") |
126 | 634 |
else: |
635 |
return show_msg(user, "You are not authorised to do this", task_url, "view the task") |
|
167 | 636 |
|
637 |
||
638 |
def delete_task(request, tid): |
|
639 |
""" mark the task status as DL. |
|
640 |
take a reason from the user and pass on to all the other mentors. |
|
641 |
""" |
|
642 |
||
643 |
task_url = "/task/view/tid=%s"%tid |
|
644 |
||
645 |
task = getTask(tid) |
|
646 |
user = get_user(request.user) if request.user.is_authenticated() else request.user |
|
647 |
||
648 |
if task.status == "DL": |
|
649 |
return show_msg(user, "This task no longer exists", '/task/browse/', "to browse other tasks") |
|
650 |
||
651 |
can_delete = True if task.status == "UP" and task.created_by == user else False |
|
652 |
||
653 |
if can_delete: |
|
654 |
if request.method == "POST": |
|
655 |
data = request.POST |
|
656 |
reason = data.get('reason', None) |
|
657 |
deleteTask(task, user, reason) |
|
658 |
return show_msg(user, "The task is deleted", '/', "to return to home page") |
|
659 |
else: |
|
660 |
return render_to_response('task/delete.html',{'user':user,}) |
|
661 |
else: |
|
662 |
return show_msg(user, "You are not authorised to do this at this stage", task_url, "view the task") |