def getAvailableStatistics(self, request, access_type, page_name=None, params=None, **kwargs): """Returns a list of all statistics that the user has access to. """ logic = params['logic'] data = {} programs = program_logic.getForFields() key_names = [] for program in programs: fields = { 'link_id': program.link_id, 'scope_path': program.scope_path } key_name = program_logic.getKeyNameFromFields(fields) data[key_name] = {'name': program.name, 'statistics': []} statistics = logic.getForFields() for statistic in statistics: has_access = self._checkHasStatisticAccess(statistic) if has_access: data[statistic.scope_path]['statistics'].append({ 'link_id': statistic.link_id, 'name': statistic.name }) return self.json(request, data)
def getAvailableStatistics(self, request, access_type, page_name=None, params=None, **kwargs): """Returns a list of all statistics that the user has access to. """ logic = params['logic'] data = {} programs = program_logic.getForFields() key_names = [] for program in programs: fields = { 'link_id': program.link_id, 'scope_path': program.scope_path } key_name = program_logic.getKeyNameFromFields(fields) data[key_name] = { 'name': program.name, 'statistics': [] } statistics = logic.getForFields() for statistic in statistics: has_access = self._checkHasStatisticAccess(statistic) if has_access: data[statistic.scope_path]['statistics'].append({ 'link_id': statistic.link_id, 'name': statistic.name }) return self.json(request, data)
def _getData(self, model, filter, order, logic): """Retrieves the pick data for this query. Args: model: the model that is being queried filter: the filters that apply logic: the logic that will be used for the query """ entities = logic.getForFields(filter=filter, order=order, limit=1000) return entities
def getExtraMenus(self, id, user, params=None): """Returns the extra menu's for this view. A menu item is generated for each program that is currently running. The public page for each program is added as menu item, as well as all public documents for that program. Args: params: a dict with params for this View. """ from soc.views.models import survey as survey_view from soc.views.models import project_survey as project_survey_view from soc.views.models import grading_project_survey as grading_survey_view logic = params['logic'] rights = params['rights'] # only get all invisible and visible programs fields = {'status': ['invisible', 'visible']} entities = logic.getForFields(fields) menus = [] rights.setCurrentUser(id, user) for entity in entities: items = [] if entity.status == 'visible': # show the documents for this program, even for not logged in users items += document_view.view.getMenusForScope(entity, params) items += survey_view.view.getMenusForScope(entity, params, id, user) items += project_survey_view.view.getMenusForScope( entity, params, id, user) items += grading_survey_view.view.getMenusForScope( entity, params, id, user) items += self._getTimeDependentEntries(entity, params, id, user) try: # check if the current user is a host for this program rights.doCachedCheck('checkIsHostForProgram', {'scope_path': entity.scope_path, 'link_id': entity.link_id}, []) if entity.status == 'invisible': # still add the document links so hosts can see how it looks like items += document_view.view.getMenusForScope(entity, params) items += survey_view.view.getMenusForScope(entity, params, id, user) items += project_survey_view.view.getMenusForScope( entity, params, id, user) items += grading_survey_view.view.getMenusForScope( entity, params, id, user) items += self._getTimeDependentEntries(entity, params, id, user) items += [(redirects.getReviewOverviewRedirect( entity, {'url_name': 'org_app'}), "Review Organization Applications", 'any_access')] # add link to edit Program Profile items += [(redirects.getEditRedirect(entity, params), 'Edit Program Profile', 'any_access')] # add link to Assign Slots items += [(redirects.getAssignSlotsRedirect(entity, params), 'Assign Slots', 'any_access')] # add link to Show Duplicate project assignments items += [(redirects.getShowDuplicatesRedirect(entity, params), 'Show Duplicate Project Assignments', 'any_access')] # add link to edit Program Timeline items += [(redirects.getEditRedirect(entity, {'url_name': 'timeline'}), "Edit Program Timeline", 'any_access')] # add link to create a new Program Document items += [(redirects.getCreateDocumentRedirect(entity, 'program'), "Create a New Document", 'any_access')] # add link to list all Program Document items += [(redirects.getListDocumentsRedirect(entity, 'program'), "List Documents", 'any_access')] # add link to create a new Program Survey items += [(redirects.getCreateSurveyRedirect(entity, 'program', 'survey'), "Create a New Survey", 'any_access')] # add link to list all Program Surveys items += [(redirects.getListSurveysRedirect(entity, 'program', 'survey'), "List Surveys", 'any_access')] # add link to create a new Project Survey items += [(redirects.getCreateSurveyRedirect(entity, 'program', 'project_survey'), "Create a New Project Survey", 'any_access')] # add link to list all Project Surveys items += [(redirects.getListSurveysRedirect(entity, 'program', 'project_survey'), "List Project Surveys", 'any_access')] # add link to create a new Grading Survey items += [(redirects.getCreateSurveyRedirect(entity, 'program', 'grading_project_survey'), "Create a New Grading Survey", 'any_access')] # add link to list all Grading Surveys items += [(redirects.getListSurveysRedirect(entity, 'program', 'grading_project_survey'), "List Grading Surveys", 'any_access')] except out_of_band.Error: pass items = sidebar.getSidebarMenu(id, user, items, params=params) if not items: continue menu = {} menu['heading'] = entity.short_name menu['items'] = items menu['group'] = 'Programs' menus.append(menu) return menus
def getExtraMenus(self, id, user, params=None): """See soc.views.models.program.View.getExtraMenus(). """ # TODO: the largest part of this method can be moved to the core Program logic = params['logic'] rights = params['rights'] # only get all invisible and visible programs fields = {'status': ['invisible', 'visible']} entities = logic.getForFields(fields) menus = [] rights.setCurrentUser(id, user) for entity in entities: items = [] if entity.status == 'visible': # show the documents for this program, even for not logged in users items += document_view.view.getMenusForScope(entity, params) items += self._getTimeDependentEntries(entity, params, id, user) try: # check if the current user is a host for this program rights.doCachedCheck('checkIsHostForProgram', { 'scope_path': entity.scope_path, 'link_id': entity.link_id }, [logic]) if entity.status == 'invisible': # still add the document links so hosts can see how it looks like items += self._getTimeDependentEntries( entity, params, id, user) items += self._getHostEntries(entity, params, 'ghop') items += [(redirects.getReviewOverviewRedirect( entity, { 'url_name': 'ghop/org_app', 'scope_view': self }), "Review Organization Applications", 'any_access')] # add link to Assign Task Quota limits items += [(ghop_redirects.getAssignTaskQuotasRedirect( entity, params), 'Assign Task Quota limits', 'any_access')] # add link to edit Task Difficulty Levels items += [(ghop_redirects.getDifficultyEditRedirect( entity, {'url_name': 'ghop/program'}), "Edit Task Difficulty Levels", 'any_access')] # add link to edit Task Type Tags items += [(ghop_redirects.getTaskTypeEditRedirect( entity, {'url_name': 'ghop/program'}), "Edit Task Type Tags", 'any_access')] except out_of_band.Error: pass items = sidebar.getSidebarMenu(id, user, items, params=params) if not items: continue menu = {} menu['heading'] = entity.short_name menu['items'] = items menu['group'] = 'Programs' menus.append(menu) return menus