def stEditPost(self, request, context, params, entity, **kwargs): """Handles the POST request for the student's edit page. Args: entity: the student project entity rest: see base.View.public() """ form = params['student_edit_form'](request.POST) if not form.is_valid(): return self._constructResponse(request, entity, context, form, params) _, fields = forms_helper.collectCleanedFields(form) project_logic.updateEntityProperties(entity, fields) return self.stEditGet(request, context, params, entity, **kwargs)
def _manageSetMentor(self, request, template, context, params, entity, form): """Handles the POST request for changing a Projects's mentor. Args: template: the template used for this view entity: the student project entity form: instance of the form used to set the mentor rest: see base.View.public() """ if not form.is_valid(): context['mentor_edit_form'] = form # add an a fresh additional mentors form context['additional_mentor_form'] = params['additional_mentor_form']() return responses.respond(request, template, context) _, fields = forms_helper.collectCleanedFields(form) # get the mentor from the form fields = {'link_id': fields['mentor_id'], 'scope': entity.scope, 'status': 'active'} mentor = mentor_logic.logic.getForFields(fields, unique=True) # update the project with the assigned mentor fields = {'mentor': mentor} additional_mentors = entity.additional_mentors # pylint: disable-msg=E1103 if additional_mentors and mentor.key() in additional_mentors: # remove the mentor that is now becoming the primary mentor additional_mentors.remove(mentor.key()) fields['additional_mentors'] = additional_mentors # update the project with the new mentor and possible # new set of additional mentors project_logic.updateEntityProperties(entity, fields) # redirect to the same page redirect = request.path return http.HttpResponseRedirect(redirect)
def _manageAddAdditionalMentor(self, request, template, context, params, entity, form): """Handles the POST request for changing a Projects's additional mentors. Args: template: the template used for this view entity: the student project entity form: instance of the form used to add an additional mentor rest: see base.View.public() """ if not form.is_valid(): context['additional_mentor_form'] = form # add a fresh edit mentor form initial = {'mentor_id': entity.mentor.link_id} context['mentor_edit_form'] = params['mentor_edit_form'](initial=initial) return responses.respond(request, template, context) _, fields = forms_helper.collectCleanedFields(form) # get the mentor from the form fields = {'link_id': fields['mentor_id'], 'scope': entity.scope, 'status': 'active'} mentor = mentor_logic.logic.getForFields(fields, unique=True) # add this mentor to the additional mentors if not entity.additional_mentors: additional_mentors = [mentor.key()] else: additional_mentors = entity.additional_mentors additional_mentors.append(mentor.key()) fields = {'additional_mentors': additional_mentors} project_logic.updateEntityProperties(entity, fields) # redirect to the same page redirect = request.path return http.HttpResponseRedirect(redirect)