def _public(self, request, entity, context): """Adds the names of all additional mentors to the context. For params see base.View._public() """ additional_mentors = entity.additional_mentors if not additional_mentors: context['additional_mentors'] = [] else: mentor_names = [] for mentor_key in additional_mentors: additional_mentor = mentor_logic.getFromKeyName( mentor_key.id_or_name()) mentor_names.append(additional_mentor.name()) context['additional_mentors'] = ', '.join(mentor_names)
def _public(self, request, entity, context): """Adds the names of all additional mentors to the context. For params see base.View._public() """ additional_mentors = entity.additional_mentors if not additional_mentors: context['additional_mentors'] = [] else: mentor_names = [] for mentor_key in additional_mentors: additional_mentor = mentor_logic.getFromKeyName( mentor_key.id_or_name()) mentor_names.append(additional_mentor.name()) context['additional_mentors'] = ', '.join(mentor_names)
def _enableMentorManagement(self, entity, params, context): """Sets the data required to manage mentors for a StudentProject. Args: entity: StudentProject entity to manage params: params dict for the manage view context: context for the manage view """ context['can_manage_mentors'] = True # get all mentors for this organization fields = {'scope': entity.scope, 'status': 'active'} mentors = mentor_logic.getForFields(fields) choices = [(mentor.link_id,'%s (%s)' %(mentor.name(), mentor.link_id)) for mentor in mentors] # create the form that org admins will use to reassign a mentor dynafields = [ {'name': 'mentor_id', 'base': forms.ChoiceField, 'label': 'Primary Mentor', 'required': True, 'passthrough': ['required', 'choices', 'label'], 'choices': choices, },] dynaproperties = params_helper.getDynaFields(dynafields) mentor_edit_form = dynaform.newDynaForm( dynabase = params['dynabase'], dynaproperties = dynaproperties, ) params['mentor_edit_form'] = mentor_edit_form additional_mentors = entity.additional_mentors # we want to show the names of the additional mentors in the context # therefore they need to be resolved to entities first additional_mentors_context = [] for mentor_key in additional_mentors: mentor_entity = mentor_logic.getFromKeyName( mentor_key.id_or_name()) additional_mentors_context.append(mentor_entity) context['additional_mentors'] = additional_mentors_context # all mentors who are not already an additional mentor or # the primary mentor are allowed to become an additional mentor possible_additional_mentors = [m for m in mentors if (m.key() not in additional_mentors) and (m.key() != entity.mentor.key())] # create the information to be shown on the additional mentor form additional_mentor_choices = [ (mentor.link_id,'%s (%s)' %(mentor.name(), mentor.link_id)) for mentor in possible_additional_mentors] dynafields = [ {'name': 'mentor_id', 'base': forms.ChoiceField, 'label': 'Co-Mentor', 'required': True, 'passthrough': ['required', 'choices', 'label'], 'choices': additional_mentor_choices, },] dynaproperties = params_helper.getDynaFields(dynafields) additional_mentor_form = dynaform.newDynaForm( dynabase = params['dynabase'], dynaproperties = dynaproperties, ) params['additional_mentor_form'] = additional_mentor_form
def _enableMentorManagement(self, entity, params, context): """Sets the data required to manage mentors for a StudentProject. Args: entity: StudentProject entity to manage params: params dict for the manage view context: context for the manage view """ context['can_manage_mentors'] = True # get all mentors for this organization fields = {'scope': entity.scope, 'status': 'active'} mentors = mentor_logic.getForFields(fields) choices = [(mentor.link_id,'%s (%s)' %(mentor.name(), mentor.link_id)) for mentor in mentors] # create the form that org admins will use to reassign a mentor dynafields = [ {'name': 'mentor_id', 'base': forms.ChoiceField, 'label': 'Primary Mentor', 'required': True, 'passthrough': ['required', 'choices', 'label'], 'choices': choices, },] dynaproperties = params_helper.getDynaFields(dynafields) mentor_edit_form = dynaform.newDynaForm( dynabase = params['dynabase'], dynaproperties = dynaproperties, ) params['mentor_edit_form'] = mentor_edit_form additional_mentors = entity.additional_mentors # we want to show the names of the additional mentors in the context # therefore they need to be resolved to entities first additional_mentors_context = [] for mentor_key in additional_mentors: mentor_entity = mentor_logic.getFromKeyName( mentor_key.id_or_name()) additional_mentors_context.append(mentor_entity) context['additional_mentors'] = additional_mentors_context # all mentors who are not already an additional mentor or # the primary mentor are allowed to become an additional mentor possible_additional_mentors = [m for m in mentors if (m.key() not in additional_mentors) and (m.key() != entity.mentor.key())] # create the information to be shown on the additional mentor form additional_mentor_choices = [ (mentor.link_id,'%s (%s)' %(mentor.name(), mentor.link_id)) for mentor in possible_additional_mentors] dynafields = [ {'name': 'mentor_id', 'base': forms.ChoiceField, 'label': 'Co-Mentor', 'required': True, 'passthrough': ['required', 'choices', 'label'], 'choices': additional_mentor_choices, },] dynaproperties = params_helper.getDynaFields(dynafields) additional_mentor_form = dynaform.newDynaForm( dynabase = params['dynabase'], dynaproperties = dynaproperties, ) params['additional_mentor_form'] = additional_mentor_form