def partial_response(self): indicator_slug = self.request.GET.get('indicator') response = { 'error': True, 'message': 'Indicator could not be processed.' } cache_key = self.indicator_cache_key(indicator_slug) cached_data = cache.get(cache_key) if cached_data and self.cache_indicators: response = cached_data elif indicator_slug: try: indicator = DynamicIndicatorDefinition.get_current(MVP.NAMESPACE, self.domain, indicator_slug, wrap_correctly=True) response = self.get_response_for_indicator(indicator) if response is not None: cache.set(cache_key, response, 3600) else: response = { 'error': True, 'message': 'This Indicator is currently undergoing updates. Please check back shortly.' } except (ResourceNotFound, AttributeError): response['message'] = "Indicator '%s' could not be found." % indicator_slug return HttpResponse(json.dumps(response))
def get_indicator_response(self, indicator_slug): indicator = DynamicIndicatorDefinition.get_current(MVP.NAMESPACE, self.domain, indicator_slug, wrap_correctly=True) result = indicator.get_value(self.user_ids, datespan=self.datespan) print(result)
def partial_response(self): indicator_slug = self.request.GET.get('indicator') response = { 'error': True, 'message': 'Indicator could not be processed.' } cache_key = self.indicator_cache_key(indicator_slug, is_debug=self.is_debug) cached_data = cache.get(cache_key) if cached_data and self.return_cached_data: response = cached_data elif indicator_slug: try: indicator = DynamicIndicatorDefinition.get_current( MVP.NAMESPACE, self.domain, indicator_slug, wrap_correctly=True, ) response = self.get_response_for_indicator(indicator) if response is not None: cache.set(cache_key, response, 3600) else: response = { 'error': True, 'message': ("This Indicator is currently undergoing updates. " "Please check back shortly."), } except (ResourceNotFound, AttributeError): response[ 'message'] = "Indicator '%s' could not be found." % indicator_slug return HttpResponse(json.dumps(response), content_type='application/json')
def report_context(self): report_matrix = [] month_headers = None for category_group in self.indicator_slugs: category_indicators = [] total_rowspan = 0 for slug in category_group['indicator_slugs']: try: indicator = DynamicIndicatorDefinition.get_current( MVP.NAMESPACE, self.domain, slug, wrap_correctly=True, ) if self.is_rendered_as_email: retrospective = indicator.get_monthly_retrospective( user_ids=self.user_ids) else: retrospective = indicator.get_monthly_retrospective( return_only_dates=True) if not month_headers: month_headers = self.get_month_headers(retrospective) if isinstance(indicator, CombinedCouchViewIndicatorDefinition): table = self.get_indicator_table(retrospective) indicator_rowspan = 3 else: table = self.get_indicator_row(retrospective) indicator_rowspan = 1 total_rowspan += indicator_rowspan + 1 category_indicators.append( dict(title=indicator.description, table=table, load_url="%s?indicator=%s" % (self.get_url(self.domain, render_as='partial'), indicator.slug), rowspan=indicator_rowspan)) except (AttributeError, ResourceNotFound): logging.info("Could not grab indicator %s in domain %s" % (slug, self.domain)) report_matrix.append( dict( category_title=category_group['category_title'], category_slug=category_group['category_slug'], rowspan=total_rowspan, indicators=category_indicators, )) return dict( months=month_headers, report=report_matrix, )
def indicators(self): all_indicators = list() for section in self.indicator_slugs: section_indicators = list() for indicator_content in section.get('indicators', []): slug = indicator_content.get('slug') if slug: indicator = DynamicIndicatorDefinition.get_current(MVP.NAMESPACE, self.domain, slug, wrap_correctly=True) if indicator is not None: section_indicators.append(indicator) else: logging.error("could not load indicator %s" % slug) all_indicators.append(section_indicators) return all_indicators
def indicators(self): all_indicators = list() for section in self.indicator_slugs: section_indicators = list() for indicator_content in section.get('indicators', []): slug = indicator_content.get('slug') if slug: indicator = DynamicIndicatorDefinition.get_current( MVP.NAMESPACE, self.domain, slug, wrap_correctly=True) if indicator is not None: section_indicators.append(indicator) else: logging.error("could not load indicator %s" % slug) all_indicators.append(section_indicators) return all_indicators
def report_context(self): report_matrix = [] month_headers = None for category_group in self.indicator_slugs: category_indicators = [] total_rowspan = 0 for slug in category_group['indicator_slugs']: try: indicator = DynamicIndicatorDefinition.get_current( MVP.NAMESPACE, self.domain, slug, wrap_correctly=True, use_new_db=self.use_new_db, ) if self.is_rendered_as_email: retrospective = indicator.get_monthly_retrospective(user_ids=self.user_ids) else: retrospective = indicator.get_monthly_retrospective(return_only_dates=True) if not month_headers: month_headers = self.get_month_headers(retrospective) if isinstance(indicator, CombinedCouchViewIndicatorDefinition): table = self.get_indicator_table(retrospective) indicator_rowspan = 3 else: table = self.get_indicator_row(retrospective) indicator_rowspan = 1 total_rowspan += indicator_rowspan + 1 category_indicators.append(dict( title=indicator.description, table=table, load_url="%s?indicator=%s" % (self.get_url(self.domain, render_as='partial'), indicator.slug), rowspan=indicator_rowspan )) except (AttributeError, ResourceNotFound): logging.info("Could not grab indicator %s in domain %s" % (slug, self.domain)) report_matrix.append(dict( category_title=category_group['category_title'], category_slug=category_group['category_slug'], rowspan=total_rowspan, indicators=category_indicators, )) return dict( months=month_headers, report=report_matrix, )
def get_indicator_response(self, indicator_slug): indicator = DynamicIndicatorDefinition.get_current(MVP.NAMESPACE, self.domain, indicator_slug, wrap_correctly=True) result = indicator.get_value(self.user_ids, datespan=self.datespan) print result