def manageOverview(self, request, access_type, page_name=None, params=None, **kwargs): """View that allows Organization Admins to see an overview of their Organization's Student Projects. For params see base.View().public() """ from soc.modules.gsoc.logic.models.survey import grading_logic as \ grading_survey_logic from soc.modules.gsoc.logic.models.survey import project_logic as \ project_survey_logic from soc.modules.gsoc.logic.models.survey_record import grading_logic from soc.modules.gsoc.logic.models.survey_record import project_logic # make sure the organization exists org_entity = org_logic.getFromKeyNameOr404(kwargs['scope_path']) page_name = '%s %s' % (page_name, org_entity.name) mo_params = params.copy() mo_params['list_heading'] = params['manage_overview_heading'] mo_params['list_row'] = params['manage_overview_row'] #list all active projects mo_params['list_description'] = \ 'List of all active %(name_plural)s' % mo_params mo_params['public_field_names'] = params['public_field_names'] + [ "Mentor evaluation", "Student Evaluation"] mo_params['public_field_keys'] = params['public_field_keys'] + [ "mentor_evaluation", "student_evaluation"] mo_params['public_row_extra'] = lambda entity, *args: { 'link': redirects.getManageRedirect(entity, mo_params) } mo_params['public_field_extra'] = lambda entity, ps, psc, gs, gsc: { "student": entity.student.name(), "mentor": entity.mentor.name(), "mentor_evaluation": "%d/%d" % ( project_logic.getQueryForFields({'project': entity}).count(), psc), "student_evaluation": "%d/%d" % ( grading_logic.getQueryForFields({'project': entity}).count(), gsc), } if request.GET.get('fmt') == 'json': return self.getManageOverviewData(request, mo_params, org_entity) mo_list = lists.getListGenerator(request, mo_params, idx=0) contents = [mo_list] # call the _list method from base to display the list return self._list(request, mo_params, contents, page_name)
def setStudentProjectSurveyInfo(list_content, program_entity): """Sets the list info to a method that returns information used in a Student Project table to show how many evaluations have been available and how many have been taken. Args: list_content: list content for which to set the info program_entity: the Program to check the total amount of (Grading)ProjctSurveys for Returns: The original list_content with info set """ from soc.modules.gsoc.logic.models.survey import grading_logic as \ grading_survey_logic from soc.modules.gsoc.logic.models.survey import project_logic as \ project_survey_logic from soc.modules.gsoc.logic.models.survey_record import grading_logic from soc.modules.gsoc.logic.models.survey_record import project_logic if not list_content: # this can happen because of the need_content parameter for getListContent return list_content fields = {'scope_path': program_entity.key().id_or_name()} # count the number of have been active ProjectSurveys project_surveys = project_survey_logic.getForFields(fields) project_survey_count = len(project_surveys) for project_survey in project_surveys: if not project_survey_logic.hasRecord(project_survey): project_survey_count = project_survey_count - 1 # count the number of have been active GradingProjectSurveys grading_surveys = grading_survey_logic.getForFields(fields) grading_survey_count = len(grading_surveys) for grading_survey in grading_surveys: if not grading_survey_logic.hasRecord(grading_survey): grading_survey_count = grading_survey_count - 1 # Pre-store the needed info since Django calls the wrapper method for every # info call. info_storage = {} for item in list_content['data']: fields = {'project': item} # count the amount of records we have on store for this project project_record_count = project_logic.getQueryForFields(fields).count() grading_record_count = grading_logic.getQueryForFields(fields).count() info = {'project_surveys_total': project_survey_count, 'project_surveys_completed': project_record_count, 'grading_project_surveys_total': grading_survey_count, 'grading_project_surveys_completed': grading_record_count} info_storage[item.key()] = info def wrapper(item, _): """Wrapper method. """ return info_storage[item.key()] list_content['info'] = (wrapper, None) return list_content
def manageOverview(self, request, access_type, page_name=None, params=None, **kwargs): """View that allows Organization Admins to see an overview of their Organization's Student Projects. For params see base.View().public() """ from soc.modules.gsoc.logic.models.survey import grading_logic as \ grading_survey_logic from soc.modules.gsoc.logic.models.survey import project_logic as \ project_survey_logic from soc.modules.gsoc.logic.models.survey_record import grading_logic from soc.modules.gsoc.logic.models.survey_record import project_logic # make sure the organization exists org_entity = org_logic.getFromKeyNameOr404(kwargs['scope_path']) page_name = '%s %s' % (page_name, org_entity.name) mo_params = params.copy() #list all active projects mo_params['list_description'] = ugettext( 'List of all %s for %s, if you are an Org Admin you can click ' 'a project for more actions. Such as reassigning mentors or viewing ' 'results of the evaluations.' %(params['name_plural'], org_entity.name) ) mo_params['public_field_names'] = params['public_field_names'] + [ 'Mentor evaluation', 'Student Evaluation'] mo_params['public_field_keys'] = params['public_field_keys'] + [ 'mentor_evaluation', 'student_evaluation'] fields = {'scope': org_entity, 'status': ['active', 'inactive']} org_admin = org_admin_logic.getForFields(fields, unique=True) # Org Admins get a link to manage the project, others go to public page if org_admin: mo_params['public_row_extra'] = lambda entity, *args: { 'link': redirects.getManageRedirect(entity, mo_params) } else: mo_params['public_row_extra'] = lambda entity, *args: { 'link': redirects.getPublicRedirect(entity, mo_params) } mo_params['public_field_prefetch'] = ['student', 'mentor', 'scope'] mo_params['public_field_extra'] = lambda entity, ps, psc, gs, gsc: { 'org': entity.scope.name, 'student': '%s (%s)' % (entity.student.name(), entity.student.email), 'mentor': entity.mentor.name(), 'mentor_evaluation': '%d/%d' % ( grading_logic.getQueryForFields({'project': entity}).count(), gsc), 'student_evaluation': '%d/%d' % ( project_logic.getQueryForFields({'project': entity}).count(), psc), } if lists.isDataRequest(request): return self.getManageOverviewData(request, mo_params, org_entity) mo_list = lists.getListGenerator(request, mo_params, idx=0) contents = [mo_list] # call the _list method from base to display the list return self._list(request, mo_params, contents, page_name)
def setStudentProjectSurveyInfo(list_content, program_entity): """Sets the list info to a method that returns information used in a Student Project table to show how many evaluations have been available and how many have been taken. Args: list_content: list content for which to set the info program_entity: the Program to check the total amount of (Grading)ProjctSurveys for Returns: The original list_content with info set """ from soc.modules.gsoc.logic.models.survey import grading_logic as \ grading_survey_logic from soc.modules.gsoc.logic.models.survey import project_logic as \ project_survey_logic from soc.modules.gsoc.logic.models.survey_record import grading_logic from soc.modules.gsoc.logic.models.survey_record import project_logic if not list_content: # this can happen because of the need_content parameter for getListContent return list_content fields = {'scope_path': program_entity.key().id_or_name()} # count the number of have been active ProjectSurveys project_surveys = project_survey_logic.getForFields(fields) project_survey_count = len(project_surveys) for project_survey in project_surveys: if not project_survey_logic.hasRecord(project_survey): project_survey_count = project_survey_count - 1 # count the number of have been active GradingProjectSurveys grading_surveys = grading_survey_logic.getForFields(fields) grading_survey_count = len(grading_surveys) for grading_survey in grading_surveys: if not grading_survey_logic.hasRecord(grading_survey): grading_survey_count = grading_survey_count - 1 # Pre-store the needed info since Django calls the wrapper method for every # info call. info_storage = {} for item in list_content['data']: fields = {'project': item} # count the amount of records we have on store for this project project_record_count = project_logic.getQueryForFields(fields).count() grading_record_count = grading_logic.getQueryForFields(fields).count() info = { 'project_surveys_total': project_survey_count, 'project_surveys_completed': project_record_count, 'grading_project_surveys_total': grading_survey_count, 'grading_project_surveys_completed': grading_record_count } info_storage[item.key()] = info def wrapper(item, _): """Wrapper method. """ return info_storage[item.key()] list_content['info'] = (wrapper, None) return list_content
def manageOverview(self, request, access_type, page_name=None, params=None, **kwargs): """View that allows Organization Admins to see an overview of their Organization's Student Projects. For params see base.View().public() """ from soc.modules.gsoc.logic.models.survey import grading_logic as \ grading_survey_logic from soc.modules.gsoc.logic.models.survey import project_logic as \ project_survey_logic from soc.modules.gsoc.logic.models.survey_record import grading_logic from soc.modules.gsoc.logic.models.survey_record import project_logic # make sure the organization exists org_entity = org_logic.getFromKeyNameOr404(kwargs['scope_path']) page_name = '%s %s' % (page_name, org_entity.name) mo_params = params.copy() #list all active projects mo_params['list_description'] = ugettext( 'List of all %s for %s, if you are an Org Admin you can click ' 'a project for more actions. Such as reassigning mentors or viewing ' 'results of the evaluations.' % (params['name_plural'], org_entity.name)) mo_params['public_field_names'] = params['public_field_names'] + [ 'Mentor evaluation', 'Student Evaluation' ] mo_params['public_field_keys'] = params['public_field_keys'] + [ 'mentor_evaluation', 'student_evaluation' ] fields = {'scope': org_entity, 'status': ['active', 'inactive']} org_admin = org_admin_logic.getForFields(fields, unique=True) # Org Admins get a link to manage the project, others go to public page if org_admin: mo_params['public_row_extra'] = lambda entity, *args: { 'link': redirects.getManageRedirect(entity, mo_params) } else: mo_params['public_row_extra'] = lambda entity, *args: { 'link': redirects.getPublicRedirect(entity, mo_params) } mo_params['public_field_prefetch'] = ['student', 'mentor', 'scope'] mo_params['public_field_extra'] = lambda entity, ps, psc, gs, gsc: { 'org': entity.scope.name, 'student': '%s (%s)' % (entity.student.name(), entity.student.email), 'mentor': entity.mentor.name(), 'mentor_evaluation': '%d/%d' % (grading_logic.getQueryForFields({ 'project': entity }).count(), gsc), 'student_evaluation': '%d/%d' % (project_logic.getQueryForFields({ 'project': entity }).count(), psc), } if lists.isDataRequest(request): return self.getManageOverviewData(request, mo_params, org_entity) mo_list = lists.getListGenerator(request, mo_params, idx=0) contents = [mo_list] # call the _list method from base to display the list return self._list(request, mo_params, contents, page_name)