def get_entity_children(request, parent_uuid=None): """ generic view to build json results of entities children list """ return HttpResponse(json.dumps( [Entity.get_or_none(e.uuid).to_dict() for e in Entity.get_or_none(parent_uuid).get_children()]), content_type='application/json')
def get_entity_children(request, parent_uuid=None): """ generic view to build json results of entities children list """ return HttpResponse(json.dumps([ Entity.get_or_none(e.uuid).to_dict() for e in Entity.get_or_none(parent_uuid).get_children() ]), content_type='application/json')
def children_geojson(request, parent_uuid): parent = Entity.get_or_none(parent_uuid) if parent is None: data = None else: data = parent.children_geojson return JsonResponse(data, safe=False)
def single_geojson(request, entity_uuid): entity = Entity.get_or_none(entity_uuid) if entity is None: data = None else: data = entity.geojson return JsonResponse(data, safe=False)
def get_entity_detail(request, entity_uuid=None): entity = Entity.get_or_none(entity_uuid) if entity is None: data = None else: data = entity.to_dict() return JsonResponse(data, safe=False)
def json_data_record_for(request, period_str, entity_uuid, indicator_slug): entity = Entity.get_or_none(entity_uuid) if entity is None: raise Http404(_("Unknown entity UUID `{u}`").format(u=entity_uuid)) period = process_period_filter(request, period_str, 'period').get('period') if period is None: raise Http404(_("Unknown period `{p}`").format(p=period_str)) indicator = Indicator.get_or_none(indicator_slug) if indicator is None: raise Http404(_("Unknown indicator `{s}`").format(s=indicator_slug)) return JsonResponse(DataRecord.get_for(period, entity, indicator), safe=False)
def upload_guide_download(request, uuid, *args, **kwargs): dps = Entity.get_or_none(uuid) if dps is None: return Http404(_("No Entity to match `{uuid}`").format(uuid=uuid)) file_name = dataentry_fname_for(dps) file_content = generate_dataentry_for(dps).getvalue() response = HttpResponse(file_content, content_type='application/' 'vnd.openxmlformats-officedocument' '.spreadsheetml.sheet') response['Content-Disposition'] = 'attachment; filename="%s"' % file_name response['Content-Length'] = len(file_content) return response
def process_entity_filter(request, entity_uuid=None): root = Entity.objects.get(level=0) entity = Entity.get_or_none(entity_uuid) if entity_uuid else root if entity is None: raise Http404(request, _("Unable to match entity `{uuid}`") .format(uuid=entity_uuid)) return { 'blank_uuid': "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 'root': root, 'entity': entity, 'lineage_data': lineage_data_for(entity), 'lineage': Entity.lineage, 'children': root.get_children(), }