author | nishanth |
Thu, 25 Feb 2010 04:38:50 +0530 | |
changeset 92 | c99f09bebe56 |
parent 91 | 1b5ad4b7c40e |
child 93 | 1a1e712e60fd |
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 |
|
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
3 |
from django.http import HttpResponse |
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 |
|
22 | 6 |
from pytask.taskapp.models import User, Task, Comment, Claim |
92
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
7 |
from pytask.taskapp.forms.task import TaskCreateForm, AddMentorForm, AddTaskForm, ChoiceForm |
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
8 |
from pytask.taskapp.events.task import createTask, addMentor, publishTask, addSubTask, addDep, addClaim, assignTask, getTask, updateTask, removeTask |
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
|
9 |
from pytask.taskapp.views.user import show_msg |
17
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
10 |
|
21
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
11 |
## 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
|
12 |
## do not create su user thro syncdb |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
13 |
|
17
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
14 |
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
|
15 |
""" 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
|
16 |
|
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
17 |
user = request.user |
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
18 |
task_list = Task.objects.order_by('id').reverse() |
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
19 |
|
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
20 |
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
|
21 |
'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
|
22 |
} |
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
23 |
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
|
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 |
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
|
26 |
""" 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
|
27 |
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
|
28 |
""" |
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
29 |
|
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
30 |
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
|
31 |
|
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
32 |
user = request.user |
55
ca2486e29178
added a utility called getTask in task events and made changes in task views accordingly
nishanth
parents:
36
diff
changeset
|
33 |
task = getTask(tid) |
17
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
34 |
comments = Comment.objects.filter(task=task) |
21
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
35 |
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
|
36 |
|
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
|
37 |
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
|
38 |
|
17
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
39 |
errors = [] |
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
40 |
|
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
41 |
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
|
42 |
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
|
43 |
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
|
44 |
'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
|
45 |
'comments':comments, |
21
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
46 |
'mentors':mentors, |
66
f670de53402b
modified view task template and view to suit new design.
nishanth
parents:
64
diff
changeset
|
47 |
'subs':subs, |
f670de53402b
modified view task template and view to suit new design.
nishanth
parents:
64
diff
changeset
|
48 |
'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
|
49 |
'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
|
50 |
'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
|
51 |
'errors':errors, |
66
f670de53402b
modified view task template and view to suit new design.
nishanth
parents:
64
diff
changeset
|
52 |
} |
f670de53402b
modified view task template and view to suit new design.
nishanth
parents:
64
diff
changeset
|
53 |
|
f670de53402b
modified view task template and view to suit new design.
nishanth
parents:
64
diff
changeset
|
54 |
context['task_viewable'] = True if ( task.status not in ["UP", "DL"] ) or is_mentor else False |
f670de53402b
modified view task template and view to suit new design.
nishanth
parents:
64
diff
changeset
|
55 |
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
|
56 |
|
f670de53402b
modified view task template and view to suit new design.
nishanth
parents:
64
diff
changeset
|
57 |
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
|
58 |
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
|
59 |
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
|
60 |
|
f670de53402b
modified view task template and view to suit new design.
nishanth
parents:
64
diff
changeset
|
61 |
context['assigned_users'] = task.assigned_users.all() |
64
e743fe1f0f99
updated view task in views to suit the new design .
nishanth
parents:
55
diff
changeset
|
62 |
|
17
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
63 |
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
|
64 |
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
|
65 |
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
|
66 |
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
|
67 |
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
|
68 |
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
|
69 |
else: |
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
70 |
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
|
71 |
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
|
72 |
else: |
aa45fec40e7e
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
nishanth
parents:
diff
changeset
|
73 |
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
|
74 |
|
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
|
75 |
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
|
76 |
""" 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
|
77 |
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
|
78 |
""" |
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
|
79 |
|
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
|
80 |
user = request.user |
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
|
81 |
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
|
82 |
|
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
|
83 |
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
|
84 |
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
|
85 |
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
|
86 |
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
|
87 |
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
|
88 |
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
|
89 |
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
|
90 |
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
|
91 |
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
|
92 |
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
|
93 |
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
|
94 |
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
|
95 |
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
|
96 |
|
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
|
97 |
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
|
98 |
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
|
99 |
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
|
100 |
|
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
|
101 |
addMentor(task, user) |
66
f670de53402b
modified view task template and view to suit new design.
nishanth
parents:
64
diff
changeset
|
102 |
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
|
103 |
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
|
104 |
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
|
105 |
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
|
106 |
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
|
107 |
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
|
108 |
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
|
109 |
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
|
110 |
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
|
111 |
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
|
112 |
return show_msg('You are not authorised to create a 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
|
113 |
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
|
114 |
return show_msg('You are not authorised to create a task.') |
21
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
115 |
|
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
116 |
def add_mentor(request, tid): |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
117 |
""" 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
|
118 |
if user is not authenticated, redirect him to concerned page. """ |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
119 |
|
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
120 |
task_url = "/task/view/tid=%s"%tid |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
121 |
|
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
122 |
user = request.user |
55
ca2486e29178
added a utility called getTask in task events and made changes in task views accordingly
nishanth
parents:
36
diff
changeset
|
123 |
task = getTask(tid) |
21
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
124 |
errors = [] |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
125 |
|
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
126 |
is_guest = True if not user.is_authenticated() else False |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
127 |
|
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
128 |
if (not is_guest) and user in task.mentors.all(): |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
129 |
|
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
130 |
## now iam going for a brute force method |
76 | 131 |
user_list = list(User.objects.filter(is_active=True)) |
21
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
132 |
for mentor in task.mentors.all(): |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
133 |
user_list.remove(mentor) |
34 | 134 |
|
135 |
for a_user in task.claimed_users.all(): |
|
136 |
user_list.remove(a_user) |
|
76 | 137 |
|
138 |
for a_user in task.assigned_users.all(): |
|
139 |
user_list.remove(a_user) |
|
34 | 140 |
|
21
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
141 |
non_mentors = ((_.id,_.username) for _ in user_list) |
34 | 142 |
## code till must be made elegant and not brute force like above |
21
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
143 |
|
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
144 |
form = AddMentorForm(non_mentors) |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
145 |
if request.method == "POST": |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
146 |
uid = request.POST['mentor'] |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
147 |
new_mentor = User.objects.get(id=uid) |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
148 |
addMentor(task, new_mentor) |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
149 |
return redirect(task_url) |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
150 |
else: |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
151 |
return render_to_response('task/addmentor.html', {'form':form, 'errors':errors}) |
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 |
else: |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
154 |
return show_msg('You are not authorised to add mentors for this task', task_url, 'view the task') |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
155 |
|
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
156 |
def add_tasks(request, tid): |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
157 |
""" 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
|
158 |
""" |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
159 |
|
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
160 |
task_url = "/task/view/tid=%s"%tid |
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 |
user = request.user |
55
ca2486e29178
added a utility called getTask in task events and made changes in task views accordingly
nishanth
parents:
36
diff
changeset
|
163 |
task = getTask(tid) |
89
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
164 |
|
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
|
165 |
deps, subs = task.deps, task.subs |
89
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
166 |
is_plain = False if deps or subs else True |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
167 |
|
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
168 |
## again a brute force method |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
169 |
valid_tasks = [] |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
170 |
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
|
171 |
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
|
172 |
valid_tasks.append(a_task) |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
173 |
|
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
174 |
task_choices = [ (_.id,_.title) for _ in valid_tasks ] |
21
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
175 |
errors = [] |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
176 |
|
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
177 |
is_guest = True if not user.is_authenticated() else False |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
178 |
|
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
179 |
if (not is_guest) and user in task.mentors.all(): |
89
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
180 |
if task.status in ["UP", "OP", "LO"]: |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
181 |
form = AddTaskForm(task_choices, is_plain) |
21
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
182 |
if request.method == "POST": |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
183 |
## 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
|
184 |
## only exclude tasks with status deleted |
89
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
185 |
data = request.POST |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
186 |
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
|
187 |
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
|
188 |
|
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
189 |
if not errors: |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
190 |
if is_plain: |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
191 |
update_method = addDep if data['type'] == "D" else addSubTask |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
192 |
elif deps: |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
193 |
update_method = addDep |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
194 |
elif subs: |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
195 |
update_method = addSubTask |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
196 |
else: |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
197 |
print "Screw you" |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
198 |
|
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
199 |
## we might iterate over a task list later on |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
200 |
task_id = data['task'] |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
201 |
sub_or_dep = getTask(task_id) |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
202 |
update_method(task, sub_or_dep) |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
203 |
|
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
204 |
return redirect(task_url) |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
205 |
else: |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
206 |
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
|
207 |
else: |
89
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
208 |
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
|
209 |
else: |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
210 |
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
|
211 |
# return render_to_response('task/add.html', {'form':form, 'errors':errors}) |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
212 |
return show_msg('The task cannot be added subtasks or dependencies now', task_url, 'view the task') |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
213 |
else: |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
214 |
return show_msg('You are not authorised to add subtasks or dependencies for this task', task_url, 'view the task') |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
215 |
|
89
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
216 |
def remove_task(request, tid): |
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
76
diff
changeset
|
217 |
""" display a list of tasks and remove the selectes ones. |
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 |
|
92
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
220 |
task_url = "/task/view/tid=%s"%tid |
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
221 |
|
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
222 |
user = request.user |
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
223 |
task = getTask(tid) |
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
224 |
|
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
225 |
is_guest = True if not user.is_authenticated() else False |
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
226 |
if (not is_guest) and user in task.mentors.all(): |
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
227 |
|
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
228 |
deps, subs = task.deps, task.subs |
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
229 |
task_list = deps if task.sub_type == "D" else subs |
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
230 |
|
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
231 |
if task_list: |
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
232 |
choices = [(_.id,_.title) for _ in task_list ] |
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
233 |
form = ChoiceForm(choices) |
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
234 |
|
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
235 |
errors = [] |
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
236 |
|
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
237 |
if request.method == "POST": |
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
238 |
data = request.POST |
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
239 |
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
|
240 |
if not errors: |
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
241 |
tid = data['choice'] |
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
242 |
sub_task = getTask(tid) |
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
243 |
removeTask(task, sub_task) |
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
244 |
return redirect(task_url) |
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
245 |
else: |
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
246 |
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
|
247 |
else: |
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
248 |
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
|
249 |
else: |
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
250 |
return show_msg("The task has no subtasks/dependencies to be removed", task_url, "view the task") |
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
251 |
else: |
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
252 |
return show_msg("You are not authorised to do this", task_url, "view the task") |
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
253 |
|
21
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
254 |
|
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
255 |
def claim_task(request, tid): |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
256 |
""" 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
|
257 |
|
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
258 |
## 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
|
259 |
## 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
|
260 |
|
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
261 |
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
|
262 |
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
|
263 |
|
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
264 |
errors = [] |
21
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
265 |
|
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
18
diff
changeset
|
266 |
user = request.user |
55
ca2486e29178
added a utility called getTask in task events and made changes in task views accordingly
nishanth
parents:
36
diff
changeset
|
267 |
task = getTask(tid) |
22 | 268 |
claims = Claim.objects.filter(task=task) |
72 | 269 |
|
270 |
mentors = task.mentors.all() |
|
271 |
claimed_users = task.claimed_users.all() |
|
76 | 272 |
assigned_users = task.assigned_users.all() |
22 | 273 |
|
274 |
is_guest = True if not user.is_authenticated() else False |
|
72 | 275 |
is_mentor = True if user in mentors else False |
22 | 276 |
|
72 | 277 |
task_claimable = True if task.status in ["OP", "WR"] else False |
76 | 278 |
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 | 279 |
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
|
280 |
|
72 | 281 |
context = {'user':user, |
282 |
'is_mentor':is_mentor, |
|
25
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
283 |
'task':task, |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
284 |
'claims':claims, |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
285 |
'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
|
286 |
'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
|
287 |
'task_claimed':task_claimed, |
25
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
288 |
'errors':errors} |
22 | 289 |
|
290 |
if not is_guest: |
|
25
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
291 |
if request.method == "POST": |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
292 |
claim_proposal = request.POST['message'] |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
293 |
if claim_proposal: |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
294 |
addClaim(task, claim_proposal, user) |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
295 |
return redirect(claim_url) |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
296 |
else: |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
297 |
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
|
298 |
return render_to_response('task/claim.html', context) |
22 | 299 |
else: |
25
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
300 |
return render_to_response('task/claim.html', context) |
22 | 301 |
else: |
302 |
return show_msg('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
|
303 |
|
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
|
304 |
|
25
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
305 |
def assign_task(request, tid): |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
306 |
""" 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
|
307 |
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
|
308 |
""" |
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
|
309 |
|
25
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
310 |
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
|
311 |
|
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
312 |
user = request.user |
55
ca2486e29178
added a utility called getTask in task events and made changes in task views accordingly
nishanth
parents:
36
diff
changeset
|
313 |
task = getTask(tid) |
25
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
314 |
|
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
315 |
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
|
316 |
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
|
317 |
|
75
fa59955a340b
modified the assign task view to suit the new design
nishanth
parents:
72
diff
changeset
|
318 |
claimed_users = task.claimed_users.all() |
fa59955a340b
modified the assign task view to suit the new design
nishanth
parents:
72
diff
changeset
|
319 |
assigned_users = task.assigned_users.all() |
fa59955a340b
modified the assign task view to suit the new design
nishanth
parents:
72
diff
changeset
|
320 |
|
fa59955a340b
modified the assign task view to suit the new design
nishanth
parents:
72
diff
changeset
|
321 |
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
|
322 |
|
25
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
323 |
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
|
324 |
if task_claimed: |
75
fa59955a340b
modified the assign task view to suit the new design
nishanth
parents:
72
diff
changeset
|
325 |
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
|
326 |
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
|
327 |
|
25
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
328 |
if request.method == "POST": |
92
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
91
diff
changeset
|
329 |
uid = request.POST['choice'] |
25
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
330 |
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
|
331 |
assignTask(task, assigned_user) |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
332 |
return redirect(task_url) |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
333 |
else: |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
334 |
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
|
335 |
elif assigned_users: |
fa59955a340b
modified the assign task view to suit the new design
nishanth
parents:
72
diff
changeset
|
336 |
return show_msg('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
|
337 |
else: |
75
fa59955a340b
modified the assign task view to suit the new design
nishanth
parents:
72
diff
changeset
|
338 |
return show_msg('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
|
339 |
else: |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
340 |
return show_msg('You are not authorised to perform this action', task_url, 'view the task') |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
341 |
|
36
0f10deac0a9b
made urls.py look better and added an empty method edit_task to taskViews .
nishanth
parents:
34
diff
changeset
|
342 |
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
|
343 |
""" 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
|
344 |
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
|
345 |
""" |
25
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
22
diff
changeset
|
346 |
|
72 | 347 |
task = Task.objects.get(id=tid) |