25 import logging |
25 import logging |
26 import time |
26 import time |
27 |
27 |
28 from django import forms |
28 from django import forms |
29 from django import http |
29 from django import http |
|
30 from django.utils.translation import ugettext |
30 |
31 |
31 from soc.logic import cleaning |
32 from soc.logic import cleaning |
32 from soc.logic import dicts |
33 from soc.logic import dicts |
33 from soc.logic.models import mentor as mentor_logic |
34 from soc.logic.models import mentor as mentor_logic |
34 from soc.logic.models.organization import logic as org_logic |
35 from soc.logic.models.organization import logic as org_logic |
35 from soc.logic.models.org_admin import logic as org_admin_logic |
36 from soc.logic.models.org_admin import logic as org_admin_logic |
36 from soc.logic.models import student as student_logic |
37 from soc.logic.models import student as student_logic |
|
38 from soc.logic.models.program import logic as program_logic |
37 from soc.logic.models.student_project import logic as project_logic |
39 from soc.logic.models.student_project import logic as project_logic |
38 from soc.views import out_of_band |
40 from soc.views import out_of_band |
39 from soc.views.helper import access |
41 from soc.views.helper import access |
40 from soc.views.helper import decorators |
42 from soc.views.helper import decorators |
41 from soc.views.helper import dynaform |
43 from soc.views.helper import dynaform |
78 # TODO: lack of better name here! |
80 # TODO: lack of better name here! |
79 rights['st_edit'] = ['checkIsMyStudentProject', |
81 rights['st_edit'] = ['checkIsMyStudentProject', |
80 ('checkStudentProjectHasStatus', |
82 ('checkStudentProjectHasStatus', |
81 [['accepted', 'completed']]) |
83 [['accepted', 'completed']]) |
82 ] |
84 ] |
|
85 rights['withdraw'] = ['checkIsHostForProgram'] |
|
86 rights['withdraw_project'] = ['checkIsHost'] # TODO proper check |
|
87 rights['accept_project'] = ['checkIsHost'] # TODO proper check |
83 |
88 |
84 new_params = {} |
89 new_params = {} |
85 new_params['logic'] = soc.logic.models.student_project.logic |
90 new_params['logic'] = soc.logic.models.student_project.logic |
86 new_params['rights'] = rights |
91 new_params['rights'] = rights |
87 new_params['name'] = "Student Project" |
92 new_params['name'] = "Student Project" |
129 'soc.views.models.%(module_name)s.manage', |
134 'soc.views.models.%(module_name)s.manage', |
130 'Manage %(name)s'), |
135 'Manage %(name)s'), |
131 (r'^%(url_name)s/(?P<access_type>st_edit)/%(key_fields)s$', |
136 (r'^%(url_name)s/(?P<access_type>st_edit)/%(key_fields)s$', |
132 'soc.views.models.%(module_name)s.st_edit', |
137 'soc.views.models.%(module_name)s.st_edit', |
133 'Edit my %(name)s'), |
138 'Edit my %(name)s'), |
|
139 (r'^%(url_name)s/(?P<access_type>withdraw)/(?P<scope_path>%(ulnp)s)/%(lnp)s$', |
|
140 'soc.views.models.%(module_name)s.withdraw', |
|
141 'Withdraw %(name_plural)s'), |
|
142 (r'^%(url_name)s/(?P<access_type>withdraw_project)/%(key_fields)s$', |
|
143 'soc.views.models.%(module_name)s.withdraw_project', |
|
144 'Withdraw a %(name)s'), |
|
145 (r'^%(url_name)s/(?P<access_type>accept_project)/%(key_fields)s$', |
|
146 'soc.views.models.%(module_name)s.accept_project', |
|
147 'Accept a %(name)s'), |
134 ] |
148 ] |
135 |
149 |
136 new_params['extra_django_patterns'] = patterns |
150 new_params['extra_django_patterns'] = patterns |
137 |
151 |
138 new_params['edit_template'] = 'soc/student_project/edit.html' |
152 new_params['edit_template'] = 'soc/student_project/edit.html' |
222 additional_mentor = mentor_logic.logic.getFromKeyName( |
236 additional_mentor = mentor_logic.logic.getFromKeyName( |
223 mentor_key.id_or_name()) |
237 mentor_key.id_or_name()) |
224 mentor_names.append(additional_mentor.name()) |
238 mentor_names.append(additional_mentor.name()) |
225 |
239 |
226 context['additional_mentors'] = ', '.join(mentor_names) |
240 context['additional_mentors'] = ', '.join(mentor_names) |
|
241 |
|
242 @decorators.merge_params |
|
243 @decorators.check_access |
|
244 def withdraw(self, request, access_type, |
|
245 page_name=None, params=None, **kwargs): |
|
246 """View that allows Program Admins to withdraw Students. |
|
247 |
|
248 For params see base.View().public() |
|
249 """ |
|
250 |
|
251 program = program_logic.getFromKeyFieldsOr404(kwargs) |
|
252 |
|
253 fields = { |
|
254 'program': program, |
|
255 'status': ['accepted', 'completed'], |
|
256 } |
|
257 |
|
258 ap_params = params.copy() # accepted projects |
|
259 |
|
260 ap_params['list_action'] = (redirects.getWithdrawProjectRedirect, ap_params) |
|
261 ap_params['list_description'] = ugettext( |
|
262 "An overview of accepted and completed Projects.") |
|
263 |
|
264 ap_list = lists.getListContent( |
|
265 request, ap_params, fields, idx=0) |
|
266 |
|
267 fields['status'] = ['withdrawn', 'invalid', 'failed'] |
|
268 |
|
269 wp_params = params.copy() # withdrawn projects |
|
270 |
|
271 wp_params['list_action'] = (redirects.getAcceptProjectRedirect, wp_params) |
|
272 wp_params['list_description'] = ugettext( |
|
273 "An overview of withdrawn, invalid, and failed Projects.") |
|
274 |
|
275 wp_list = lists.getListContent( |
|
276 request, wp_params, fields, idx=1) |
|
277 |
|
278 # fill contents with all the needed lists |
|
279 contents = [ap_list, wp_list] |
|
280 |
|
281 # call the _list method from base to display the list |
|
282 return self._list(request, params, contents, page_name) |
|
283 |
|
284 @decorators.merge_params |
|
285 @decorators.check_access |
|
286 def withdrawProject(self, request, access_type, |
|
287 page_name=None, params=None, **kwargs): |
|
288 """View that allows Program Admins to withdraw Students. |
|
289 |
|
290 For params see base.View().public() |
|
291 |
|
292 """ |
|
293 |
|
294 logic = params['logic'] |
|
295 entity = logic.getFromKeyFieldsOr404(kwargs) |
|
296 |
|
297 fields = { |
|
298 'status': 'withdrawn', |
|
299 } |
|
300 |
|
301 logic.updateEntityProperties(entity, fields) |
|
302 |
|
303 url = redirects.getWithdrawRedirect(entity.program, params) |
|
304 |
|
305 return http.HttpResponseRedirect(url) |
|
306 |
|
307 @decorators.merge_params |
|
308 @decorators.check_access |
|
309 def acceptProject(self, request, access_type, |
|
310 page_name=None, params=None, **kwargs): |
|
311 """View that allows Program Admins to withdraw Students. |
|
312 |
|
313 For params see base.View().public() |
|
314 |
|
315 """ |
|
316 |
|
317 logic = params['logic'] |
|
318 entity = logic.getFromKeyFieldsOr404(kwargs) |
|
319 |
|
320 fields = { |
|
321 'status': 'accepted', |
|
322 } |
|
323 |
|
324 logic.updateEntityProperties(entity, fields) |
|
325 |
|
326 url = redirects.getWithdrawRedirect(entity.program, params) |
|
327 |
|
328 return http.HttpResponseRedirect(url) |
227 |
329 |
228 @decorators.merge_params |
330 @decorators.merge_params |
229 @decorators.check_access |
331 @decorators.check_access |
230 def manage(self, request, access_type, |
332 def manage(self, request, access_type, |
231 page_name=None, params=None, **kwargs): |
333 page_name=None, params=None, **kwargs): |