Пример #1
0
def area(request, area_id, format='json'):
    if hasattr(countries, 'area_code_lookup'):
        resp = countries.area_code_lookup(request, area_id, format)
        if resp: return resp


    if not re.match('\d+$', area_id):
        raise ViewException(format, 'Bad area ID specified', 400)


    area = get_object_or_404(Area, format=format, id=area_id)

    codes = []
    for code_type, code in sorted(area.all_codes.items()):
        code_link = None
        if code_type in ('osm', 'osm_rel'):
            code_link = 'http://www.openstreetmap.org/browse/relation/' + code
        elif code_type == 'osm_way':
            code_link = 'http://www.openstreetmap.org/browse/way/' + code
        codes.append((code_type, code, code_link))

    # Sort any alternative names by the description of the name (the
    # English name of the language for global MapIt) and exclude the
    # default OSM name, since if that exists, it'll already be
    # displayed as the page title.

    names = Name.objects.filter(area=area).select_related()
    alternative_names = sorted((n.type.description, n.name) for n in names
                               if n.type.code != "default")

    geotype = {}
    if hasattr(countries, 'restrict_geo_html'):
        geotype = countries.restrict_geo_html(area)

    if format == 'html':
        return render(request, 'mapit/area.html', {
            'area': area,
            'codes': codes,
            'alternative_names': alternative_names,
            'geotype': geotype,
        })
    return output_json( area.as_dict(names) )
Пример #2
0
def area(request, area_id, format=''):
    if hasattr(countries, 'area_code_lookup'):
        resp = countries.area_code_lookup(request, area_id, format)
        if resp:
            return resp

    if not re.match(r'\d+$', area_id):
        raise ViewException(format, _('Bad area ID specified'), 400)

    area = get_object_or_404(Area, format=format, id=area_id)

    codes = []
    for code_type, code in sorted(area.all_codes.items()):
        code_link = None
        if code_type in ('osm', 'osm_rel'):
            code_link = 'http://www.openstreetmap.org/browse/relation/' + code
        elif code_type == 'osm_way':
            code_link = 'http://www.openstreetmap.org/browse/way/' + code
        codes.append((code_type, code, code_link))

    # Sort any alternative names by the description of the name (the
    # English name of the language for global MapIt) and exclude the
    # default OSM name, since if that exists, it'll already be
    # displayed as the page title.

    names = Name.objects.filter(area=area).select_related()
    alternative_names = sorted((n.type.description, n.name) for n in names
                               if n.type.code != "default")

    geotype = {}
    if hasattr(countries, 'restrict_geo_html'):
        geotype = countries.restrict_geo_html(area)

    if format == 'html':
        return render(
            request, 'mapit/area.html', {
                'area': area,
                'codes': codes,
                'alternative_names': alternative_names,
                'geotype': geotype,
            })
    return output_json(area.as_dict(names))
Пример #3
0
def area(request, area_id, format="json"):
    if hasattr(countries, "area_code_lookup"):
        resp = countries.area_code_lookup(request, area_id, format)
        if resp:
            return resp

    if not re.match("\d+$", area_id):
        raise ViewException(format, "Bad area ID specified", 400)

    area = get_object_or_404(Area, format=format, id=area_id)

    codes = []
    for code_type, code in sorted(area.all_codes.items()):
        code_link = None
        if code_type in ("osm", "osm_rel"):
            code_link = "http://www.openstreetmap.org/browse/relation/" + code
        elif code_type == "osm_way":
            code_link = "http://www.openstreetmap.org/browse/way/" + code
        codes.append((code_type, code, code_link))

    # Sort any alternative names by the description of the name (the
    # English name of the language for global MapIt) and exclude the
    # default OSM name, since if that exists, it'll already be
    # displayed as the page title.

    names = Name.objects.filter(area=area).select_related()
    alternative_names = sorted((n.type.description, n.name) for n in names if n.type.code != "default")

    geotype = {}
    if hasattr(countries, "restrict_geo_html"):
        geotype = countries.restrict_geo_html(area)

    if format == "html":
        return render(
            request,
            "mapit/area.html",
            {"area": area, "codes": codes, "alternative_names": alternative_names, "geotype": geotype},
        )
    return output_json(area.as_dict(names))