1 from datetime import datetime |
1 from datetime import datetime |
2 |
2 |
3 from django.http import HttpResponse |
3 from django.http import HttpResponse |
4 from django.shortcuts import render_to_response, redirect |
4 from django.shortcuts import render_to_response, redirect |
5 |
5 |
6 from pytask.taskapp.models import Task, Comment |
6 from pytask.taskapp.models import User, Task, Comment |
7 from pytask.taskapp.forms.task import TaskCreateForm |
7 from pytask.taskapp.forms.task import TaskCreateForm, AddMentorForm |
8 from pytask.taskapp.events.task import createTask, addMentor, publishTask |
8 from pytask.taskapp.events.task import createTask, addMentor, publishTask, addSubTask |
9 from pytask.taskapp.views.user import show_msg |
9 from pytask.taskapp.views.user import show_msg |
|
10 |
|
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 |
|
12 ## do not create su user thro syncdb |
10 |
13 |
11 def browse_tasks(request): |
14 def browse_tasks(request): |
12 """ display all the tasks """ |
15 """ display all the tasks """ |
13 |
16 |
14 user = request.user |
17 user = request.user |
27 task_url = "/task/view/tid=%s"%tid |
30 task_url = "/task/view/tid=%s"%tid |
28 |
31 |
29 user = request.user |
32 user = request.user |
30 task = Task.objects.get(id=tid) |
33 task = Task.objects.get(id=tid) |
31 comments = Comment.objects.filter(task=task) |
34 comments = Comment.objects.filter(task=task) |
|
35 mentors = task.mentors.all() |
32 errors = [] |
36 errors = [] |
33 |
37 |
34 is_guest = True if not user.is_authenticated() else False |
38 is_guest = True if not user.is_authenticated() else False |
35 is_mentor = True if user in task.mentors.all() else False |
39 is_mentor = True if user in task.mentors.all() else False |
36 |
40 |
37 context = {'user':user, |
41 context = {'user':user, |
38 'task':task, |
42 'task':task, |
39 'comments':comments, |
43 'comments':comments, |
|
44 'mentors':mentors, |
40 'is_guest':is_guest, |
45 'is_guest':is_guest, |
41 'is_mentor':is_mentor, |
46 'is_mentor':is_mentor, |
42 'errors':errors, |
47 'errors':errors, |
43 } |
48 } |
44 |
49 |
92 return render_to_response('task/create.html',{'form':form}) |
97 return render_to_response('task/create.html',{'form':form}) |
93 else: |
98 else: |
94 return show_msg('You are not authorised to create a task.') |
99 return show_msg('You are not authorised to create a task.') |
95 else: |
100 else: |
96 return show_msg('You are not authorised to create a task.') |
101 return show_msg('You are not authorised to create a task.') |
|
102 |
|
103 def add_mentor(request, tid): |
|
104 """ check if the current user has the rights to edit the task and add him. |
|
105 if user is not authenticated, redirect him to concerned page. """ |
|
106 |
|
107 task_url = "/task/view/tid=%s"%tid |
|
108 |
|
109 user = request.user |
|
110 task = Task.objects.get(id=tid) |
|
111 errors = [] |
|
112 |
|
113 is_guest = True if not user.is_authenticated() else False |
|
114 |
|
115 if (not is_guest) and user in task.mentors.all(): |
|
116 |
|
117 ## now iam going for a brute force method |
|
118 user_list = list(User.objects.all()) |
|
119 for mentor in task.mentors.all(): |
|
120 user_list.remove(mentor) |
|
121 non_mentors = ((_.id,_.username) for _ in user_list) |
|
122 |
|
123 form = AddMentorForm(non_mentors) |
|
124 if request.method == "POST": |
|
125 uid = request.POST['mentor'] |
|
126 new_mentor = User.objects.get(id=uid) |
|
127 addMentor(task, new_mentor) |
|
128 return redirect(task_url) |
|
129 else: |
|
130 return render_to_response('task/addmentor.html', {'form':form, 'errors':errors}) |
|
131 |
|
132 else: |
|
133 return show_msg('You are not authorised to add mentors for this task', task_url, 'view the task') |
|
134 |
|
135 def add_tasks(request, tid): |
|
136 """ first display tasks which can be subtasks for the task and do the rest. |
|
137 """ |
|
138 |
|
139 task_url = "/task/view/tid=%s"%tid |
|
140 |
|
141 user = request.user |
|
142 task = Task.objects.get(id=tid) |
|
143 errors = [] |
|
144 |
|
145 is_guest = True if not user.is_authenticated() else False |
|
146 |
|
147 if (not is_guest) and user in task.mentors.all(): |
|
148 if task.status in ["OP", "LO"]: |
|
149 if request.method == "POST": |
|
150 ## first decide if adding subs and deps can be in same page |
|
151 ## only exclude tasks with status deleted |
|
152 pass |
|
153 else: |
|
154 ## write a form just like add mentor and get the form here |
|
155 pass |
|
156 else: |
|
157 errors = ["The task cannot be added subtasks or dependencies in this state"] |
|
158 # return render_to_response('task/add.html', {'form':form, 'errors':errors}) |
|
159 return show_msg('The task cannot be added subtasks or dependencies now', task_url, 'view the task') |
|
160 else: |
|
161 return show_msg('You are not authorised to add subtasks or dependencies for this task', task_url, 'view the task') |
|
162 |
|
163 |
|
164 def claim_task(request, tid): |
|
165 """ display a list of claims for get and display submit only if claimable """ |
|
166 |
|
167 ## create claims model and create a new database with required tables for it |
|
168 ## see if that "one to n" or "n to one" relationship has a special field |
|
169 |
|
170 task_url = "/task/view/tid=%s"%tid |
|
171 |
|
172 user = request.user |
|
173 task = Task.objects.get(id=tid) |
97 |
174 |
98 |
175 |
99 |
176 |
100 |
177 |
101 |
178 |
102 |
179 |
103 |
180 |
104 |
|
105 |
|
106 |
|
107 |
|
108 |
|
109 |
|
110 |
|