author | Madhusudan.C.S <madhusudancs@gmail.com> |
Sun, 25 Oct 2009 11:24:46 -0700 | |
changeset 3038 | 34eeacafc5dc |
parent 3034 | aa5ebb226b22 |
child 3059 | 14421976288a |
permissions | -rw-r--r-- |
2885 | 1 |
#!/usr/bin/python2.5 |
2 |
# |
|
3 |
# Copyright 2009 the Melange authors. |
|
4 |
# |
|
5 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
|
6 |
# you may not use this file except in compliance with the License. |
|
7 |
# You may obtain a copy of the License at |
|
8 |
# |
|
9 |
# http://www.apache.org/licenses/LICENSE-2.0 |
|
10 |
# |
|
11 |
# Unless required by applicable law or agreed to in writing, software |
|
12 |
# distributed under the License is distributed on an "AS IS" BASIS, |
|
13 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
14 |
# See the License for the specific language governing permissions and |
|
15 |
# limitations under the License. |
|
16 |
||
17 |
"""Views for Tasks. |
|
18 |
""" |
|
19 |
||
20 |
__authors__ = [ |
|
2942
996e64ba2db8
Removed undefined order argument in GHOP Task View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2893
diff
changeset
|
21 |
'"Madhusudan.C.S" <madhusudancs@gmail.com>', |
996e64ba2db8
Removed undefined order argument in GHOP Task View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2893
diff
changeset
|
22 |
'"Lennard de Rijk" <ljvderijk@gmail.com>', |
2885 | 23 |
] |
24 |
||
25 |
||
26 |
import datetime |
|
27 |
import time |
|
28 |
||
29 |
from google.appengine.ext import db |
|
30 |
||
31 |
from django import forms |
|
32 |
from django import http |
|
33 |
from django.utils.translation import ugettext |
|
34 |
||
35 |
from soc.logic import cleaning |
|
36 |
from soc.logic import dicts |
|
3034
aa5ebb226b22
Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
3033
diff
changeset
|
37 |
from soc.logic.models import host as host_logic |
2885 | 38 |
from soc.logic.models import student as student_logic |
39 |
from soc.logic.models import user as user_logic |
|
40 |
from soc.views import helper |
|
41 |
from soc.views import out_of_band |
|
42 |
from soc.views.helper import decorators |
|
43 |
from soc.views.helper import dynaform |
|
44 |
from soc.views.helper import lists |
|
45 |
from soc.views.helper import params as params_helper |
|
46 |
from soc.views.helper import requests |
|
47 |
from soc.views.helper import redirects |
|
48 |
from soc.views.helper import responses |
|
49 |
from soc.views.helper import widgets |
|
50 |
from soc.views.models import base |
|
51 |
||
52 |
from soc.modules.ghop.logic import cleaning as ghop_cleaning |
|
53 |
from soc.modules.ghop.logic.models import comment as ghop_comment_logic |
|
54 |
from soc.modules.ghop.logic.models import mentor as ghop_mentor_logic |
|
55 |
from soc.modules.ghop.logic.models import organization as ghop_org_logic |
|
56 |
from soc.modules.ghop.logic.models import org_admin as ghop_org_admin_logic |
|
57 |
from soc.modules.ghop.logic.models import program as ghop_program_logic |
|
58 |
from soc.modules.ghop.logic.models import task as ghop_task_logic |
|
59 |
from soc.modules.ghop.models import task as ghop_task_model |
|
60 |
from soc.modules.ghop.views.helper import access |
|
61 |
from soc.modules.ghop.views.helper import redirects as ghop_redirects |
|
62 |
from soc.modules.ghop.views.models import organization as ghop_org_view |
|
63 |
from soc.modules.ghop.tasks import task_update |
|
64 |
||
65 |
import soc.modules.ghop.logic.models.task |
|
66 |
||
67 |
||
68 |
class View(base.View): |
|
69 |
"""View methods for the Tasks. |
|
70 |
""" |
|
71 |
||
72 |
DEF_AWAITING_REG_MSG = ugettext( |
|
73 |
'The task is open but you cannot claim this task since you ' |
|
74 |
'have not completed the student signup after finishing your ' |
|
75 |
'first task.') |
|
76 |
||
77 |
DEF_CAN_EDIT_TASK_MSG = ugettext( |
|
78 |
'The task can be edited by clicking on the edit link ' |
|
79 |
'next to the title above.') |
|
80 |
||
81 |
DEF_MAX_TASK_LIMIT_MSG_FMT = ugettext( |
|
82 |
'The task is open but you cannot claim this task since you ' |
|
3018
0653f924ee7e
Fix typographical error and changes in status messages for Task workflow.
Matthew Wilkes <matthew@matthewwilkes.co.uk>
parents:
3017
diff
changeset
|
83 |
'have already claimed %d task(s).') |
2885 | 84 |
|
85 |
DEF_SIGNIN_TO_COMMENT_MSG = ugettext( |
|
86 |
'<a href=%s>Sign in</a> to perform any action or comment on ' |
|
87 |
'this task.') |
|
88 |
||
89 |
DEF_STUDENT_SIGNUP_MSG = ugettext( |
|
90 |
'You have successfully completed this task. Sign up as a student ' |
|
91 |
'before you proceed further.') |
|
92 |
||
3034
aa5ebb226b22
Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
3033
diff
changeset
|
93 |
DEF_TASK_CLAIMED_BY_YOU_MSG = ugettext( |
3018
0653f924ee7e
Fix typographical error and changes in status messages for Task workflow.
Matthew Wilkes <matthew@matthewwilkes.co.uk>
parents:
3017
diff
changeset
|
94 |
'You have claimed this task!') |
2885 | 95 |
|
96 |
DEF_TASK_CLAIMED_BY_STUDENT_MSG = ugettext( |
|
97 |
'This task has been claimed by a student!') |
|
98 |
||
99 |
DEF_TASK_CLAIMED_MSG = ugettext( |
|
100 |
'The task is already claimed and the work is in progress.') |
|
101 |
||
102 |
DEF_TASK_CLAIM_REQUESTED_MSG = ugettext( |
|
103 |
'A student has requested to claim this task. Accept or ' |
|
3018
0653f924ee7e
Fix typographical error and changes in status messages for Task workflow.
Matthew Wilkes <matthew@matthewwilkes.co.uk>
parents:
3017
diff
changeset
|
104 |
'reject the request.') |
2885 | 105 |
|
3018
0653f924ee7e
Fix typographical error and changes in status messages for Task workflow.
Matthew Wilkes <matthew@matthewwilkes.co.uk>
parents:
3017
diff
changeset
|
106 |
DEF_TASK_CLOSED_MSG = ugettext('This task is closed.') |
2885 | 107 |
|
108 |
DEF_TASK_CMPLTD_BY_YOU_MSG = ugettext( |
|
109 |
'You have successfully completed this task!') |
|
110 |
||
111 |
DEF_TASK_NO_MORE_SUBMIT_MSG = ugettext( |
|
112 |
'You have submitted the work to this task, but deadline has passed ' |
|
113 |
'You cannot submit any more work until your mentor extends the ' |
|
114 |
'deadline.') |
|
115 |
||
116 |
DEF_TASK_MENTOR_REOPENED_MSG = ugettext( |
|
117 |
'The task has been reopened.') |
|
118 |
||
119 |
DEF_TASK_NEEDS_REVIEW_MSG = ugettext( |
|
120 |
'Student has submitted his work for this task! It needs review.') |
|
121 |
||
122 |
DEF_TASK_OPEN_MSG = ugettext( |
|
3018
0653f924ee7e
Fix typographical error and changes in status messages for Task workflow.
Matthew Wilkes <matthew@matthewwilkes.co.uk>
parents:
3017
diff
changeset
|
123 |
'This task is open. If you are a GHOP student, you can claim it!') |
2885 | 124 |
|
125 |
DEF_TASK_REOPENED_MSG = ugettext( |
|
126 |
'This task has been reopened. If you are a GHOP student, ' |
|
3018
0653f924ee7e
Fix typographical error and changes in status messages for Task workflow.
Matthew Wilkes <matthew@matthewwilkes.co.uk>
parents:
3017
diff
changeset
|
127 |
'you can claim it!') |
2885 | 128 |
|
129 |
DEF_TASK_REQ_CLAIMED_BY_YOU_MSG = ugettext( |
|
130 |
'You have requested to claim this task!') |
|
131 |
||
132 |
DEF_TASK_UNPUBLISHED_MSG = ugettext( |
|
133 |
'The task is not yet published. It can be edited by clicking on ' |
|
134 |
'the edit button below.') |
|
135 |
||
136 |
DEF_WS_MSG_FMT = ugettext( |
|
137 |
'(To see the work submitted <a href=#ws%d>click here</a>.)') |
|
138 |
||
139 |
def __init__(self, params=None): |
|
140 |
"""Defines the fields and methods required for the task View class |
|
141 |
to provide the user with the necessary views. |
|
142 |
||
143 |
Params: |
|
144 |
params: a dict with params for this View |
|
145 |
""" |
|
146 |
||
147 |
rights = access.GHOPChecker(params) |
|
148 |
# TODO: create and suggest_task don't need access checks which use state |
|
149 |
# also feels like roles are being checked twice? |
|
150 |
rights['create'] = [ |
|
151 |
('checkCanOrgAdminOrMentorEdit', ['scope_path', True]), |
|
152 |
('checkRoleAndStatusForTask', |
|
3034
aa5ebb226b22
Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
3033
diff
changeset
|
153 |
[['ghop/org_admin'], ['active'], |
2885 | 154 |
[]])] |
155 |
rights['edit'] = [ |
|
156 |
('checkCanOrgAdminOrMentorEdit', ['scope_path', False]), |
|
157 |
('checkRoleAndStatusForTask', |
|
3034
aa5ebb226b22
Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
3033
diff
changeset
|
158 |
[['ghop/org_admin'], ['active'], |
2885 | 159 |
['Unapproved', 'Unpublished', 'Open']])] |
160 |
rights['delete'] = ['checkIsDeveloper'] |
|
161 |
rights['show'] = ['checkStatusForTask'] |
|
162 |
rights['list_org_tasks'] = [ |
|
163 |
('checkCanOrgAdminOrMentorEdit', ['scope_path', False])] |
|
164 |
rights['suggest_task'] = [ |
|
165 |
('checkCanOrgAdminOrMentorEdit', ['scope_path', True]), |
|
166 |
('checkRoleAndStatusForTask', |
|
3034
aa5ebb226b22
Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
3033
diff
changeset
|
167 |
[['ghop/org_admin', 'ghop/mentor'], ['active'], |
3027
a223fff4cca8
Fixed access check and seed for Task Suggest page.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
3026
diff
changeset
|
168 |
['Unapproved']])] |
2885 | 169 |
rights['search'] = ['allow'] |
170 |
||
171 |
new_params = {} |
|
172 |
new_params['logic'] = soc.modules.ghop.logic.models.task.logic |
|
173 |
new_params['rights'] = rights |
|
174 |
||
175 |
new_params['name'] = "Task" |
|
176 |
new_params['module_name'] = "task" |
|
177 |
new_params['sidebar_grouping'] = 'Tasks' |
|
178 |
||
179 |
new_params['module_package'] = 'soc.modules.ghop.views.models' |
|
180 |
new_params['url_name'] = 'ghop/task' |
|
181 |
||
182 |
new_params['scope_view'] = ghop_org_view |
|
183 |
new_params['scope_redirect'] = redirects.getCreateRedirect |
|
184 |
||
3034
aa5ebb226b22
Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
3033
diff
changeset
|
185 |
new_params['list_heading'] = 'modules/ghop/task/list/heading.html' |
2885 | 186 |
new_params['list_row'] = 'modules/ghop/task/list/row.html' |
187 |
||
188 |
new_params['extra_dynaexclude'] = ['task_type', 'mentors', 'user', |
|
3034
aa5ebb226b22
Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
3033
diff
changeset
|
189 |
'student', 'program', 'status', |
2885 | 190 |
'deadline', 'created_by', |
191 |
'created_on', 'modified_by', |
|
192 |
'modified_on', 'history', |
|
193 |
'link_id', 'difficulty'] |
|
194 |
||
195 |
patterns = [] |
|
196 |
patterns += [ |
|
197 |
(r'^%(url_name)s/(?P<access_type>suggest_task)/%(scope)s$', |
|
198 |
'%(module_package)s.%(module_name)s.suggest_task', |
|
199 |
'Mentors suggest %(name)s'), |
|
200 |
(r'^%(url_name)s/(?P<access_type>suggest_task)/%(key_fields)s$', |
|
201 |
'%(module_package)s.%(module_name)s.suggest_task', |
|
202 |
'Mentors edit a %(name)s'), |
|
203 |
(r'^%(url_name)s/(?P<access_type>list_org_tasks)/%(scope)s$', |
|
204 |
'%(module_package)s.%(module_name)s.list_org_tasks', |
|
205 |
'List Organization %(name)s'), |
|
206 |
(r'^%(url_name)s/(?P<access_type>search)/' |
|
207 |
'(?P<scope_path>%(ulnp)s)/%(lnp)s$', |
|
208 |
'%(module_package)s.%(module_name)s.search', |
|
209 |
'Search for %(name)ss'), |
|
210 |
] |
|
211 |
||
212 |
new_params['extra_django_patterns'] = patterns |
|
213 |
||
214 |
new_params['create_dynafields'] = [ |
|
215 |
{'name': 'arbit_tags', |
|
216 |
'base': forms.fields.CharField, |
|
217 |
'label': 'Arbitrary Tags', |
|
218 |
'required': False, |
|
219 |
'group': ugettext('Tags'), |
|
220 |
'help_text': ugettext( |
|
221 |
'Enter arbitrary Tags for this task separated by comma.\n' |
|
222 |
'<b>Note:</b> Tag names are case sensitive. If the tag is same ' |
|
223 |
'as the program mandated tag, it will be considered as a ' |
|
224 |
'mandatory tag.') |
|
225 |
}, |
|
226 |
] |
|
227 |
||
228 |
new_params['create_extra_dynaproperties'] = { |
|
229 |
'description': forms.fields.CharField(required=True, |
|
230 |
widget=widgets.FullTinyMCE(attrs={'rows': 25, 'cols': 100})), |
|
231 |
'scope_path': forms.CharField(widget=forms.HiddenInput, |
|
232 |
required=True), |
|
233 |
'time_to_complete': forms.IntegerField(min_value=1, |
|
234 |
required=True), |
|
235 |
'clean_description': cleaning.clean_html_content('description'), |
|
236 |
'clean_arbit_tags': cleaning.str2set('arbit_tags'), |
|
237 |
} |
|
238 |
||
239 |
new_params['edit_extra_dynaproperties'] = { |
|
240 |
'link_id': forms.CharField(widget=forms.HiddenInput) |
|
241 |
} |
|
242 |
||
243 |
new_params['public_template'] = 'modules/ghop/task/public.html' |
|
244 |
||
245 |
params = dicts.merge(params, new_params, sub_merge=True) |
|
246 |
||
247 |
super(View, self).__init__(params=params) |
|
248 |
||
249 |
# holds the base form for the task creation and editing |
|
250 |
self._params['base_create_form'] = self._params['create_form'] |
|
3034
aa5ebb226b22
Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
3033
diff
changeset
|
251 |
self._params['base_edit_form'] = self._params['edit_form'] |
2885 | 252 |
|
253 |
# extend create and edit form for org admins |
|
254 |
dynafields = [ |
|
255 |
{'name': 'mentors_list', |
|
256 |
'required': True, |
|
257 |
'base': forms.fields.CharField, |
|
258 |
'label': 'Assign mentors', |
|
259 |
'help_text': 'Assign mentors to this task by ' |
|
260 |
'giving their link_ids separated by comma.', |
|
261 |
}, |
|
262 |
{'name': 'published', |
|
263 |
'required': False, |
|
264 |
'initial': False, |
|
265 |
'base': forms.fields.BooleanField, |
|
266 |
'label': 'Publish the task', |
|
267 |
'help_text': ugettext('By ticking this box, the task will be' |
|
268 |
'made public and can be claimed by students.'), |
|
269 |
} |
|
270 |
] |
|
271 |
||
272 |
dynaproperties = params_helper.getDynaFields(dynafields) |
|
273 |
||
274 |
dynaproperties['clean_mentors_list'] = ghop_cleaning.cleanMentorsList( |
|
275 |
'mentors_list') |
|
276 |
||
277 |
create_form = dynaform.extendDynaForm( |
|
278 |
dynaform=self._params['create_form'], |
|
279 |
dynaproperties=dynaproperties) |
|
280 |
||
281 |
self._params['create_form'] = create_form |
|
282 |
||
283 |
edit_form = dynaform.extendDynaForm( |
|
284 |
dynaform=self._params['edit_form'], |
|
285 |
dynaproperties=dynaproperties) |
|
286 |
||
287 |
self._params['edit_form'] = edit_form |
|
288 |
||
289 |
# create the comment form |
|
290 |
dynafields = [ |
|
291 |
{'name': 'comment', |
|
292 |
'base': forms.CharField, |
|
293 |
'widget': widgets.FullTinyMCE(attrs={'rows': 10, 'cols': 40}), |
|
294 |
'label': 'Comment', |
|
295 |
'required': False, |
|
296 |
'example_text': 'Comment is optional.<br/>' |
|
297 |
'Choose an appropriate Action below and Save your ' |
|
298 |
'changes.<br /><br />Caution, you will not be able ' |
|
299 |
'to edit your comment!', |
|
300 |
}, |
|
301 |
] |
|
302 |
||
303 |
dynaproperties = params_helper.getDynaFields(dynafields) |
|
304 |
dynaproperties['clean_comment'] = cleaning.clean_html_content('comment') |
|
2893
1adc6a815c71
Several style and import fixes regarding the GHOP module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2885
diff
changeset
|
305 |
dynaproperties['clean'] = ghop_cleaning.cleanTaskComment( |
2885 | 306 |
'comment', 'action', 'work_submission') |
307 |
||
3034
aa5ebb226b22
Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
3033
diff
changeset
|
308 |
comment_form = dynaform.newDynaForm(dynamodel=None, |
aa5ebb226b22
Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
3033
diff
changeset
|
309 |
dynabase=helper.forms.BaseForm, dynainclude=None, |
2885 | 310 |
dynaexclude=None, dynaproperties=dynaproperties) |
311 |
self._params['comment_form'] = comment_form |
|
312 |
||
313 |
def _getTagsForProgram(self, form_name, params, **kwargs): |
|
314 |
"""Extends form dynamically from difficulty levels in program entity. |
|
315 |
||
316 |
Args: |
|
317 |
form_name: the Form entry in params to extend |
|
318 |
params: the params for the view |
|
319 |
""" |
|
320 |
||
3034
aa5ebb226b22
Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
3033
diff
changeset
|
321 |
# obtain program_entity using scope_path which holds |
2885 | 322 |
# the org_entity key_name |
323 |
org_entity = ghop_org_logic.logic.getFromKeyName(kwargs['scope_path']) |
|
324 |
program_entity = ghop_program_logic.logic.getFromKeyName( |
|
325 |
org_entity.scope_path) |
|
326 |
||
327 |
# get a list difficulty levels stored for the program entity |
|
328 |
tds = ghop_task_model.TaskDifficultyTag.get_by_scope( |
|
3034
aa5ebb226b22
Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
3033
diff
changeset
|
329 |
program_entity) |
2885 | 330 |
|
331 |
difficulties = [] |
|
332 |
for td in tds: |
|
333 |
difficulties.append((td.tag, td.tag)) |
|
334 |
||
335 |
# get a list of task type tags stored for the program entity |
|
3034
aa5ebb226b22
Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
3033
diff
changeset
|
336 |
tts = ghop_task_model.TaskTypeTag.get_by_scope(program_entity) |
2885 | 337 |
|
338 |
type_tags = [] |
|
339 |
for tt in tts: |
|
340 |
type_tags.append((tt.tag, tt.tag)) |
|
341 |
||
3034
aa5ebb226b22
Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
3033
diff
changeset
|
342 |
# create the difficultly level field containing the choices |
2885 | 343 |
# defined in the program entity |
344 |
dynafields = [ |
|
345 |
{'name': 'difficulty', |
|
346 |
'base': forms.ChoiceField, |
|
347 |
'label': 'Difficulty level', |
|
348 |
'required': True, |
|
349 |
'passthrough': ['initial', 'required', 'choices', |
|
350 |
'label', 'help_text'], |
|
351 |
'choices': difficulties, |
|
352 |
'group': ugettext('Tags'), |
|
353 |
'help_text': ugettext('Difficulty Level of this task.'), |
|
354 |
}, |
|
355 |
{'name': 'type_tags', |
|
356 |
'base': forms.MultipleChoiceField, |
|
357 |
'label': 'Task Types', |
|
358 |
'required': True, |
|
359 |
'passthrough': ['initial', 'required', 'choices', |
|
360 |
'label', 'help_text'], |
|
361 |
'choices': type_tags, |
|
362 |
'group': ugettext('Tags'), |
|
363 |
'help_text': ugettext('Task Type tags mandated by the program. You ' |
|
364 |
'must select one or more of them.'), |
|
365 |
}, |
|
366 |
] |
|
367 |
||
368 |
dynaproperties = params_helper.getDynaFields(dynafields) |
|
369 |
||
370 |
extended_form = dynaform.extendDynaForm( |
|
371 |
dynaform=params[form_name], |
|
372 |
dynaproperties=dynaproperties) |
|
373 |
||
374 |
return extended_form |
|
375 |
||
376 |
@decorators.check_access |
|
377 |
def create(self, request, access_type, |
|
378 |
page_name=None, params=None, **kwargs): |
|
379 |
"""Replaces the create Form with the dynamic one. |
|
380 |
||
381 |
For args see base.View.create(). |
|
382 |
""" |
|
383 |
||
384 |
params = dicts.merge(params, self._params) |
|
385 |
||
386 |
# extend create_form to include difficulty levels |
|
387 |
params['create_form'] = self._getTagsForProgram( |
|
388 |
'create_form', params, **kwargs) |
|
389 |
||
390 |
return super(View, self).create(request, 'allow', page_name=page_name, |
|
391 |
params=params, **kwargs) |
|
392 |
||
393 |
@decorators.merge_params |
|
394 |
@decorators.check_access |
|
395 |
def edit(self, request, access_type, |
|
396 |
page_name=None, params=None, seed=None, **kwargs): |
|
397 |
"""See base.View.edit(). |
|
398 |
""" |
|
399 |
||
400 |
logic = params['logic'] |
|
401 |
||
402 |
context = helper.responses.getUniversalContext(request) |
|
403 |
helper.responses.useJavaScript(context, params['js_uses_all']) |
|
404 |
context['page_name'] = page_name |
|
405 |
||
406 |
try: |
|
407 |
entity = logic.getFromKeyFieldsOr404(kwargs) |
|
408 |
except out_of_band.Error, error: |
|
409 |
msg = self.DEF_CREATE_NEW_ENTITY_MSG_FMT % { |
|
410 |
'entity_type_lower' : params['name'].lower(), |
|
411 |
'entity_type' : params['name'], |
|
412 |
'create' : params['missing_redirect'] |
|
413 |
} |
|
414 |
error.message_fmt = error.message_fmt + msg |
|
415 |
return helper.responses.errorResponse( |
|
416 |
error, request, context=context) |
|
417 |
||
418 |
# extend edit_form to include difficulty levels |
|
419 |
params['edit_form'] = self._getTagsForProgram( |
|
420 |
'edit_form', params, **kwargs) |
|
421 |
||
3026
75ef22dc5a8a
Removed query wether or not the current user was ever an org admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
3018
diff
changeset
|
422 |
if entity.status == 'Unapproved': |
75ef22dc5a8a
Removed query wether or not the current user was ever an org admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
3018
diff
changeset
|
423 |
dynafields = [ |
75ef22dc5a8a
Removed query wether or not the current user was ever an org admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
3018
diff
changeset
|
424 |
{'name': 'approved', |
75ef22dc5a8a
Removed query wether or not the current user was ever an org admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
3018
diff
changeset
|
425 |
'required': False, |
75ef22dc5a8a
Removed query wether or not the current user was ever an org admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
3018
diff
changeset
|
426 |
'initial': False, |
75ef22dc5a8a
Removed query wether or not the current user was ever an org admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
3018
diff
changeset
|
427 |
'base': forms.fields.BooleanField, |
75ef22dc5a8a
Removed query wether or not the current user was ever an org admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
3018
diff
changeset
|
428 |
'label': 'Approve the task', |
75ef22dc5a8a
Removed query wether or not the current user was ever an org admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
3018
diff
changeset
|
429 |
'help_text': 'By ticking this box, the task will be' |
75ef22dc5a8a
Removed query wether or not the current user was ever an org admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
3018
diff
changeset
|
430 |
'will be approved for publishing.', |
75ef22dc5a8a
Removed query wether or not the current user was ever an org admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
3018
diff
changeset
|
431 |
} |
75ef22dc5a8a
Removed query wether or not the current user was ever an org admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
3018
diff
changeset
|
432 |
] |
2885 | 433 |
|
3026
75ef22dc5a8a
Removed query wether or not the current user was ever an org admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
3018
diff
changeset
|
434 |
dynaproperties = params_helper.getDynaFields(dynafields) |
2885 | 435 |
|
3026
75ef22dc5a8a
Removed query wether or not the current user was ever an org admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
3018
diff
changeset
|
436 |
edit_form = dynaform.extendDynaForm( |
75ef22dc5a8a
Removed query wether or not the current user was ever an org admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
3018
diff
changeset
|
437 |
dynaform=params['edit_form'], |
75ef22dc5a8a
Removed query wether or not the current user was ever an org admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
3018
diff
changeset
|
438 |
dynaproperties=dynaproperties) |
2885 | 439 |
|
3026
75ef22dc5a8a
Removed query wether or not the current user was ever an org admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
3018
diff
changeset
|
440 |
params['edit_form'] = edit_form |
2885 | 441 |
|
442 |
if request.method == 'POST': |
|
443 |
return self.editPost(request, entity, context, params=params) |
|
444 |
else: |
|
445 |
return self.editGet(request, entity, context, params=params) |
|
446 |
||
447 |
def _editGet(self, request, entity, form): |
|
448 |
"""See base.View._editGet(). |
|
449 |
""" |
|
450 |
||
451 |
if entity.task_type: |
|
452 |
form.fields['type_tags'].initial = entity.tags_string( |
|
453 |
entity.task_type, ret_list=True) |
|
454 |
if entity.arbit_tag: |
|
455 |
form.fields['arbit_tags'].initial = entity.tags_string( |
|
456 |
entity.arbit_tag) |
|
457 |
||
458 |
if entity.difficulty: |
|
3034
aa5ebb226b22
Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
3033
diff
changeset
|
459 |
form.fields['difficulty'].initial = entity.tags_string( |
2885 | 460 |
entity.difficulty) |
461 |
||
462 |
if entity.mentors and 'mentors_list' in form.fields: |
|
463 |
mentor_entities = db.get(entity.mentors) |
|
464 |
mentors_list = [] |
|
465 |
for mentor in mentor_entities: |
|
466 |
mentors_list.append(mentor.link_id) |
|
467 |
form.fields['mentors_list'].initial = ', '.join(mentors_list) |
|
468 |
||
469 |
form.fields['link_id'].initial = entity.link_id |
|
470 |
||
471 |
# checks if the task is already approved or not and sets |
|
472 |
# the form approved field |
|
473 |
if 'approved' in form.fields: |
|
474 |
if entity.status == 'Unapproved': |
|
475 |
form.fields['approved'].initial = False |
|
476 |
else: |
|
477 |
form.fields['approved'].initial = True |
|
3034
aa5ebb226b22
Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
3033
diff
changeset
|
478 |
|
2885 | 479 |
# checks if the task is already published or not and sets |
3034
aa5ebb226b22
Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
3033
diff
changeset
|
480 |
# the form published field |
2885 | 481 |
if 'published' in form.fields: |
482 |
if entity.status == 'Unapproved' or entity.status == 'Unpublished': |
|
483 |
form.fields['published'].initial = False |
|
484 |
else: |
|
485 |
form.fields['published'].initial = True |
|
486 |
||
487 |
return super(View, self)._editGet(request, entity, form) |
|
488 |
||
489 |
def _editPost(self, request, entity, fields): |
|
490 |
"""See base._editPost(). |
|
491 |
""" |
|
492 |
||
3038
34eeacafc5dc
Once a task has been approved it can no longer be unapproved.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
3034
diff
changeset
|
493 |
# set the scope field |
2885 | 494 |
super(View, self)._editPost(request, entity, fields) |
495 |
||
496 |
# TODO: this method can be made more clear, it seems a bit of a mess |
|
497 |
||
498 |
if not entity: |
|
499 |
program_entity = fields['scope'].scope |
|
500 |
fields['program'] = program_entity |
|
501 |
else: |
|
3034
aa5ebb226b22
Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
3033
diff
changeset
|
502 |
program_entity = entity.program |
2885 | 503 |
|
504 |
user_account = user_logic.logic.getForCurrentAccount() |
|
505 |
||
506 |
filter = { |
|
507 |
'user': user_account, |
|
508 |
'status': 'active' |
|
509 |
} |
|
2978
2b3c39483f6f
Fixes the problem of GHOP Task editing after it is created.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2942
diff
changeset
|
510 |
if not entity: |
2b3c39483f6f
Fixes the problem of GHOP Task editing after it is created.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2942
diff
changeset
|
511 |
filter['scope'] = fields['scope'] |
2b3c39483f6f
Fixes the problem of GHOP Task editing after it is created.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2942
diff
changeset
|
512 |
else: |
3033
8a18ac7ca909
When a task is edited, 'modified_by' field is not cleared any more.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
3028
diff
changeset
|
513 |
filter['scope'] = entity.scope |
2885 | 514 |
|
515 |
role_entity = ghop_org_admin_logic.logic.getForFields( |
|
516 |
filter, unique=True) |
|
517 |
||
518 |
if role_entity: |
|
519 |
# this user can publish/approve the task |
|
3038
34eeacafc5dc
Once a task has been approved it can no longer be unapproved.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
3034
diff
changeset
|
520 |
if fields.get('published'): |
2885 | 521 |
fields['status'] = 'Open' |
3038
34eeacafc5dc
Once a task has been approved it can no longer be unapproved.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
3034
diff
changeset
|
522 |
elif fields.get('approved'): |
2885 | 523 |
fields['status'] = 'Unpublished' |
524 |
||
525 |
fields['mentors'] = [] |
|
526 |
if fields.get('mentors_list'): |
|
527 |
||
528 |
for mentor_link_id in fields['mentors_list']: |
|
529 |
properties = { |
|
530 |
'scope_path': fields['scope_path'], |
|
531 |
'link_id': mentor_link_id, |
|
532 |
} |
|
533 |
||
534 |
mentor_entity = ghop_mentor_logic.logic.getFromKeyFields(properties) |
|
535 |
fields['mentors'].append(mentor_entity.key()) |
|
536 |
else: |
|
537 |
role_entity = ghop_mentor_logic.logic.getForFields( |
|
538 |
filter, unique=True) |
|
539 |
if not entity: |
|
540 |
# creating a new task |
|
541 |
fields['status'] = 'Unapproved' |
|
542 |
||
543 |
# explicitly change the last_modified_on since the content has been edited |
|
544 |
fields['modified_on'] = datetime.datetime.now() |
|
545 |
||
546 |
if not entity: |
|
547 |
fields['link_id'] = 't%i' % (int(time.time()*100)) |
|
548 |
fields['modified_by'] = role_entity |
|
3034
aa5ebb226b22
Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
3033
diff
changeset
|
549 |
fields['created_by'] = role_entity |
2885 | 550 |
fields['created_on'] = datetime.datetime.now() |
551 |
else: |
|
552 |
fields['link_id'] = entity.link_id |
|
553 |
fields['modified_by'] = role_entity |
|
554 |
if 'status' not in fields: |
|
555 |
fields['status'] = entity.status |
|
556 |
||
557 |
fields['difficulty'] = { |
|
558 |
'tags': fields['difficulty'], |
|
559 |
'scope': program_entity |
|
560 |
} |
|
561 |
||
562 |
fields['task_type'] = { |
|
563 |
'tags': fields['type_tags'], |
|
564 |
'scope': program_entity |
|
565 |
} |
|
566 |
||
567 |
fields['arbit_tag'] = { |
|
568 |
'tags': fields['arbit_tags'], |
|
569 |
'scope': program_entity |
|
570 |
} |
|
571 |
||
572 |
return |
|
573 |
||
574 |
@decorators.merge_params |
|
575 |
@decorators.check_access |
|
3034
aa5ebb226b22
Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
3033
diff
changeset
|
576 |
def suggestTask(self, request, access_type, page_name=None, |
2885 | 577 |
params=None, **kwargs): |
3034
aa5ebb226b22
Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
3033
diff
changeset
|
578 |
"""View used to allow mentors to create or edit a task. |
2885 | 579 |
|
580 |
Tasks created by mentors must be approved by org admins |
|
581 |
before they are published. |
|
582 |
""" |
|
583 |
||
584 |
params = dicts.merge(params, self._params) |
|
585 |
||
586 |
if 'link_id' in kwargs: |
|
587 |
# extend create_form to include difficulty levels |
|
588 |
params['mentor_form'] = self._getTagsForProgram( |
|
589 |
'base_edit_form', params, **kwargs) |
|
590 |
try: |
|
591 |
entity = self._logic.getFromKeyFieldsOr404(kwargs) |
|
592 |
except out_of_band.Error, error: |
|
593 |
return helper.responses.errorResponse( |
|
594 |
error, request, template=params['error_public']) |
|
595 |
else: |
|
596 |
# extend create_form to include difficulty levels |
|
597 |
params['mentor_form'] = self._getTagsForProgram( |
|
598 |
'base_create_form', params, **kwargs) |
|
599 |
entity = None |
|
600 |
||
601 |
context = helper.responses.getUniversalContext(request) |
|
602 |
helper.responses.useJavaScript(context, params['js_uses_all']) |
|
603 |
context['page_name'] = page_name |
|
604 |
||
605 |
if request.method == 'POST': |
|
606 |
return self.suggestTaskPost(request, context, |
|
607 |
params, entity) |
|
608 |
else: |
|
609 |
return self.suggestTaskGet(request, context, |
|
3027
a223fff4cca8
Fixed access check and seed for Task Suggest page.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
3026
diff
changeset
|
610 |
params, entity, kwargs) |
2885 | 611 |
|
612 |
def suggestTaskPost(self, request, context, params, entity): |
|
613 |
"""Handles the POST request for the suggest task view. |
|
614 |
""" |
|
615 |
||
616 |
form = params['mentor_form'](request.POST) |
|
617 |
||
618 |
if not form.is_valid(): |
|
619 |
return self._constructResponse(request, None, context, form, params) |
|
620 |
||
621 |
_, fields = helper.forms.collectCleanedFields(form) |
|
622 |
# TODO: this non-standard view shouldn't call _editPost but its own method |
|
623 |
self._editPost(request, entity, fields) |
|
624 |
||
625 |
logic = params['logic'] |
|
626 |
if entity: |
|
627 |
entity = logic.updateEntityProperties(entity, fields) |
|
628 |
else: |
|
3026
75ef22dc5a8a
Removed query wether or not the current user was ever an org admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
3018
diff
changeset
|
629 |
# TODO: Redirect to standard edit page which already has the ability to |
75ef22dc5a8a
Removed query wether or not the current user was ever an org admin.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
3018
diff
changeset
|
630 |
# hide certain fields. |
3028
1852a74ba03a
Set the Mentors list to the user that is suggesting a Task.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
3027
diff
changeset
|
631 |
# get the mentor entity of the current user that is suggesting the task |
1852a74ba03a
Set the Mentors list to the user that is suggesting a Task.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
3027
diff
changeset
|
632 |
user_entity = user_logic.logic.getForCurrentAccount() |
1852a74ba03a
Set the Mentors list to the user that is suggesting a Task.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
3027
diff
changeset
|
633 |
|
1852a74ba03a
Set the Mentors list to the user that is suggesting a Task.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
3027
diff
changeset
|
634 |
filter = {'user': user_entity, |
1852a74ba03a
Set the Mentors list to the user that is suggesting a Task.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
3027
diff
changeset
|
635 |
'scope': fields['scope'], |
1852a74ba03a
Set the Mentors list to the user that is suggesting a Task.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
3027
diff
changeset
|
636 |
'status': 'active'} |
1852a74ba03a
Set the Mentors list to the user that is suggesting a Task.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
3027
diff
changeset
|
637 |
|
1852a74ba03a
Set the Mentors list to the user that is suggesting a Task.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
3027
diff
changeset
|
638 |
mentor_entity = ghop_mentor_logic.logic.getForFields(filter, unique=True) |
1852a74ba03a
Set the Mentors list to the user that is suggesting a Task.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
3027
diff
changeset
|
639 |
fields['mentors'] = [mentor_entity.key()] |
1852a74ba03a
Set the Mentors list to the user that is suggesting a Task.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
3027
diff
changeset
|
640 |
|
2885 | 641 |
entity = logic.updateOrCreateFromFields(fields) |
642 |
||
643 |
redirect = ghop_redirects.getSuggestTaskRedirect( |
|
644 |
entity, params) |
|
645 |
||
646 |
return http.HttpResponseRedirect(redirect) |
|
647 |
||
3027
a223fff4cca8
Fixed access check and seed for Task Suggest page.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
3026
diff
changeset
|
648 |
def suggestTaskGet(self, request, context, params, entity, seed): |
2885 | 649 |
"""Handles the GET request for the suggest task view. |
650 |
""" |
|
651 |
||
652 |
if entity: |
|
653 |
# populate form with the existing entity |
|
654 |
form = params['mentor_form'](instance=entity) |
|
655 |
||
656 |
self._editGet(request, entity, form) |
|
3027
a223fff4cca8
Fixed access check and seed for Task Suggest page.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
3026
diff
changeset
|
657 |
elif seed: |
a223fff4cca8
Fixed access check and seed for Task Suggest page.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
3026
diff
changeset
|
658 |
form = params['mentor_form'](initial=seed) |
2885 | 659 |
else: |
660 |
form = params['mentor_form']() |
|
661 |
||
662 |
return self._constructResponse(request, entity, context, form, params) |
|
663 |
||
664 |
@decorators.merge_params |
|
665 |
@decorators.check_access |
|
666 |
def listOrgTasks(self, request, access_type, |
|
667 |
page_name=None, params=None, **kwargs): |
|
668 |
"""See base.View.list() |
|
669 |
""" |
|
670 |
if request.method == 'POST': |
|
671 |
return self.listOrgTasksPost(request, params, **kwargs) |
|
672 |
else: # request.method == 'GET' |
|
673 |
return self.listOrgTasksGet(request, page_name, params, **kwargs) |
|
674 |
||
675 |
def listOrgTasksPost(self, request, params, **kwargs): |
|
676 |
"""Handles the POST request for the list tasks view. |
|
677 |
""" |
|
678 |
||
3017
6689a4c8f02e
Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
3002
diff
changeset
|
679 |
# get the org entity for which we are listing these tasks |
6689a4c8f02e
Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
3002
diff
changeset
|
680 |
org_entity = ghop_org_logic.logic.getFromKeyNameOr404(kwargs['scope_path']) |
6689a4c8f02e
Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
3002
diff
changeset
|
681 |
|
6689a4c8f02e
Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
3002
diff
changeset
|
682 |
# save the state to which the selected tasks must be changed |
6689a4c8f02e
Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
3002
diff
changeset
|
683 |
# to based on the actions. |
6689a4c8f02e
Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
3002
diff
changeset
|
684 |
if request.POST.get('Approve'): |
6689a4c8f02e
Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
3002
diff
changeset
|
685 |
changed_status = 'Unpublished' |
6689a4c8f02e
Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
3002
diff
changeset
|
686 |
elif request.POST.get('Publish'): |
6689a4c8f02e
Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
3002
diff
changeset
|
687 |
changed_status = 'Open' |
6689a4c8f02e
Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
3002
diff
changeset
|
688 |
|
6689a4c8f02e
Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
3002
diff
changeset
|
689 |
# update the status of task entities that should be approved or published |
2885 | 690 |
task_entities = [] |
3017
6689a4c8f02e
Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
3002
diff
changeset
|
691 |
|
6689a4c8f02e
Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
3002
diff
changeset
|
692 |
# get all the task keys to update, will return empty list if doesn't exist |
6689a4c8f02e
Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
3002
diff
changeset
|
693 |
task_keys = request.POST.getlist('task_id') |
6689a4c8f02e
Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
3002
diff
changeset
|
694 |
|
6689a4c8f02e
Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
3002
diff
changeset
|
695 |
for key_name in task_keys: |
6689a4c8f02e
Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
3002
diff
changeset
|
696 |
|
2885 | 697 |
task_entity = ghop_task_logic.logic.getFromKeyName(key_name) |
3017
6689a4c8f02e
Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
3002
diff
changeset
|
698 |
|
3034
aa5ebb226b22
Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
3033
diff
changeset
|
699 |
# Of course only the tasks from this organization and those with a valid |
3017
6689a4c8f02e
Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
3002
diff
changeset
|
700 |
# state can be updated. |
6689a4c8f02e
Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
3002
diff
changeset
|
701 |
if task_entity and task_entity.scope.key() == org_entity.key() and \ |
6689a4c8f02e
Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
3002
diff
changeset
|
702 |
task_entity.status in ['Unapproved', 'Unpublished']: |
6689a4c8f02e
Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
3002
diff
changeset
|
703 |
task_entity.status = changed_status |
2885 | 704 |
|
705 |
task_entities.append(task_entity) |
|
706 |
||
3017
6689a4c8f02e
Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
3002
diff
changeset
|
707 |
# bulk put the task_entities |
6689a4c8f02e
Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
3002
diff
changeset
|
708 |
# TODO: replace with Task API call? |
2885 | 709 |
db.put(task_entities) |
710 |
||
711 |
# redirect to the same page |
|
712 |
return http.HttpResponseRedirect('') |
|
713 |
||
714 |
def listOrgTasksGet(self, request, page_name, params, **kwargs): |
|
715 |
"""Handles the GET request for the list tasks view. |
|
716 |
""" |
|
717 |
||
718 |
from soc.modules.ghop.views.helper import list_info as list_info_helper |
|
719 |
||
720 |
org_entity = ghop_org_logic.logic.getFromKeyNameOr404( |
|
721 |
kwargs['scope_path']) |
|
722 |
||
723 |
contents = [] |
|
724 |
context = {} |
|
725 |
||
726 |
user_account = user_logic.logic.getForCurrentAccount() |
|
727 |
||
728 |
fields = { |
|
729 |
'user': user_account, |
|
730 |
'scope': org_entity, |
|
731 |
'status': 'active' |
|
732 |
} |
|
733 |
||
734 |
up_params = params.copy() |
|
735 |
# give the capability to approve tasks for the org_admins |
|
736 |
if ghop_org_admin_logic.logic.getForFields(fields, unique=True): |
|
737 |
up_params['list_template'] = 'modules/ghop/task/approve/approve.html' |
|
738 |
up_params['list_heading'] = 'modules/ghop/task/approve/heading.html' |
|
739 |
up_params['list_row'] = 'modules/ghop/task/approve/row.html' |
|
740 |
||
741 |
up_params['list_action'] = (redirects.getPublicRedirect, |
|
742 |
up_params) |
|
743 |
||
744 |
up_params['list_description'] = ugettext( |
|
3017
6689a4c8f02e
Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
3002
diff
changeset
|
745 |
'List of Unapproved tasks.') |
2885 | 746 |
|
747 |
filter = { |
|
748 |
'scope': org_entity, |
|
3017
6689a4c8f02e
Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
3002
diff
changeset
|
749 |
'status': 'Unapproved', |
2885 | 750 |
} |
751 |
||
2942
996e64ba2db8
Removed undefined order argument in GHOP Task View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2893
diff
changeset
|
752 |
up_list = lists.getListContent(request, up_params, filter, idx=0, |
2885 | 753 |
need_content=True) |
754 |
||
755 |
if up_list: |
|
756 |
up_mentors_list = {} |
|
757 |
for task_entity in up_list['data']: |
|
758 |
up_mentors_list[task_entity.key()] = db.get(task_entity.mentors) |
|
759 |
||
760 |
up_list['info'] = (list_info_helper.getTasksInfo(up_mentors_list), None) |
|
761 |
||
762 |
contents.append(up_list) |
|
763 |
context['up_list'] = True |
|
764 |
||
3017
6689a4c8f02e
Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
3002
diff
changeset
|
765 |
aup_params = params.copy() |
6689a4c8f02e
Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
3002
diff
changeset
|
766 |
aup_params['list_heading'] = 'modules/ghop/task/approve/heading.html' |
6689a4c8f02e
Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
3002
diff
changeset
|
767 |
aup_params['list_row'] = 'modules/ghop/task/approve/row.html' |
6689a4c8f02e
Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
3002
diff
changeset
|
768 |
|
6689a4c8f02e
Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
3002
diff
changeset
|
769 |
aup_params['list_action'] = (redirects.getPublicRedirect, |
6689a4c8f02e
Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
3002
diff
changeset
|
770 |
aup_params) |
6689a4c8f02e
Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
3002
diff
changeset
|
771 |
|
6689a4c8f02e
Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
3002
diff
changeset
|
772 |
aup_params['list_description'] = ugettext( |
6689a4c8f02e
Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
3002
diff
changeset
|
773 |
'List of Approved but Unpublished tasks.') |
6689a4c8f02e
Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
3002
diff
changeset
|
774 |
|
6689a4c8f02e
Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
3002
diff
changeset
|
775 |
filter = { |
6689a4c8f02e
Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
3002
diff
changeset
|
776 |
'scope': org_entity, |
6689a4c8f02e
Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
3002
diff
changeset
|
777 |
'status': 'Unpublished', |
6689a4c8f02e
Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
3002
diff
changeset
|
778 |
} |
6689a4c8f02e
Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
3002
diff
changeset
|
779 |
|
6689a4c8f02e
Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
3002
diff
changeset
|
780 |
aup_list = lists.getListContent(request, aup_params, filter, idx=1, |
6689a4c8f02e
Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
3002
diff
changeset
|
781 |
need_content=True) |
6689a4c8f02e
Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
3002
diff
changeset
|
782 |
|
6689a4c8f02e
Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
3002
diff
changeset
|
783 |
if aup_list: |
6689a4c8f02e
Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
3002
diff
changeset
|
784 |
aup_mentors_list = {} |
6689a4c8f02e
Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
3002
diff
changeset
|
785 |
for task_entity in aup_list['data']: |
6689a4c8f02e
Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
3002
diff
changeset
|
786 |
aup_mentors_list[task_entity.key()] = db.get(task_entity.mentors) |
6689a4c8f02e
Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
3002
diff
changeset
|
787 |
|
6689a4c8f02e
Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
3002
diff
changeset
|
788 |
aup_list['info'] = (list_info_helper.getTasksInfo(aup_mentors_list), None) |
6689a4c8f02e
Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
3002
diff
changeset
|
789 |
|
6689a4c8f02e
Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
3002
diff
changeset
|
790 |
contents.append(aup_list) |
6689a4c8f02e
Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
3002
diff
changeset
|
791 |
|
2885 | 792 |
ap_params = up_params.copy() |
793 |
ap_params['list_template'] = 'soc/models/list.html' |
|
794 |
ap_params['list_heading'] = 'modules/ghop/task/list/heading.html' |
|
795 |
ap_params['list_row'] = 'modules/ghop/task/list/row.html' |
|
796 |
||
797 |
ap_params['list_action'] = (redirects.getPublicRedirect, |
|
798 |
ap_params) |
|
799 |
||
800 |
ap_params['list_description'] = ugettext( |
|
3017
6689a4c8f02e
Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
3002
diff
changeset
|
801 |
'List of Published tasks.') |
2885 | 802 |
|
803 |
filter = { |
|
804 |
'scope': org_entity, |
|
805 |
'status': ['Open', 'Reopened', 'ClaimRequested', 'Claimed', |
|
3034
aa5ebb226b22
Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
3033
diff
changeset
|
806 |
'ActionNeeded', 'Closed', 'AwaitingRegistration', |
2885 | 807 |
'NeedsWork', 'NeedsReview'], |
808 |
} |
|
809 |
||
3017
6689a4c8f02e
Separated the publish and approve button on the Task list page for Org members.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
3002
diff
changeset
|
810 |
ap_list = lists.getListContent(request, ap_params, filter, idx=2, |
2885 | 811 |
need_content=True) |
812 |
||
813 |
if ap_list: |
|
814 |
ap_mentors_list = {} |
|
815 |
for task_entity in ap_list['data']: |
|
816 |
ap_mentors_list[task_entity.key()] = db.get(task_entity.mentors) |
|
817 |
||
818 |
ap_list['info'] = (list_info_helper.getTasksInfo(ap_mentors_list), None) |
|
819 |
||
820 |
contents.append(ap_list) |
|
821 |
||
822 |
# call the _list method from base to display the list |
|
823 |
return self._list(request, up_params, contents, page_name, context) |
|
824 |
||
825 |
@decorators.merge_params |
|
826 |
@decorators.check_access |
|
827 |
def public(self, request, access_type, |
|
828 |
page_name=None, params=None, **kwargs): |
|
829 |
"""See base.View.public(). |
|
830 |
""" |
|
831 |
||
832 |
# create default template context for use with any templates |
|
833 |
context = helper.responses.getUniversalContext(request) |
|
834 |
helper.responses.useJavaScript(context, params['js_uses_all']) |
|
835 |
context['page_name'] = page_name |
|
836 |
entity = None |
|
837 |
logic = params['logic'] |
|
838 |
||
839 |
try: |
|
840 |
entity, comment_entities, ws_entities = ( |
|
841 |
logic.getFromKeyFieldsWithCWSOr404(kwargs)) |
|
842 |
except out_of_band.Error, error: |
|
843 |
return helper.responses.errorResponse( |
|
844 |
error, request, template=params['error_public'], context=context) |
|
845 |
||
2981
8a99de852dc2
Fixed Task public view to always call the update method.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2978
diff
changeset
|
846 |
# because we are not sure if the Task API has called this for us we do it |
8a99de852dc2
Fixed Task public view to always call the update method.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2978
diff
changeset
|
847 |
entity, comment_entity = ghop_task_logic.logic.updateTaskStatus(entity) |
8a99de852dc2
Fixed Task public view to always call the update method.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2978
diff
changeset
|
848 |
if comment_entity: |
8a99de852dc2
Fixed Task public view to always call the update method.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2978
diff
changeset
|
849 |
comment_entities.append(comment_entity) |
2885 | 850 |
|
851 |
context['entity'] = entity |
|
3034
aa5ebb226b22
Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
3033
diff
changeset
|
852 |
context['entity_key_name'] = entity.key().id_or_name() |
2885 | 853 |
context['entity_type'] = params['name'] |
854 |
context['entity_type_url'] = params['url_name'] |
|
855 |
||
856 |
user_account = user_logic.logic.getForCurrentAccount() |
|
857 |
||
858 |
# get some entity specific context |
|
859 |
self.updatePublicContext(context, entity, comment_entities, |
|
860 |
ws_entities, user_account, params) |
|
861 |
||
3034
aa5ebb226b22
Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
3033
diff
changeset
|
862 |
validation = self._constructActionsList(context, entity, |
2885 | 863 |
user_account, params) |
864 |
||
865 |
context = dicts.merge(params['context'], context) |
|
866 |
||
867 |
if request.method == 'POST': |
|
3034
aa5ebb226b22
Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
3033
diff
changeset
|
868 |
return self.publicPost(request, context, params, entity, |
2885 | 869 |
user_account, validation, **kwargs) |
870 |
else: # request.method == 'GET' |
|
871 |
return self.publicGet(request, context, params, entity, |
|
872 |
user_account, **kwargs) |
|
873 |
||
874 |
def publicPost(self, request, context, params, entity, |
|
875 |
user_account=None, validation=None, **kwargs): |
|
876 |
"""Handles the POST request for the entity's public page. |
|
877 |
||
878 |
Args: |
|
879 |
entity: the task entity |
|
880 |
rest: see base.View.public() |
|
881 |
""" |
|
882 |
||
883 |
from soc.modules.ghop.logic.models import student as ghop_student_logic |
|
884 |
||
885 |
form = params['comment_form'](request.POST) |
|
886 |
||
887 |
if not form.is_valid(): |
|
888 |
template = params['public_template'] |
|
889 |
context['comment_form'] = form |
|
890 |
return self._constructResponse(request, entity, context, |
|
891 |
form, params, template=template) |
|
892 |
||
893 |
_, fields = helper.forms.collectCleanedFields(form) |
|
894 |
||
895 |
changes = [] |
|
896 |
||
897 |
action = fields['action'] |
|
898 |
||
899 |
properties = None |
|
900 |
ws_properties = None |
|
901 |
||
902 |
# TODO: this can be separated into several methods that handle the changes |
|
903 |
if validation == 'claim_request' and action == 'request': |
|
904 |
properties = { |
|
905 |
'status': 'ClaimRequested', |
|
906 |
'user': user_account, |
|
907 |
} |
|
908 |
||
909 |
st_filter = { |
|
910 |
'user': user_account, |
|
911 |
'scope': entity.program, |
|
912 |
'status': 'active' |
|
913 |
} |
|
914 |
student_entity = ghop_student_logic.logic.getForFields( |
|
915 |
st_filter, unique=True) |
|
916 |
||
917 |
if student_entity: |
|
918 |
properties['student'] = student_entity |
|
919 |
||
3034
aa5ebb226b22
Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
3033
diff
changeset
|
920 |
changes.extend([ugettext('User-Student'), |
aa5ebb226b22
Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
3033
diff
changeset
|
921 |
ugettext('Action-Claim Requested'), |
2885 | 922 |
ugettext('Status-%s' % (properties['status'])) |
923 |
]) |
|
3034
aa5ebb226b22
Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
3033
diff
changeset
|
924 |
elif (validation == 'claim_withdraw' or |
2885 | 925 |
validation == 'needs_review') and action == 'withdraw': |
926 |
properties = { |
|
927 |
'user': None, |
|
928 |
'student': None, |
|
929 |
'status': 'Reopened', |
|
930 |
'deadline': None, |
|
931 |
} |
|
932 |
||
933 |
changes.extend([ugettext('User-Student'), |
|
934 |
ugettext('Action-Withdrawn'), |
|
935 |
ugettext('Status-%s' % (properties['status'])) |
|
936 |
]) |
|
937 |
elif validation == 'needs_review' and action == 'needs_review': |
|
938 |
properties = { |
|
939 |
'status': 'NeedsReview', |
|
940 |
} |
|
941 |
||
942 |
changes.extend([ |
|
943 |
ugettext('User-Student'), |
|
944 |
ugettext('Action-Submitted work and Requested for review'), |
|
945 |
ugettext('Status-%s' % (properties['status']))]) |
|
946 |
||
947 |
ws_properties = { |
|
948 |
'parent': entity, |
|
949 |
'link_id': 't%i' % (int(time.time()*100)), |
|
950 |
'scope_path': entity.key().name(), |
|
951 |
'scope': entity.scope, |
|
952 |
'user': user_account, |
|
953 |
'information': fields['comment'], |
|
954 |
'url_to_work': fields['work_submission'], |
|
955 |
'submitted_on': datetime.datetime.now(), |
|
956 |
} |
|
957 |
elif validation == 'accept_claim': |
|
958 |
if action == 'accept': |
|
959 |
deadline = datetime.datetime.now() + datetime.timedelta( |
|
960 |
hours=entity.time_to_complete) |
|
961 |
||
962 |
properties = { |
|
963 |
'status': 'Claimed', |
|
964 |
'deadline': deadline, |
|
965 |
} |
|
966 |
||
967 |
changes.extend([ugettext('User-Mentor'), |
|
968 |
ugettext('Action-Claim Accepted'), |
|
969 |
ugettext('Status-%s' % (properties['status'])) |
|
970 |
]) |
|
971 |
||
972 |
task_update.spawnUpdateTask(entity) |
|
973 |
if action == 'reject': |
|
974 |
properties = { |
|
975 |
'user': None, |
|
976 |
'student': None, |
|
977 |
'status': 'Reopened', |
|
978 |
'deadline': None, |
|
979 |
} |
|
980 |
||
981 |
changes.extend([ugettext('User-Mentor'), |
|
982 |
ugettext('Action-Claim Rejected'), |
|
983 |
ugettext('Status-%s' % (properties['status'])) |
|
984 |
]) |
|
985 |
elif validation == 'close': |
|
986 |
if action == 'needs_work': |
|
987 |
properties = { |
|
988 |
'status': 'NeedsWork', |
|
989 |
} |
|
990 |
||
991 |
changes.extend([ugettext('User-Mentor'), |
|
992 |
ugettext('Action-Requested more work'), |
|
993 |
ugettext('Status-%s' % (properties['status'])) |
|
994 |
]) |
|
995 |
||
996 |
if fields['extended_deadline'] > 0: |
|
997 |
deadline = entity.deadline + datetime.timedelta( |
|
998 |
hours=fields['extended_deadline']) |
|
999 |
||
1000 |
properties['deadline'] = deadline |
|
1001 |
||
1002 |
changes.append(ugettext('DeadlineExtendedBy-%d hrs to %s' % ( |
|
1003 |
fields['extended_deadline'], deadline.strftime( |
|
1004 |
'%d %B %Y, %H :%M')))) |
|
1005 |
||
1006 |
task_update.spawnUpdateTask(entity) |
|
1007 |
else: |
|
1008 |
changes.append(ugettext('NoDeadlineExtensionGiven')) |
|
1009 |
elif action == 'reopened': |
|
1010 |
properties = { |
|
1011 |
'user': None, |
|
1012 |
'student': None, |
|
1013 |
'status': 'Reopened', |
|
1014 |
'deadline': None, |
|
1015 |
} |
|
1016 |
||
1017 |
changes.extend([ugettext('User-Mentor'), |
|
1018 |
ugettext('Action-Reopened'), |
|
1019 |
ugettext('Status-%s' % (properties['status'])) |
|
1020 |
]) |
|
1021 |
elif action == 'closed': |
|
1022 |
properties = { |
|
1023 |
'deadline': None, |
|
1024 |
} |
|
1025 |
||
1026 |
if entity.student: |
|
1027 |
properties['status'] = 'Closed' |
|
1028 |
else: |
|
1029 |
properties['status'] = 'AwaitingRegistration' |
|
1030 |
||
1031 |
changes.extend([ugettext('User-Mentor'), |
|
1032 |
ugettext('Action-Closed the task'), |
|
1033 |
ugettext('Status-%s' % (properties['status'])) |
|
1034 |
]) |
|
1035 |
||
1036 |
comment_properties = { |
|
1037 |
'parent': entity, |
|
1038 |
'scope_path': entity.key().name(), |
|
1039 |
'created_by': user_account, |
|
1040 |
'changes': changes, |
|
1041 |
} |
|
1042 |
||
1043 |
if ws_properties: |
|
1044 |
comment_properties['content'] = self.DEF_WS_MSG_FMT |
|
1045 |
else: |
|
1046 |
comment_properties['content'] = fields['comment'] |
|
1047 |
||
1048 |
ghop_task_logic.logic.updateEntityPropertiesWithCWS( |
|
1049 |
entity, properties, comment_properties, ws_properties) |
|
1050 |
||
1051 |
# redirect to the same page |
|
1052 |
return http.HttpResponseRedirect('') |
|
1053 |
||
1054 |
def publicGet(self, request, context, params, entity, |
|
1055 |
user_account, **kwargs): |
|
1056 |
"""Handles the GET request for the entity's public page. |
|
1057 |
||
1058 |
Args: |
|
1059 |
entity: the task entity |
|
1060 |
rest see base.View.public() |
|
1061 |
""" |
|
1062 |
||
1063 |
context['comment_form'] = params['comment_form']() |
|
1064 |
||
1065 |
template = params['public_template'] |
|
1066 |
||
1067 |
return responses.respond(request, template, context=context) |
|
1068 |
||
1069 |
def updatePublicContext(self, context, entity, comment_entities, |
|
1070 |
ws_entities, user_account, params): |
|
1071 |
"""Updates the context for the public page with information. |
|
1072 |
||
1073 |
Args: |
|
1074 |
context: the context that should be updated |
|
1075 |
entity: a task used to set context |
|
1076 |
user_account: user entity of the logged in user |
|
1077 |
params: dict with params for the view using this context |
|
1078 |
""" |
|
1079 |
||
1080 |
mentor_entities = db.get(entity.mentors) |
|
1081 |
mentors_str = "" |
|
1082 |
for mentor in mentor_entities: |
|
1083 |
mentors_str += mentor.name() + ", " |
|
1084 |
||
1085 |
if mentors_str: |
|
1086 |
context['mentors_str'] = mentors_str[:-2] |
|
1087 |
else: |
|
3034
aa5ebb226b22
Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
3033
diff
changeset
|
1088 |
context['mentors_str'] = "Not Assigned" |
2885 | 1089 |
|
1090 |
context['difficulty_str'] = entity.tags_string(entity.difficulty) |
|
1091 |
||
1092 |
context['task_type_str'] = entity.tags_string(entity.task_type) |
|
1093 |
||
1094 |
if entity.deadline: |
|
1095 |
# TODO: it should be able to abuse Django functionality for this |
|
1096 |
ttc = entity.deadline - datetime.datetime.now() |
|
1097 |
(ttc_min, ttc_hour) = ((ttc.seconds / 60), (ttc.seconds / 3600)) |
|
1098 |
if ttc_min >= 60: |
|
1099 |
ttc_min = ttc_min % 60 |
|
1100 |
if ttc_hour > 1: |
|
1101 |
if ttc_min == 0: |
|
1102 |
ttc_str = '%d hours' % (ttc_hour) |
|
1103 |
else: |
|
1104 |
ttc_str = '%d:%02d hours' % (ttc_hour, ttc_min) |
|
1105 |
if ttc.days == 1: |
|
1106 |
ttc_str = '%d day, %s' % (ttc.days, ttc_str) |
|
1107 |
elif ttc.days > 1: |
|
1108 |
ttc_str = '%d days, %s' % (ttc.days, ttc_str) |
|
1109 |
else: |
|
1110 |
ttc_str = '%d mins' % (ttc_min) |
|
1111 |
context['time_to_complete'] = ttc_str |
|
1112 |
else: |
|
1113 |
if entity.status == 'NeedsReview': |
|
1114 |
context['time_to_complete'] = 'No Time Left' |
|
1115 |
else: |
|
1116 |
context['time_to_complete'] = '%d hours' % (entity.time_to_complete) |
|
1117 |
||
1118 |
context['comments'] = comment_entities |
|
1119 |
||
1120 |
context['work_submissions'] = ws_entities |
|
1121 |
||
1122 |
def _constructActionsList(self, context, entity, |
|
1123 |
user_account, params): |
|
1124 |
"""Constructs a list of actions for the task page and extends |
|
1125 |
the comment form with this list. |
|
1126 |
||
3034
aa5ebb226b22
Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
3033
diff
changeset
|
1127 |
This method also returns the validation used by POST method to |
2885 | 1128 |
validate the user input data. |
1129 |
||
1130 |
Args: |
|
1131 |
context: the context that should be updated |
|
1132 |
entity: a task used to set context |
|
1133 |
user_account: user entity of the logged in user |
|
1134 |
params: dict with params for the view using this context |
|
1135 |
""" |
|
1136 |
||
1137 |
# variable that holds what kind of validation this user |
|
1138 |
# and task combination pass. |
|
1139 |
validation = None |
|
1140 |
||
1141 |
# The following header messages are shown for non-logged in |
|
1142 |
# general public, logged in public and the student. |
|
1143 |
if entity.status is 'Closed': |
|
1144 |
context['header_msg'] = self.DEF_TASK_CLOSED_MSG |
|
1145 |
validation = 'closed' |
|
1146 |
||
1147 |
if entity.status == 'Open': |
|
1148 |
context['header_msg'] = self.DEF_TASK_OPEN_MSG |
|
1149 |
elif entity.status == 'Reopened': |
|
1150 |
context['header_msg'] = self.DEF_TASK_REOPENED_MSG |
|
1151 |
||
1152 |
if user_account: |
|
1153 |
actions = [('noaction', 'Comment without action')] |
|
1154 |
||
1155 |
# if the user is logged give him the permission to claim |
|
1156 |
# the task only if he none of program host, org admin or mentor |
|
1157 |
filter = { |
|
1158 |
'user': user_account, |
|
1159 |
} |
|
1160 |
||
1161 |
host_entity = host_logic.logic.getForFields(filter, unique=True) |
|
1162 |
||
1163 |
filter['scope_path'] = entity.scope_path |
|
1164 |
org_admin_entity = ghop_org_admin_logic.logic.getForFields( |
|
1165 |
filter, unique=True) |
|
1166 |
mentor_entity = ghop_mentor_logic.logic.getForFields( |
|
1167 |
filter, unique=True) |
|
1168 |
||
1169 |
if host_entity or org_admin_entity or mentor_entity: |
|
1170 |
validation, mentor_actions = self._constructMentorActions( |
|
1171 |
context, entity) |
|
1172 |
actions += mentor_actions |
|
1173 |
if entity.status in ['Unapproved', 'Unpublished', 'Open']: |
|
1174 |
if host_entity or org_admin_entity: |
|
1175 |
context['edit_link'] = redirects.getEditRedirect(entity, params) |
|
1176 |
elif mentor_entity: |
|
1177 |
context['suggest_link'] = ghop_redirects.getSuggestTaskRedirect( |
|
1178 |
entity, params) |
|
1179 |
else: |
|
1180 |
validation, student_actions = self._constructStudentActions( |
|
1181 |
context, entity, user_account) |
|
1182 |
actions += student_actions |
|
1183 |
||
3034
aa5ebb226b22
Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
3033
diff
changeset
|
1184 |
# create the difficultly level field containing the choices |
2885 | 1185 |
# defined in the program entity |
1186 |
dynafields = [ |
|
1187 |
{'name': 'action', |
|
1188 |
'base': forms.ChoiceField, |
|
1189 |
'label': 'Action', |
|
1190 |
'required': False, |
|
1191 |
'passthrough': ['initial', 'required', 'choices'], |
|
1192 |
'choices': actions, |
|
1193 |
}, |
|
1194 |
] |
|
1195 |
||
1196 |
if validation == 'needs_review': |
|
1197 |
dynafields.append( |
|
1198 |
{'name': 'work_submission', |
|
1199 |
'base': forms.URLField, |
|
1200 |
'label': 'Submit Work', |
|
1201 |
'required': False, |
|
1202 |
'help_text': 'Provide a link to your work in this box. ' |
|
1203 |
'Please use the comment box if you need to explain ' |
|
1204 |
'of your work.', |
|
1205 |
}) |
|
1206 |
||
1207 |
if validation == 'close': |
|
1208 |
dynafields.append( |
|
1209 |
{'name': 'extended_deadline', |
|
1210 |
'base': forms.IntegerField, |
|
1211 |
'min_value': 1, |
|
1212 |
'label': 'Extend deadline by', |
|
1213 |
'required': False, |
|
1214 |
'passthrough': ['min_value', 'required', 'help_text'], |
|
1215 |
'help_text': 'Optional: Specify the number of hours by ' |
|
1216 |
'which you want to extend the deadline for the task ' |
|
1217 |
'for this student. ', |
|
1218 |
}) |
|
1219 |
||
1220 |
dynaproperties = params_helper.getDynaFields(dynafields) |
|
1221 |
if validation == 'needs_review': |
|
1222 |
dynaproperties['clean_work_submission'] = cleaning.clean_url( |
|
1223 |
'work_submission') |
|
1224 |
||
1225 |
extended_comment_form = dynaform.extendDynaForm( |
|
1226 |
dynaform=params['comment_form'], |
|
1227 |
dynaproperties=dynaproperties) |
|
1228 |
||
1229 |
params['comment_form'] = extended_comment_form |
|
1230 |
else: |
|
1231 |
# list of statuses a task can be in after it is requested to be |
|
1232 |
# claimed before closing or re-opening |
|
1233 |
claim_status = ['ClaimRequested', 'Claimed', 'ActionNeeded', |
|
1234 |
'NeedsWork', 'NeedsReview'] |
|
1235 |
if entity.status in claim_status: |
|
1236 |
context['header_msg'] = self.DEF_TASK_CLAIMED_MSG |
|
1237 |
elif entity.status in ['AwaitingRegistration', 'Closed']: |
|
1238 |
context['header_msg'] = self.DEF_TASK_CLOSED_MSG |
|
1239 |
||
1240 |
context['signin_comment_msg'] = self.DEF_SIGNIN_TO_COMMENT_MSG % ( |
|
1241 |
context['sign_in']) |
|
1242 |
||
1243 |
return validation |
|
1244 |
||
1245 |
def _constructMentorActions(self, context, entity): |
|
1246 |
"""Constructs the list of actions for mentors, org admins and |
|
1247 |
hosts. |
|
1248 |
""" |
|
1249 |
||
1250 |
# variable that holds what kind of validation this user |
|
1251 |
# and task combination pass. |
|
1252 |
validation = None |
|
1253 |
||
1254 |
actions = [] |
|
1255 |
||
1256 |
if entity.status in ['Unapproved', 'Unpublished']: |
|
1257 |
context['header_msg'] = self.DEF_TASK_UNPUBLISHED_MSG |
|
1258 |
context['comment_disabled'] = True |
|
1259 |
elif entity.status == 'Open': |
|
1260 |
context['header_msg'] = self.DEF_CAN_EDIT_TASK_MSG |
|
1261 |
elif entity.status == 'Reopened': |
|
1262 |
context['header_msg'] = self.DEF_TASK_MENTOR_REOPENED_MSG |
|
1263 |
elif entity.status == 'ClaimRequested': |
|
1264 |
actions.extend([('accept', 'Accept claim request'), |
|
1265 |
('reject', 'Reject claim request')]) |
|
1266 |
context['header_msg'] = self.DEF_TASK_CLAIM_REQUESTED_MSG |
|
1267 |
validation = 'accept_claim' |
|
1268 |
elif entity.status == 'Claimed': |
|
1269 |
context['header_msg'] = self.DEF_TASK_CLAIMED_BY_STUDENT_MSG |
|
1270 |
elif entity.status == 'NeedsReview': |
|
1271 |
context['header_msg'] = self.DEF_TASK_NEEDS_REVIEW_MSG |
|
1272 |
actions.extend([('needs_work', 'Needs More Work'), |
|
1273 |
('reopened', 'Reopen the task'), |
|
1274 |
('closed', 'Close the task')]) |
|
1275 |
validation = 'close' |
|
1276 |
elif entity.status in ['AwaitingRegistration', 'Closed']: |
|
1277 |
context['header_msg'] = self.DEF_TASK_CLOSED_MSG |
|
1278 |
||
1279 |
return validation, actions |
|
1280 |
||
1281 |
def _constructStudentActions(self, context, entity, user_account): |
|
1282 |
"""Constructs the list of actions for students. |
|
1283 |
""" |
|
1284 |
||
1285 |
# variable that holds what kind of validation this user |
|
1286 |
# and task combination pass. |
|
1287 |
validation = None |
|
1288 |
||
1289 |
actions = [] |
|
1290 |
||
1291 |
if entity.status in ['Open', 'Reopened']: |
|
1292 |
task_filter = { |
|
1293 |
'user': user_account, |
|
3034
aa5ebb226b22
Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
3033
diff
changeset
|
1294 |
'status': ['ClaimRequested', 'Claimed', 'ActionNeeded', |
2885 | 1295 |
'NeedsWork', 'NeedsReview'] |
1296 |
} |
|
1297 |
task_entities = ghop_task_logic.logic.getForFields(task_filter) |
|
1298 |
||
1299 |
if len(task_entities) >= entity.program.nr_simultaneous_tasks: |
|
1300 |
context['header_msg'] = self.DEF_MAX_TASK_LIMIT_MSG_FMT % ( |
|
1301 |
entity.program.nr_simultaneous_tasks) |
|
1302 |
validation = 'claim_ineligible' |
|
1303 |
return validation, actions |
|
1304 |
||
1305 |
task_filter['status'] = 'AwaitingRegistration' |
|
1306 |
task_entities = ghop_task_logic.logic.getForFields(task_filter) |
|
1307 |
||
1308 |
if task_entities: |
|
1309 |
context['header_msg'] = self.DEF_AWAITING_REG_MSG |
|
1310 |
validation = 'claim_ineligible' |
|
1311 |
else: |
|
1312 |
actions.append(('request', 'Request to claim the task')) |
|
1313 |
validation = 'claim_request' |
|
1314 |
||
1315 |
# TODO: lot of double information here that can be simplified |
|
1316 |
if entity.user and user_account.key() == entity.user.key(): |
|
1317 |
if entity.status == 'ClaimRequested': |
|
1318 |
context['header_msg'] = self.DEF_TASK_REQ_CLAIMED_BY_YOU_MSG |
|
1319 |
actions.append(('withdraw', 'Withdraw from the task')) |
|
1320 |
validation = 'claim_withdraw' |
|
3034
aa5ebb226b22
Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
3033
diff
changeset
|
1321 |
elif entity.status in ['Claimed', 'NeedsWork', |
2885 | 1322 |
'NeedsReview', 'ActionNeeded']: |
1323 |
context['header_msg'] = self.DEF_TASK_CLAIMED_BY_YOU_MSG |
|
1324 |
actions.extend([ |
|
1325 |
('withdraw', 'Withdraw from the task'), |
|
1326 |
('needs_review', 'Submit work and Request for review')]) |
|
1327 |
validation = 'needs_review' |
|
1328 |
elif entity.status == 'NeedsReview': |
|
1329 |
context['header_msg'] = self.DEF_TASK_NO_MORE_SUBMIT_MSG |
|
1330 |
actions.append(('withdraw', 'Withdraw from the task')) |
|
1331 |
if datetime.datetime.now < entity.deadline: |
|
1332 |
actions.append( |
|
1333 |
('needs_review', 'Submit work and Request for review')) |
|
1334 |
validation = 'needs_review' |
|
1335 |
elif entity.status == 'AwaitingRegistration': |
|
1336 |
context['header_msg'] = self.DEF_STUDENT_SIGNUP_MSG |
|
1337 |
elif entity.status == 'Closed': |
|
1338 |
context['header_msg'] = self.DEF_TASK_CMPLTD_BY_YOU_MSG |
|
1339 |
else: |
|
3034
aa5ebb226b22
Whitespaces fixed in task view.
Daniel Hans <Daniel.M.Hans@gmail.com>
parents:
3033
diff
changeset
|
1340 |
if entity.status in ['ClaimRequested', 'Claimed', |
2885 | 1341 |
'ActionNeeded', 'NeedsWork', |
1342 |
'NeedsReview']: |
|
1343 |
context['header_msg'] = self.DEF_TASK_CLAIMED_MSG |
|
1344 |
if entity.status in ['AwaitingRegistration', 'Closed']: |
|
1345 |
context['header_msg'] = self.DEF_TASK_CLOSED_MSG |
|
1346 |
||
1347 |
return validation, actions |
|
1348 |
||
1349 |
@decorators.merge_params |
|
1350 |
@decorators.check_access |
|
1351 |
def search(self, request, access_type, page_name=None, |
|
1352 |
params=None, filter=None, order=None,**kwargs): |
|
1353 |
"""View method to search for GHOP Tasks. |
|
1354 |
||
1355 |
Args: |
|
1356 |
request: the standard Django HTTP request object |
|
1357 |
access_type : the name of the access type which should be checked |
|
1358 |
page_name: the page name displayed in templates as page and header title |
|
1359 |
params: a dict with params for this View |
|
1360 |
kwargs: the Key Fields for the specified entity |
|
1361 |
""" |
|
1362 |
||
1363 |
from soc.modules.ghop.views.helper import list_info as list_info_helper |
|
1364 |
||
1365 |
get_params = request.GET |
|
1366 |
||
1367 |
contents = [] |
|
1368 |
context = {} |
|
1369 |
if not filter: |
|
1370 |
filter = {} |
|
1371 |
||
1372 |
public_status = ['Open', 'Reopened', 'ClaimRequested', 'Claimed', |
|
1373 |
'ActionNeeded', 'Closed', 'AwaitingRegistration', |
|
1374 |
'NeedsWork', 'NeedsReview'] |
|
1375 |
||
1376 |
task_params = params.copy() |
|
1377 |
task_params['list_template'] = 'modules/ghop/task/search/search.html' |
|
1378 |
task_params['list_heading'] = 'modules/ghop/task/search/heading.html' |
|
1379 |
task_params['list_row'] = 'modules/ghop/task/search/row.html' |
|
1380 |
||
1381 |
task_params['list_action'] = (redirects.getPublicRedirect, |
|
1382 |
task_params) |
|
1383 |
||
1384 |
task_params['list_description'] = ugettext( |
|
1385 |
'Search results: ') |
|
1386 |
||
1387 |
program_entity = ghop_program_logic.logic.getFromKeyFields(kwargs) |
|
1388 |
||
1389 |
org_fields = { |
|
1390 |
'scope': program_entity, |
|
1391 |
} |
|
1392 |
||
1393 |
org_entities = ghop_org_logic.logic.getForFields(org_fields) |
|
1394 |
org_names = [] |
|
1395 |
for org in org_entities: |
|
1396 |
org_names.append(org.name) |
|
1397 |
||
1398 |
df_entities = ghop_task_model.TaskDifficultyTag.get_by_scope( |
|
1399 |
program_entity) |
|
1400 |
difficulties = [] |
|
1401 |
for df_entity in df_entities: |
|
1402 |
difficulties.append(df_entity.tag) |
|
1403 |
||
1404 |
tt_entities = ghop_task_model.TaskTypeTag.get_by_scope(program_entity) |
|
1405 |
task_types = [] |
|
1406 |
for tt_entity in tt_entities: |
|
1407 |
task_types.append(tt_entity.tag) |
|
1408 |
||
1409 |
context['org_entities'] = org_names |
|
1410 |
context['public_status'] = public_status |
|
1411 |
context['difficulties'] = difficulties |
|
1412 |
context['tags'] = task_types |
|
1413 |
||
1414 |
org_filter = get_params.getlist('Organization') |
|
1415 |
status_filter = get_params.getlist('Status') |
|
1416 |
df_filter = get_params.getlist('Difficulty') |
|
1417 |
tag_filter = get_params.getlist('Tags') |
|
1418 |
||
1419 |
if org_filter: |
|
1420 |
org_fields = { |
|
1421 |
'scope': program_entity, |
|
1422 |
'name': org_filter, |
|
1423 |
} |
|
1424 |
org_entities = ghop_org_logic.logic.getForFields(org_fields) |
|
1425 |
filter['scope'] = org_entities |
|
1426 |
if status_filter: |
|
1427 |
filter['status']= status_filter |
|
1428 |
else: |
|
1429 |
filter['status'] = public_status |
|
1430 |
if df_filter: |
|
1431 |
filter['difficulty'] = df_filter |
|
1432 |
if tag_filter: |
|
1433 |
filter['task_type'] = tag_filter |
|
1434 |
||
1435 |
filter['program'] = program_entity |
|
1436 |
||
1437 |
task_list = lists.getListContent(request, task_params, filter, |
|
1438 |
order=order, idx=0, need_content=True) |
|
1439 |
||
1440 |
if task_list: |
|
1441 |
contents.append(task_list) |
|
1442 |
||
1443 |
# call the _list method from base to display the list |
|
1444 |
return self._list(request, task_params, contents, page_name, context) |
|
1445 |
||
1446 |
||
1447 |
view = View() |
|
1448 |
||
1449 |
create = decorators.view(view.create) |
|
1450 |
delete = decorators.view(view.delete) |
|
1451 |
edit = decorators.view(view.edit) |
|
1452 |
list = decorators.view(view.list) |
|
1453 |
list_org_tasks = decorators.view(view.listOrgTasks) |
|
1454 |
suggest_task = decorators.view(view.suggestTask) |
|
1455 |
public = decorators.view(view.public) |
|
1456 |
search = decorators.view(view.search) |