72 rights['delete'] = ['checkIsDeveloper'] |
72 rights['delete'] = ['checkIsDeveloper'] |
73 rights['show'] = ['allow'] |
73 rights['show'] = ['allow'] |
74 rights['list'] = ['checkIsDeveloper'] |
74 rights['list'] = ['checkIsDeveloper'] |
75 rights['manage'] = [('checkHasActiveRoleForScope', |
75 rights['manage'] = [('checkHasActiveRoleForScope', |
76 org_admin_logic), |
76 org_admin_logic), |
77 ('checkStudentProjectHasStatus', [['accepted']])] |
77 ('checkStudentProjectHasStatus', [['accepted', 'failed', 'completed', |
|
78 'withdrawn']])] |
78 rights['manage_overview'] = [('checkHasActiveRoleForScope', |
79 rights['manage_overview'] = [('checkHasActiveRoleForScope', |
79 org_admin_logic)] |
80 org_admin_logic)] |
80 # TODO: lack of better name here! |
81 # TODO: lack of better name here! |
81 rights['st_edit'] = ['checkIsMyStudentProject', |
82 rights['st_edit'] = ['checkIsMyStudentProject', |
82 ('checkStudentProjectHasStatus', |
83 ('checkStudentProjectHasStatus', |
348 try: |
348 try: |
349 entity = self._logic.getFromKeyFieldsOr404(kwargs) |
349 entity = self._logic.getFromKeyFieldsOr404(kwargs) |
350 except out_of_band.Error, error: |
350 except out_of_band.Error, error: |
351 return responses.errorResponse( |
351 return responses.errorResponse( |
352 error, request, template=params['error_public']) |
352 error, request, template=params['error_public']) |
353 |
|
354 get_dict = request.GET |
|
355 |
|
356 if 'remove' in get_dict: |
|
357 # get the mentor to remove |
|
358 fields = {'link_id': get_dict['remove'], |
|
359 'scope': entity.scope} |
|
360 mentor = mentor_logic.logic.getForFields(fields, unique=True) |
|
361 |
|
362 additional_mentors = entity.additional_mentors |
|
363 # pylint: disable-msg=E1103 |
|
364 if additional_mentors and mentor.key() in additional_mentors: |
|
365 # remove the mentor from the additional mentors list |
|
366 additional_mentors.remove(mentor.key()) |
|
367 fields = {'additional_mentors': additional_mentors} |
|
368 project_logic.updateEntityProperties(entity, fields) |
|
369 |
|
370 # redirect to the same page without GET arguments |
|
371 redirect = request.path |
|
372 return http.HttpResponseRedirect(redirect) |
|
373 |
353 |
374 template = params['manage_template'] |
354 template = params['manage_template'] |
375 |
355 |
376 # get the context for this webpage |
356 # get the context for this webpage |
377 context = responses.getUniversalContext(request) |
357 context = responses.getUniversalContext(request) |
378 responses.useJavaScript(context, params['js_uses_all']) |
358 responses.useJavaScript(context, params['js_uses_all']) |
379 context['page_name'] = "%s '%s' from %s" % (page_name, entity.title, |
359 context['page_name'] = "%s '%s' from %s" % (page_name, entity.title, |
380 entity.student.name()) |
360 entity.student.name()) |
381 context['entity'] = entity |
361 context['entity'] = entity |
|
362 |
|
363 |
|
364 if entity.status == 'accepted': |
|
365 # only accepted project can have their mentors managed |
|
366 self._enableMentorManagement(entity, params, context) |
|
367 |
|
368 context['evaluation_list'] = self._getEvaluationLists(request, params, |
|
369 entity) |
|
370 |
|
371 if request.POST: |
|
372 return self.managePost(request, template, context, params, entity, |
|
373 **kwargs) |
|
374 else: #request.GET |
|
375 return self.manageGet(request, template, context, params, entity, |
|
376 **kwargs) |
|
377 |
|
378 def _enableMentorManagement(self, entity, params, context): |
|
379 """Sets the data required to manage mentors for a StudentProject. |
|
380 |
|
381 Args: |
|
382 entity: StudentProject entity to manage |
|
383 params: params dict for the manage view |
|
384 context: context for the manage view |
|
385 """ |
382 |
386 |
383 # get all mentors for this organization |
387 # get all mentors for this organization |
384 fields = {'scope': entity.scope, |
388 fields = {'scope': entity.scope, |
385 'status': 'active'} |
389 'status': 'active'} |
386 mentors = mentor_logic.logic.getForFields(fields) |
390 mentors = mentor_logic.logic.getForFields(fields) |
447 dynaproperties = dynaproperties, |
451 dynaproperties = dynaproperties, |
448 ) |
452 ) |
449 |
453 |
450 params['additional_mentor_form'] = additional_mentor_form |
454 params['additional_mentor_form'] = additional_mentor_form |
451 |
455 |
452 context['evaluation_list'] = self._getEvaluationLists(request, params, |
|
453 entity) |
|
454 |
|
455 if request.POST: |
|
456 return self.managePost(request, template, context, params, entity, |
|
457 **kwargs) |
|
458 else: #request.GET |
|
459 return self.manageGet(request, template, context, params, entity, |
|
460 **kwargs) |
|
461 |
|
462 def _getEvaluationLists(self, request, params, entity): |
456 def _getEvaluationLists(self, request, params, entity): |
463 """Returns List Object containing the list to be shown on the Student |
457 """Returns List Object containing the list to be shown on the Student |
464 Project's manage page. |
458 Project's manage page. |
465 |
459 |
466 This list contains all Surveys that have at least one record and will also |
460 This list contains all Surveys that have at least one record and will also |
534 template: the template used for this view |
528 template: the template used for this view |
535 entity: the student project entity |
529 entity: the student project entity |
536 rest: see base.View.public() |
530 rest: see base.View.public() |
537 """ |
531 """ |
538 |
532 |
539 # populate form with the current mentor |
533 get_dict = request.GET |
540 initial = {'mentor_id': entity.mentor.link_id} |
534 |
541 context['mentor_edit_form'] = params['mentor_edit_form'](initial=initial) |
535 if 'remove' in get_dict and entity.status == 'accepted': |
542 |
536 # get the mentor to remove |
543 context['additional_mentor_form'] = params['additional_mentor_form']() |
537 fields = {'link_id': get_dict['remove'], |
|
538 'scope': entity.scope} |
|
539 mentor = mentor_logic.logic.getForFields(fields, unique=True) |
|
540 |
|
541 additional_mentors = entity.additional_mentors |
|
542 # pylint: disable- msg=E1103 |
|
543 if additional_mentors and mentor.key() in additional_mentors: |
|
544 # remove the mentor from the additional mentors list |
|
545 additional_mentors.remove(mentor.key()) |
|
546 fields = {'additional_mentors': additional_mentors} |
|
547 project_logic.updateEntityProperties(entity, fields) |
|
548 |
|
549 # redirect to the same page without GET arguments |
|
550 redirect = request.path |
|
551 return http.HttpResponseRedirect(redirect) |
|
552 |
|
553 if entity.status == 'accepted': |
|
554 # populate forms with the current mentors set |
|
555 initial = {'mentor_id': entity.mentor.link_id} |
|
556 context['mentor_edit_form'] = params['mentor_edit_form'](initial=initial) |
|
557 context['additional_mentor_form'] = params['additional_mentor_form']() |
544 |
558 |
545 return responses.respond(request, template, context) |
559 return responses.respond(request, template, context) |
546 |
560 |
547 def managePost(self, request, template, context, params, entity, **kwargs): |
561 def managePost(self, request, template, context, params, entity, **kwargs): |
548 """Handles the POST request for the project's manage page. |
562 """Handles the POST request for the project's manage page. |
553 rest: see base.View.public() |
567 rest: see base.View.public() |
554 """ |
568 """ |
555 |
569 |
556 post_dict = request.POST |
570 post_dict = request.POST |
557 |
571 |
558 if 'set_mentor' in post_dict: |
572 if 'set_mentor' in post_dict and entity.status == 'accepted': |
559 form = params['mentor_edit_form'](post_dict) |
573 form = params['mentor_edit_form'](post_dict) |
560 return self._manageSetMentor(request, template, context, params, entity, |
574 return self._manageSetMentor(request, template, context, params, entity, |
561 form) |
575 form) |
562 elif 'add_additional_mentor' in post_dict: |
576 elif 'add_additional_mentor' in post_dict and entity.status == 'accepted': |
563 form = params['additional_mentor_form'](post_dict) |
577 form = params['additional_mentor_form'](post_dict) |
564 return self._manageAddAdditionalMentor(request, template, context, |
578 return self._manageAddAdditionalMentor(request, template, context, |
565 params, entity, form) |
579 params, entity, form) |
566 else: |
580 else: |
567 # unexpected error return the normal page |
581 # unexpected error return the normal page |