def _updateCacheList(self, statistic, scope_path, logic): """Update list of all statistics in memcache. """ if statistic.access_for_other_programs == 'invisible': filter = { 'scope_path': scope_path, 'access_for_other_programs': 'invisible' } else: filter = { 'access_for_other_programs': ['visible', 'collectable'] } entities, _ = soc.cache.logic.get(logic.getModel(), filter, order=None) if entities is not None: for i in range(len(entities)): if entities[i].link_id == statistic.link_id: entities[i] = statistic break soc.cache.logic.force_cache(logic.getModel(), filter, order=None, data=entities)
def _updateCacheList(self, statistic, scope_path, logic): """Update list of all statistics in memcache. """ if statistic.access_for_other_programs == 'invisible': filter = { 'scope_path': scope_path, 'access_for_other_programs': 'invisible' } else: filter = {'access_for_other_programs': ['visible', 'collectable']} entities, _ = soc.cache.logic.get(logic.getModel(), filter, order=None) if entities is not None: for i in range(len(entities)): if entities[i].link_id == statistic.link_id: entities[i] = statistic break soc.cache.logic.force_cache(logic.getModel(), filter, order=None, data=entities)
def _getAcceptedOrgsList(self, description, params, filter, use_cache): """Returns a list with all accepted orgs. Args: description: the description of the list params: the params to use filter: the filter to use use_cache: whether or not to use the cache """ logic = params['logic'] order = ['name'] if not use_cache: fun = self._getData else: # only cache if all profiles are created fun = soc.cache.logic.cache(self._getData) entities = fun(logic.getModel(), filter, order, logic) result = dicts.rename(params, params['list_params']) result['action'] = (redirects.getHomeRedirect, params) result['description'] = description result['pagination'] = 'soc/list/no_pagination.html' result['data'] = entities return result
def _getAllStatisticEntitiesForProgram(self, scope_path, logic): """Returns a list of statistics that can be accessed by a program. """ # There are two types of stats that can be accessed by a program: # - stats that are assigned to the particular program # - stats that are defined for another program but can be seen by others filter = { 'scope_path': scope_path, 'access_for_other_programs': 'invisible' } fun = soc.cache.logic.cache(self._getData) entities = fun(logic.getModel(), filter, order=None, logic=logic) filter = {'access_for_other_programs': ['visible', 'collectable']} entities += fun(logic.getModel(), filter, order=None, logic=logic) return entities
def _updateCache(self, statistic, link_id, scope_path, logic): """It updates cache value for a key associated with a specific statistic. """ filter = {'link_id': link_id, 'scope_path': scope_path} soc.cache.logic.force_cache(logic.getModel(), filter, order=None, data=[statistic])
def _updateCache(self, statistic, link_id, scope_path, logic): """It updates cache value for a key associated with a specific statistic. """ filter = { 'link_id': link_id, 'scope_path': scope_path } soc.cache.logic.force_cache(logic.getModel(), filter, order=None, data=[statistic])
def _getAllStatisticEntitiesForProgram(self, scope_path, logic): """Returns a list of statistics that can be accessed by a program. """ # There are two types of stats that can be accessed by a program: # - stats that are assigned to the particular program # - stats that are defined for another program but can be seen by others filter = { 'scope_path': scope_path, 'access_for_other_programs' : 'invisible' } fun = soc.cache.logic.cache(self._getData) entities = fun(logic.getModel(), filter, order=None, logic=logic) filter = { 'access_for_other_programs': ['visible', 'collectable'] } entities += fun(logic.getModel(), filter, order=None, logic=logic) return entities
def _getStatisticEntity(self, link_id, scope_path, logic): """Returns a statistic entity for given fields. """ filter = {'link_id': link_id, 'scope_path': scope_path} fun = soc.cache.logic.cache(self._getData) entities = fun(logic.getModel(), filter, order=None, logic=logic) if entities is not None and len(entities) != 0: return entities[0] else: return None
def _getStatisticEntity(self, link_id, scope_path, logic): """Returns a statistic entity for given fields. """ filter = { 'link_id': link_id, 'scope_path': scope_path } fun = soc.cache.logic.cache(self._getData) entities = fun(logic.getModel(), filter, order=None, logic=logic) if entities is not None and len(entities) != 0: return entities[0] else: return None
def pick(self, request, acces_type, page_name=None, params=None): """Displays a list page allowing the user to select an entity. After having selected an entity, the user is redirected to the return_url as specified in the GET args. Params usage: The params dictionary is passed to self.select, refer to its docstring for details on how it uses it. Args: request: the standard Django HTTP request object access_type : the name of the access type which should be checked page_name: the page name displayed in templates as page and header title params: a dict with params for this View """ logic = params['logic'] # convert to a regular dict filter = {} for key in request.GET.keys(): # need to use getlist as we want to support multiple values filter[key] = request.GET.getlist(key) if params['cache_pick']: fun = soc.cache.logic.cache(self._getData) else: fun = self._getData order = [] entities = fun(logic.getModel(), filter, order, logic) key_order = params.get('cache_pick_order') data = [i.toDict(key_order) for i in entities] return self.json(request, data)
def acceptedProjects(self, request, access_type, page_name=None, params=None, filter=None, **kwargs): """See base.View.list. """ contents = [] logic = params['logic'] program_entity = logic.getFromKeyFieldsOr404(kwargs) filter = { 'status': 'accepted', 'program': program_entity } fmt = {'name': program_entity.name} description = self.DEF_ACCEPTED_PROJECTS_MSG_FMT % fmt from soc.views.models import student_project as sp_view ap_params = sp_view.view.getParams().copy() # accepted projects fun = soc.cache.logic.cache(self._getData) ap_logic = ap_params['logic'] entities = fun(logic.getModel(), filter, order=None, logic=ap_logic) ap_list = dicts.rename(ap_params, ap_params['list_params']) ap_list['action'] = (redirects.getPublicRedirect, ap_params) ap_list['description'] = description ap_list['pagination'] = 'soc/list/no_pagination.html' ap_list['heading'] = 'soc/student_project/list/heading_all.html' ap_list['row'] = 'soc/student_project/list/row_all.html' ap_list['data'] = entities contents.append(ap_list) params = params.copy() return self._list(request, params, contents, page_name)