def wrapper(survey_entity, _): """Wrapper method. Args: survey_entity: a ProjectSurvey (or subclass) entity """ # try to retrieve the SurveyRecord for the given Survey and Project fields = {'survey': survey_entity, 'project': project_entity} record_entity = record_logic.getForFields(fields, unique=True) info = {'record': record_entity} if record_entity: # SurveyRecord has been found store the import data in info info['taken_by'] = record_entity.user.name info['taken_on'] = record_entity.modified else: info['taken_by'] = DEF_NO_RECORD_AVAILABLE_MESSAGE info['taken_on'] = DEF_NO_RECORD_AVAILABLE_MESSAGE take_redirect_info = {'survey': survey_entity, 'params': survey_params} info['take_url'] = redirects.getTakeProjectSurveyRedirect( project_entity, take_redirect_info) return info
def _selectProjects(self, request, page_name, params, survey, fields): """Shows a view upon which a User can select a Student Project to fill in the ProjectSurvey for. Args: survey: a Survey entity fields: the filter to use on the Project List rest: see base.View.public() """ from soc.modules.gsoc.views.models.student_project import view as \ student_project_view student_project_params = student_project_view.getParams().copy() redirect_dict = {'survey': survey, 'params': params} student_project_params['public_row_extra'] = lambda entity: { 'link': redirects.getTakeProjectSurveyRedirect(entity, redirect_dict) } student_project_params['list_description'] = ( "Select a %s for which to fill in the %s named %s" %( student_project_params['name'], params['name'], survey.title)) return self.list(request, 'allow', page_name=page_name, params=student_project_params, filter=fields)
def setProjectSurveyInfoForProject(list_content, project_entity, survey_params): """Sets the list info to a function for the given list. This function contains the information used for showing ProjectSurvey records on the StudentProject manage page. Args: list_content: list content for which to set the info project_entity: a StudentProject entity survey_params: params for the view of the type of Survey that is listed """ survey_logic = survey_params['logic'] record_logic = survey_logic.getRecordLogic() # store the needed info since Django calls the wrapper method for every # info call. info_storage = {} for survey_entity in list_content['data']: # try to retrieve the SurveyRecord for the given Survey and Project fields = {'survey': survey_entity, 'project': project_entity} record_entity = record_logic.getForFields(fields, unique=True) info = {'record': record_entity} if record_entity: # SurveyRecord has been found store the import data in info info['taken_by'] = record_entity.user.name info['taken_on'] = record_entity.modified info['record_url'] = redirects.getViewSurveyRecordRedirect(record_entity, survey_params) else: info['taken_by'] = DEF_NO_RECORD_AVAILABLE_MESSAGE info['taken_on'] = DEF_NO_RECORD_AVAILABLE_MESSAGE take_redirect_info = {'survey': survey_entity, 'params': survey_params} info['take_url'] = redirects.getTakeProjectSurveyRedirect( project_entity, take_redirect_info) info_storage[survey_entity.key()] = info def wrapper(item, _): """Wrapper method. """ return info_storage[item.key()] list_content['info'] = (wrapper, None) return list_content
def setProjectSurveyInfoForProject(list_content, project_entity, survey_params): """Sets the list info to a function for the given list. This function contains the information used for showing ProjectSurvey records on the StudentProject manage page. Args: list_content: list content for which to set the info project_entity: a StudentProject entity survey_params: params for the view of the type of Survey that is listed """ survey_logic = survey_params['logic'] record_logic = survey_logic.getRecordLogic() # store the needed info since Django calls the wrapper method for every # info call. info_storage = {} for survey_entity in list_content['data']: # try to retrieve the SurveyRecord for the given Survey and Project fields = {'survey': survey_entity, 'project': project_entity} record_entity = record_logic.getForFields(fields, unique=True) info = {'record': record_entity} if record_entity: # SurveyRecord has been found store the import data in info info['taken_by'] = record_entity.user.name info['taken_on'] = record_entity.modified info['record_url'] = redirects.getViewSurveyRecordRedirect( record_entity, survey_params) else: info['taken_by'] = DEF_NO_RECORD_AVAILABLE_MESSAGE info['taken_on'] = DEF_NO_RECORD_AVAILABLE_MESSAGE take_redirect_info = {'survey': survey_entity, 'params': survey_params} info['take_url'] = redirects.getTakeProjectSurveyRedirect( project_entity, take_redirect_info) info_storage[survey_entity.key()] = info def wrapper(item, _): """Wrapper method. """ return info_storage[item.key()] list_content['info'] = (wrapper, None) return list_content
def manage(self, request, access_type, page_name=None, params=None, **kwargs): """View that allows Organization Admins to manage their Student Projects. For params see base.View().public() """ import soc.logic.lists from soc.modules.gsoc.views.models.grading_project_survey import view as \ grading_survey_view from soc.modules.gsoc.views.models.project_survey import view as \ project_survey_view entity = self._logic.getFromKeyFieldsOr404(kwargs) template = params['manage_template'] # get the context for this webpage context = responses.getUniversalContext(request) responses.useJavaScript(context, params['js_uses_all']) context['page_name'] = "%s '%s' from %s" % (page_name, entity.title, entity.student.name()) context['entity'] = entity if project_logic.canChangeMentors(entity): # only accepted project can have their mentors managed self._enableMentorManagement(entity, params, context) # list all surveys for this Project's Program gps_params = grading_survey_view.getParams().copy() gps_params['list_description'] = \ 'List of all Mentor Evaluations for this Project' gps_params['public_row_extra'] = lambda entity, *args: {} gps_params['public_row_action'] = {} gps_params['public_field_keys'] = [ "title", "taken_by", "taken_on", "record_url", "take_url" ] gps_params['public_field_names'] = [ "Title", "Taken by", "Taken on", "View", "(Re) Take", ] no_record = self.DEF_NO_RECORD_AVAILABLE_MSG # TODO(SRabbelier): use buttons instead project_entity = entity getExtra = lambda params: lambda entity, re: { "taken_by": no_record if not re(entity) else re(entity).user.name, "taken_on": no_record if not re(entity) else str(re(entity).modified), "record_url": no_record if not re(entity) else lists.urlize( redirects.getViewSurveyRecordRedirect(re(entity), params), name=self.DEF_VIEW_RECORD_MSG), "take_url": lists.urlize(redirects.getTakeProjectSurveyRedirect( project_entity, {'survey': entity, 'params': params}), name=self.DEF_TAKE_SURVEY_MSG), } gps_params['public_field_extra'] = getExtra(gps_params) # get the ProjectSurvey list ps_params = project_survey_view.getParams().copy() ps_params['list_description'] = \ 'List of all Student Evaluations for this Project' ps_params['public_row_extra'] = lambda entity, *args: {} ps_params['public_row_action'] = {} ps_params['public_field_keys'] = gps_params['public_field_keys'] ps_params['public_field_names'] = gps_params['public_field_names'] ps_params['public_field_ignore'] = ["take_url"] ps_params['public_field_extra'] = getExtra(ps_params) if lists.isDataRequest(request): return self._getManageData(request, gps_params, ps_params, entity) gps_list = lists.getListGenerator(request, gps_params, idx=0) ps_list = lists.getListGenerator(request, ps_params, idx=1) # store both lists in the content content = [gps_list, ps_list] context['evaluation_list'] = soc.logic.lists.Lists(content) if request.POST: return self.managePost(request, template, context, params, entity, **kwargs) else: #request.GET return self.manageGet(request, template, context, params, entity, **kwargs)
def manage(self, request, access_type, page_name=None, params=None, **kwargs): """View that allows Organization Admins to manage their Student Projects. For params see base.View().public() """ import soc.logic.lists from soc.modules.gsoc.views.models.grading_project_survey import view as \ grading_survey_view from soc.modules.gsoc.views.models.project_survey import view as \ project_survey_view entity = self._logic.getFromKeyFieldsOr404(kwargs) template = params['manage_template'] # get the context for this webpage context = responses.getUniversalContext(request) responses.useJavaScript(context, params['js_uses_all']) context['page_name'] = "%s '%s' from %s" % (page_name, entity.title, entity.student.name()) context['entity'] = entity if project_logic.canChangeMentors(entity): # only accepted project can have their mentors managed self._enableMentorManagement(entity, params, context) # list all surveys for this Project's Program gps_params = grading_survey_view.getParams().copy() gps_params['list_description'] = \ 'List of all Mentor Evaluations for this Project' gps_params['public_row_extra'] = lambda entity, *args: {} gps_params['public_row_action'] = {} gps_params['public_field_keys'] = [ "title", "taken_by", "taken_on", "record_url", "take_url" ] gps_params['public_field_names'] = [ "Title", "Taken by", "Taken on", "View", "(Re) Take", ] no_record = self.DEF_NO_RECORD_AVAILABLE_MSG # TODO(SRabbelier): use buttons instead project_entity = entity getExtra = lambda params: lambda entity, re: { "taken_by": no_record if not re(entity) else re(entity).user.name, "taken_on": no_record if not re(entity) else str(re(entity).modified), "record_url": no_record if not re(entity) else lists.urlize( redirects.getViewSurveyRecordRedirect(re(entity), params), name=self.DEF_VIEW_RECORD_MSG), "take_url": lists.urlize(redirects.getTakeProjectSurveyRedirect( project_entity, { 'survey': entity, 'params': params }), name=self.DEF_TAKE_SURVEY_MSG), } gps_params['public_field_extra'] = getExtra(gps_params) # get the ProjectSurvey list ps_params = project_survey_view.getParams().copy() ps_params['list_description'] = \ 'List of all Student Evaluations for this Project' ps_params['public_row_extra'] = lambda entity, *args: {} ps_params['public_row_action'] = {} ps_params['public_field_keys'] = gps_params['public_field_keys'] ps_params['public_field_names'] = gps_params['public_field_names'] ps_params['public_field_ignore'] = ["take_url"] ps_params['public_field_extra'] = getExtra(ps_params) if lists.isDataRequest(request): return self._getManageData(request, gps_params, ps_params, entity) gps_list = lists.getListGenerator(request, gps_params, idx=0) ps_list = lists.getListGenerator(request, ps_params, idx=1) # store both lists in the content content = [gps_list, ps_list] context['evaluation_list'] = soc.logic.lists.Lists(content) if request.POST: return self.managePost(request, template, context, params, entity, **kwargs) else: #request.GET return self.manageGet(request, template, context, params, entity, **kwargs)