def _manageStatisticsPost(self, request, access_type, page_name=None, params=None, **kwargs): """POST method for manage statistics request. """ logic = params['logic'] post_dict = request.POST selections = simplejson.loads(post_dict.get('data', '[]')) button_id = post_dict.get('button_id', '') modified_entities = [] for selection in selections: entity = logic.getFromKeyName(selection['key']) if not entity: logging.error('No notification found for %(key)s' % selection) continue # check if the current user can modify the statistic if button_id == 'collect_stats': fields = { 'url_name': params['url_name'], 'key_name': entity.key().name() } task_url = '/%(url_name)s/collect_task/%(key_name)s' % fields task = task_responses.startTask(task_url, queue_name='statistic') if not task: logging.error( 'There was an error. The task is not started') elif button_id == 'clear_stats': modified_entities.append(logic.clearStatistic(entity)) db.put(modified_entities) return http.HttpResponseRedirect('')
def updateOrClearStats(self, request, access_type, page_name=None, params=None, **kwargs): """Collects one batch of statistic or clears a statistic. """ get_dict = request.GET logic = params['logic'] link_id = kwargs['link_id'] scope_path = kwargs['scope_path'] statistic = None if 'update' in get_dict: statistic, _ = logic.collectDispatcher( self._getStatisticEntity(link_id, scope_path, logic)) elif 'clear' in get_dict: statistic = logic.clearStatistic( self._getStatisticEntity(link_id, scope_path, logic)) if statistic is not None: self._updateCacheList(statistic, scope_path, logic) self._updateCache(statistic, link_id, scope_path, logic) fields = { 'url_name': params['url_name'], 'scope_path': scope_path, 'link_id': link_id } if 'show_after_operation' in get_dict: return http.HttpResponseRedirect( '/%(url_name)s/show/%(scope_path)s/%(link_id)s' % fields) return http.HttpResponseRedirect( '/%(url_name)s/manage_stats/%(scope_path)s' % fields)
def _manageStatisticsPost(self, request, access_type, page_name=None, params=None, **kwargs): """POST method for manage statistics request. """ logic = params['logic'] post_dict = request.POST selections = simplejson.loads(post_dict.get('data', '[]')) button_id = post_dict.get('button_id', '') modified_entities = [] for selection in selections: entity = logic.getFromKeyName(selection['key']) if not entity: logging.error('No notification found for %(key)s' % selection) continue # check if the current user can modify the statistic if button_id == 'collect_stats': fields = { 'url_name': params['url_name'], 'key_name': entity.key().name() } task_url = '/%(url_name)s/collect_task/%(key_name)s' % fields task = task_responses.startTask(task_url, queue_name='statistic') if not task: logging.error('There was an error. The task is not started') elif button_id == 'clear_stats': modified_entities.append(logic.clearStatistic(entity)) db.put(modified_entities) return http.HttpResponseRedirect('')