23 from django.utils import simplejson as json |
23 from django.utils import simplejson as json |
24 from django.utils.translation import ugettext |
24 from django.utils.translation import ugettext |
25 |
25 |
26 from tagging.models import Tag |
26 from tagging.models import Tag |
27 |
27 |
|
28 from pytask.helpers import exceptions |
28 from pytask.views import show_msg |
29 from pytask.views import show_msg |
29 |
30 |
30 from pytask.profile import models as profile_models |
31 from pytask.profile import models as profile_models |
31 |
32 |
32 from pytask.taskapp import forms as taskapp_forms |
33 from pytask.taskapp import forms as taskapp_forms |
33 from pytask.taskapp import models as taskapp_models |
34 from pytask.taskapp import models as taskapp_models |
34 |
35 |
35 |
36 |
36 DONT_CLAIM_TASK_MSG = ugettext( |
37 DONT_CLAIM_TASK_MSG = ugettext( |
37 "Please don't submit any claims for the tasks until the workshop is " |
38 "Please don't submit any claims for the tasks until you get an email " |
38 "over. During the workshop we will introduce you to the work-flow of " |
39 "to start claiming tasks. Please be warned that the task claim work-" |
39 "this entire project. Also please be warned that the task claim work-" |
|
40 "flow may change. So all the claims submitted before the workshop may " |
40 "flow may change. So all the claims submitted before the workshop may " |
41 "not be valid.") |
41 "not be valid.") |
|
42 |
|
43 NO_EDIT_RIGHT = ugettext( |
|
44 "You are not authorized to edit this page.") |
42 |
45 |
43 |
46 |
44 @login_required |
47 @login_required |
45 def create_task(request): |
48 def create_task(request): |
46 |
49 |
128 |
131 |
129 return shortcuts.render_to_response('task/browse.html', |
132 return shortcuts.render_to_response('task/browse.html', |
130 RequestContext(request, context)) |
133 RequestContext(request, context)) |
131 |
134 |
132 |
135 |
133 def view_task(request, task_id): |
136 def view_task(request, task_id, **kwargs): |
134 """ get the task depending on its task_id and display accordingly if it is a get. |
137 """View to get the requested. |
135 check for authentication and add a comment if it is a post request. |
138 |
|
139 Checks for authentication and add a comment if it is a post request. |
136 """ |
140 """ |
137 |
141 |
138 context = {} |
142 context = {} |
|
143 |
|
144 if 'context' in kwargs: |
|
145 context.update(kwargs['context']) |
139 |
146 |
140 # TODO(disable): Disable once the tasks can be claimed |
147 # TODO(disable): Disable once the tasks can be claimed |
141 context['uberbar_message'] = DONT_CLAIM_TASK_MSG |
148 context['uberbar_message'] = DONT_CLAIM_TASK_MSG |
142 |
149 |
143 task_url = reverse('view_task', kwargs={'task_id': task_id}) |
150 task_url = reverse('view_task', kwargs={'task_id': task_id}) |
197 context['can_approve'] = True |
204 context['can_approve'] = True |
198 else: |
205 else: |
199 context['can_approve'] = False |
206 context['can_approve'] = False |
200 |
207 |
201 if ((is_creator or user_role != profile_models.ROLES_CHOICES[3][0]) |
208 if ((is_creator or user_role != profile_models.ROLES_CHOICES[3][0]) |
202 and task.status == taskapp_models.TASK_STATUS_CHOICES[0][0]): |
209 and task.status in [taskapp_models.TASK_STATUS_CHOICES[0][0], |
|
210 taskapp_models.TASK_STATUS_CHOICES[1][0]]): |
203 context['can_edit'] = True |
211 context['can_edit'] = True |
204 else: |
212 else: |
205 context['can_edit'] = False |
213 context['can_edit'] = False |
206 |
214 |
207 if (task.status not in [taskapp_models.TASK_STATUS_CHOICES[0][0], |
215 if (task.status not in [taskapp_models.TASK_STATUS_CHOICES[0][0], |
270 |
278 |
271 task_url = reverse('view_task', kwargs={'task_id': task_id}) |
279 task_url = reverse('view_task', kwargs={'task_id': task_id}) |
272 task = shortcuts.get_object_or_404(taskapp_models.Task, pk=task_id) |
280 task = shortcuts.get_object_or_404(taskapp_models.Task, pk=task_id) |
273 |
281 |
274 is_creator = True if user == task.created_by else False |
282 is_creator = True if user == task.created_by else False |
275 can_edit = True if task.status == taskapp_models.TASK_STATUS_CHOICES[0][0] and is_creator else False |
283 |
|
284 if ((is_creator or profile.role != profile_models.ROLES_CHOICES[3][0]) |
|
285 and task.status in [taskapp_models.TASK_STATUS_CHOICES[0][0], |
|
286 taskapp_models.TASK_STATUS_CHOICES[1][0]]): |
|
287 can_edit = True |
|
288 else: |
|
289 can_edit = False |
|
290 |
276 if not can_edit: |
291 if not can_edit: |
277 raise http.Http404 |
292 raise exceptions.UnauthorizedAccess(NO_EDIT_RIGHT) |
278 |
293 |
279 context = {"user": user, |
294 context = {"user": user, |
280 "profile": profile, |
295 "profile": profile, |
281 "task": task, |
296 "task": task, |
282 } |
297 } |