Exemple #1
0
def lgas_json(request):
    dbm = DatabaseManager(
                server=settings.MANGROVE_DATABASES['default']['SERVER'],
                database=settings.MANGROVE_DATABASES['default']['DATABASE'])
    lgas = [{'label': lga.aggregation_paths['_geo'][-1], \
             'path': "/".join([slugify(part) \
                               for part \
                               in lga.aggregation_paths['_geo'][-2:]])} \
            for lga in get_entities_by_type(dbm, 'LGA')]
    return HttpResponse(json.dumps(lgas), mimetype='application/json')
Exemple #2
0
def load_nigeria_regions_to_file():
    dbm = DatabaseManager(
        server=settings.MANGROVE_DATABASES['default']['SERVER'],
        database=settings.MANGROVE_DATABASES['default']['DATABASE']
        )
    country = get_entities_by_type(dbm, 'Country')[0]
    country_name = country.aggregation_paths['_geo'][-1]
    country_slug = slugify(country_name)
    country_region_thing = RegionThing(
        name=country_name,
        slug=country_slug,
        entity_id=country.id,
        server=dbm.server,
        database=dbm.database_name
    )
    states = get_entities_in(dbm, country.aggregation_paths['_geo'], 'State')
    for state in states:
        state_name = state.aggregation_paths['_geo'][-1]
        state_slug = slugify(state_name)
        state_region_thing = RegionThing(
            name=state_name,
            slug=state_slug,
            entity_id=state.id,
            server=dbm.server,
            database=dbm.database_name
        )
        lgas = get_entities_in(dbm, state.aggregation_paths['_geo'], 'LGA')
        for lga in lgas:
            lga_name = lga.aggregation_paths['_geo'][-1]
            lga_slug = slugify(lga_name)
            lga_region_thing = RegionThing(
                name=lga_name,
                slug=lga_slug,
                entity_id=lga.id,
                server=dbm.server,
                database=dbm.database_name
            )
            state_region_thing._set_subregions([lga_region_thing])
        country_region_thing._set_subregions([state_region_thing])
    dict_repr = country_region_thing.export_to_dict()
    json_val = json.dumps(dict_repr)
    f = open(NIGERIA_REGION_CACHE, 'w')
    f.write(json_val)
    f.close()
Exemple #3
0
 def _get_health_facilities(cls, dbm):
     from mangrove.datastore.entity import get_entities_by_type
     return get_entities_by_type(dbm, "Health Clinic")
Exemple #4
0
def map_entities(request):
    entity_list = get_entities_by_type(get_database_manager(request), request.GET['id'])
    location_geojson = helper.create_location_geojson(entity_list)
    return HttpResponse(location_geojson)