def indicator_by_group(request, scorecard_id, data_series_group_name, identifier, output_format='html'): scorecard = get_object_or_404(models.Scorecard, pk = scorecard_id) dataseries_group = DataSeriesGroup.objects.get(name=data_series_group_name) if 'government' in scorecard.name.lower(): entity_type = models.EntityType.objects.get(name='government') else: entity_type = models.EntityType.objects.get(name='agency') rs = models.get_responsesets(scorecard, aggregate_on=dataseries_group, limit_to_entitytype=[entity_type], compare_series=[ds for ds in DataSeriesGroup.objects.get(name='Data collection year').get_dataseries() if ds.visible]) operation = scorecard.operation_set.get(identifier=identifier) output = OrderedDict() for country, data in rs.items(): output[country] = [(ds, operation.get_data(responses)) for ds, responses in data] context = { 'scorecard':scorecard, 'project':scorecard.project, 'operation':operation, 'dataseries_group':dataseries_group, 'data':output, } if output_format == 'html': return render_to_response('ihp_results/reports/indicator_country.html',context,RequestContext(request)) else: return render_json(context)
def entity_report(request, agency_id, output_format='html'): entity = get_object_or_404(models.Entity, pk = agency_id) scorecard = models.Scorecard.objects.filter(name__contains='2012').get(name__icontains=entity.entity_type.name) rs = models.get_responsesets(scorecard, limit_to_entity=[entity], aggregate_by_entity=True, compare_series=DataSeriesGroup.objects.get(name='Data collection year').dataseries_set.filter(visible=True)) output = scorecard.get_values(rs[entity]) context = { 'entity':entity, 'scorecard':scorecard, 'project':scorecard.project, 'data':output, } if output_format=='html': return render_to_response('ihp_results/reports/entity.html',context,RequestContext(request)) else: return render_json(context)