def gazetteer_states(request): states = [{ "name": s.name, "id": s.state_fips, "next_entries": s.counties.count() } for s in State.objects.all().order_by("name")] return completed_request(states)
def gazetteer_countries(request): language_code = request.GET.get("language", "en") countries = [{ "name": c.name_for_language(language_code), "id": c.country_code } for c in CountryName.objects.all()] countries.sort(key=lambda c: c["name"]) return completed_request(countries)
def counties_for_state(request): state_fips = request.GET.get("id") if not state_fips: return bad_request(["MISSING: id"]) counties = [{ "name": c.name, "id": c.identifier, "next_entries": c.municipalities.count() } for c in County.objects.filter(state_fips=state_fips).order_by("name")] return completed_request(counties)
def municipalities_for_county(request): fips = request.GET.get("id") if not fips: return bad_request(["MISSING: id"]) municipalities = [{ "name": m.name, "id": "%s%s-%s" % (m.state_fips, m.county_fips, m.identifier), "next_entries": 0, } for m in Municipality.objects.filter( state_fips=fips[:2], county_fips=fips[2:]).order_by("name")] return completed_request(municipalities)