• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python shortcuts.get_object_or_404函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中mapit.shortcuts.get_object_or_404函数的典型用法代码示例。如果您正苦于以下问题:Python get_object_or_404函数的具体用法?Python get_object_or_404怎么用?Python get_object_or_404使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get_object_or_404函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: _get_voting_area_info

def _get_voting_area_info(area_id):
    if re.match('\d\d([a-z][a-z])?([a-z][a-z])?$(?i)', area_id):
        area = get_object_or_404(Area, codes__type='ons', codes__code=area_id)
    else:
        area = get_object_or_404(Area, id=int(area_id))
    if isinstance(area, HttpResponse): return area

    try:
        os_name = area.names.get(type='O').name
    except:
        os_name = None
    try:
        ons_code = area.codes.get(type='ons').code
    except:
        ons_code = None

    current = Generation.objects.current().id
    out = {
        'area_id': area.id,
        'name': area.name,
        'os_name': os_name,
        'country': area.country,
        'parent_area_id': area.parent_area_id,
        'type': area.type,
        'ons_code': ons_code,
        'generation_low': area.generation_low_id if area.generation_low_id else 0,
        'generation_high': area.generation_high_id if area.generation_high_id else current,
        'generation': current,
    }

    for item in ('type_name', 'attend_prep', 'general_prep', 'rep_name', 'rep_name_plural',
                 'rep_name_long', 'rep_name_long_plural', 'rep_suffix', 'rep_prefix'):
        out[item] = voting_area[item].get(area.type)

    return out
开发者ID:michaelmcandrew,项目名称:mapit,代码行数:35,代码来源:views.py


示例2: area

def area(request, area_id, legacy=False):
    if re.match('\d\d([A-Z]{2}|[A-Z]{4}|[A-Z]{2}\d\d\d|[A-Z]|[A-Z]\d\d)$', area_id):
        area = get_object_or_404(Area, codes__type='ons', codes__code=area_id)
    elif not re.match('\d+$', area_id):
        return output_json({ 'error': 'Bad area ID specified' }, code=400)
    else:
        area = get_object_or_404(Area, id=area_id)
    if isinstance(area, HttpResponse): return area
    return output_json( area.as_dict() )
开发者ID:annapowellsmith,项目名称:mapit,代码行数:9,代码来源:views.py


示例3: area_intersect

def area_intersect(query_type, title, request, area_id, format):
    area = get_object_or_404(Area, format=format, id=area_id)
    if not area.polygons.count():
        raise ViewException(format, 'No polygons found', 404)

    generation = Generation.objects.current()
    types = [_f for _f in request.REQUEST.get('type', '').split(',') if _f]

    set_timeout(format)
    try:
        # Cast to list so that it's evaluated here, and output_areas doesn't get
        # confused with a RawQuerySet
        areas = list(Area.objects.intersect(query_type, area, types, generation))
    except QueryCanceledError:
        raise ViewException(
            format, 'That query was taking too long to compute - '
            'try restricting to a specific type, if you weren\'t already doing so.', 500)
    except DatabaseError as e:
        # Django 1.2+ catches QueryCanceledError and throws its own DatabaseError instead
        if 'canceling statement due to statement timeout' not in e.args[0]:
            raise
        raise ViewException(
            format, 'That query was taking too long to compute - '
            'try restricting to a specific type, if you weren\'t already doing so.', 500)
    except InternalError:
        raise ViewException(format, 'There was an internal error performing that query.', 500)

    title = title % ('<a href="%sarea/%d.html">%s</a>' % (reverse('mapit_index'), area.id, area.name))
    return output_areas(request, title, format, areas, norobots=True)
开发者ID:dracos,项目名称:mapit,代码行数:29,代码来源:areas.py


示例4: area_polygon

def area_polygon(request, srid="", area_id="", format="kml"):
    if not srid and 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)

    if not srid:
        srid = 4326 if format in ("kml", "json", "geojson") else settings.MAPIT_AREA_SRID
    srid = int(srid)

    area = get_object_or_404(Area, id=area_id)

    try:
        simplify_tolerance = float(request.GET.get("simplify_tolerance", 0))
    except ValueError:
        raise ViewException(format, "Badly specified tolerance", 400)

    try:
        output, content_type = area.export(srid, format, simplify_tolerance=simplify_tolerance)
        if output is None:
            return output_json({"error": "No polygons found"}, code=404)
    except SimplifiedAway:
        return output_json({"error": "Simplifying removed all the polygons"}, code=404)

    return HttpResponse(output, content_type="%s; charset=utf-8" % content_type)
开发者ID:Hutspace,项目名称:mapit,代码行数:28,代码来源:areas.py


示例5: _area_geometry

def _area_geometry(area_id):
    area = get_object_or_404(Area, id=area_id)
    all_areas = area.polygons.all().collect()
    if not all_areas:
        return output_json({"error": "No polygons found"}, code=404)
    out = {"parts": all_areas.num_geom}
    if settings.MAPIT_AREA_SRID != 4326:
        out["srid_en"] = settings.MAPIT_AREA_SRID
        out["area"] = all_areas.area
        out["min_e"], out["min_n"], out["max_e"], out["max_n"] = all_areas.extent
        out["centre_e"], out["centre_n"] = all_areas.centroid
        all_areas.transform(4326)
        out["min_lon"], out["min_lat"], out["max_lon"], out["max_lat"] = all_areas.extent
        out["centre_lon"], out["centre_lat"] = all_areas.centroid
    else:
        out["min_lon"], out["min_lat"], out["max_lon"], out["max_lat"] = all_areas.extent
        out["centre_lon"], out["centre_lat"] = all_areas.centroid
        if hasattr(countries, "area_geometry_srid"):
            srid = countries.area_geometry_srid
            all_areas.transform(srid)
            out["srid_en"] = srid
            out["area"] = all_areas.area
            out["min_e"], out["min_n"], out["max_e"], out["max_n"] = all_areas.extent
            out["centre_e"], out["centre_n"] = all_areas.centroid
    return out
开发者ID:Hutspace,项目名称:mapit,代码行数:25,代码来源:areas.py


示例6: area_code_lookup

def area_code_lookup(request, area_id, format):
    from mapit.models import Area, CodeType
    area_code = None
    if re.match('\d\d([A-Z]{2}|[A-Z]{4}|[A-Z]{2}\d\d\d|[A-Z]|[A-Z]\d\d)$', area_id):
        area_code = CodeType.objects.get(code='ons')
    elif re.match('[EW]0[12]\d{6}$', area_id): # LSOA/MSOA have ONS code type
        area_code = CodeType.objects.get(code='ons')
    elif re.match('[ENSW]\d{8}$', area_id):
        area_code = CodeType.objects.get(code='gss')
    if not area_code:
        return None

    args = { 'format': format, 'codes__type': area_code, 'codes__code': area_id }
    if re.match('[EW]01', area_id):
        args['type__code'] = 'OLF'
    elif re.match('[EW]02', area_id):
        args['type__code'] = 'OMF'

    area = get_object_or_404(Area, **args)
    path = '/area/%d%s' % (area.id, '.%s' % format if format else '')
    # If there was a query string, make sure it's passed on in the
    # redirect:
    if request.META['QUERY_STRING']:
        path += "?" + request.META['QUERY_STRING']
    return HttpResponseRedirect(path)
开发者ID:Arenhardt,项目名称:mapit,代码行数:25,代码来源:gb.py


示例7: area_children

def area_children(request, area_id, format='json'):
    q = query_args(request, format)
    area = get_object_or_404(Area, format=format, id=area_id)
    children = area.children.filter(q).distinct()
    if format in ('kml', 'geojson'):
        return _areas_polygon(request, format, children)
    return output_areas(request, _('Children of %s') % area.name, format, children)
开发者ID:mysociety,项目名称:mapit,代码行数:7,代码来源:areas.py


示例8: area_polygon

def area_polygon(request, srid='', area_id='', format='kml'):
    if not srid and 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)

    if not srid:
        srid = 4326 if format in ('kml', 'json', 'geojson') else settings.MAPIT_AREA_SRID
    srid = int(srid)

    area = get_object_or_404(Area, id=area_id)

    try:
        simplify_tolerance = float(request.GET.get('simplify_tolerance', 0))
    except ValueError:
        raise ViewException(format, 'Badly specified tolerance', 400)

    try:
        output, content_type = area.export(srid, format, simplify_tolerance=simplify_tolerance)
        if output is None:
            return output_json({'error': 'No polygons found'}, code=404)
    except SimplifiedAway:
        return output_json({'error': 'Simplifying removed all the polygons'}, code=404)

    return HttpResponse(output, content_type='%s; charset=utf-8' % content_type)
开发者ID:AltisCorp,项目名称:mapit,代码行数:27,代码来源:areas.py


示例9: area_polygon

def area_polygon(request, srid='', area_id='', format='kml'):
    if not srid:
        srid = 4326 if format in ('kml', 'json', 'geojson') else int(mysociety.config.get('AREA_SRID'))
    srid = int(srid)
    area = get_object_or_404(Area, id=area_id)
    if isinstance(area, HttpResponse): return area
    all_areas = area.polygons.all()
    if len(all_areas) > 1:
        all_areas = all_areas.collect()
    elif len(all_areas) == 1:
        all_areas = all_areas[0].polygon
    else:
        return output_json({ 'error': 'No polygons found' }, code=404)
    if srid != int(mysociety.config.get('AREA_SRID')):
        all_areas.transform(srid)
    if format=='kml':
        out = '''<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
    <Placemark>
        <name>%s</name>
        %s
    </Placemark>
</kml>''' % (area.name, all_areas.kml)
        content_type = 'application/vnd.google-earth.kml+xml'
    elif format in ('json', 'geojson'):
        out = all_areas.json
        content_type = 'application/json'
    elif format=='wkt':
        out = all_areas.wkt
        content_type = 'text/plain'
    return HttpResponse(out, content_type='%s; charset=utf-8' % content_type)
开发者ID:michaelmcandrew,项目名称:mapit,代码行数:31,代码来源:views.py


示例10: _area_geometry

def _area_geometry(area_id):
    area = get_object_or_404(Area, id=area_id)
    if isinstance(area, HttpResponse): return area
    all_areas = area.polygons.all().collect()
    if not all_areas:
        return output_json({ 'error': 'No polygons found' }, code=404)
    out = {
        'parts': all_areas.num_geom,
    }
    if settings.MAPIT_AREA_SRID != 4326:
        out['srid_en'] = settings.MAPIT_AREA_SRID
        out['area'] = all_areas.area
        out['min_e'], out['min_n'], out['max_e'], out['max_n'] = all_areas.extent
        out['centre_e'], out['centre_n'] = all_areas.centroid
        all_areas.transform(4326)
        out['min_lon'], out['min_lat'], out['max_lon'], out['max_lat'] = all_areas.extent
        out['centre_lon'], out['centre_lat'] = all_areas.centroid
    else:
        out['min_lon'], out['min_lat'], out['max_lon'], out['max_lat'] = all_areas.extent
        out['centre_lon'], out['centre_lat'] = all_areas.centroid
        if hasattr(countries, 'area_geometry_srid'):
            srid = countries.area_geometry_srid
            all_areas.transform(srid)
            out['srid_en'] = srid
            out['area'] = all_areas.area
            out['min_e'], out['min_n'], out['max_e'], out['max_n'] = all_areas.extent
            out['centre_e'], out['centre_n'] = all_areas.centroid
    return out
开发者ID:grischard,项目名称:mapit,代码行数:28,代码来源:areas.py


示例11: area_polygon

def area_polygon(request, srid='', area_id='', format='kml'):
    if not srid and 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)

    if not srid:
        srid = 4326 if format in ('kml', 'json', 'geojson') else settings.MAPIT_AREA_SRID
    srid = int(srid)

    area = get_object_or_404(Area, id=area_id)

    try:
        simplify_tolerance = float(request.GET.get('simplify_tolerance', 0))
    except ValueError:
        raise ViewException(format, 'Badly specified tolerance', 400)

    try:
        output, content_type = area.export(srid, format, simplify_tolerance=simplify_tolerance)
        if output is None:
            return output_json({'error': 'No polygons found'}, code=404)
    except TransformError as e:
        return output_json({'error': e.args[0]}, code=400)

    response = HttpResponse(content_type='%s; charset=utf-8' % content_type)
    response['Access-Control-Allow-Origin'] = '*'
    response['Cache-Control'] = 'max-age=2419200'  # 4 weeks
    response.write(output)
    return response
开发者ID:Code4SA,项目名称:mapit,代码行数:32,代码来源:areas.py


示例12: area_intersect

def area_intersect(query_type, title, request, area_id, format):
    area = get_object_or_404(Area, format=format, id=area_id)
    if not area.polygons.count():
        raise ViewException(format, "No polygons found", 404)

    generation = Generation.objects.current()
    types = filter(None, request.REQUEST.get("type", "").split(","))

    set_timeout(format)
    try:
        # Cast to list so that it's evaluated here, and add_codes doesn't get
        # confused with a RawQuerySet
        areas = list(Area.objects.intersect(query_type, area, types, generation))
        areas = add_codes(areas)
    except QueryCanceledError:
        raise ViewException(
            format,
            "That query was taking too long to compute - try restricting to a specific type, if you weren't already doing so.",
            500,
        )
    except DatabaseError, e:
        # Django 1.2+ catches QueryCanceledError and throws its own DatabaseError instead
        if "canceling statement due to statement timeout" not in e.args[0]:
            raise
        raise ViewException(
            format,
            "That query was taking too long to compute - try restricting to a specific type, if you weren't already doing so.",
            500,
        )
开发者ID:Hutspace,项目名称:mapit,代码行数:29,代码来源:areas.py


示例13: area_code_lookup

def area_code_lookup(request, area_code, format):
    from mapit.models import Area, CodeType
    area_code_type = None
    if re.match(r'\d\d([A-Z]{2}|[A-Z]{4}|[A-Z]{2}\d\d\d|[A-Z]|[A-Z]\d\d)$', area_code):
        area_code_type = CodeType.objects.get(code='ons')
    elif re.match(r'[EW]0[12]\d{6}$', area_code):  # LSOA/MSOA have ONS code type
        area_code_type = CodeType.objects.get(code='ons')
    elif re.match(r'[ENSW]\d{8}$', area_code):
        area_code_type = CodeType.objects.get(code='gss')
    if not area_code_type:
        return None

    args = {'format': format, 'codes__type': area_code_type, 'codes__code': area_code}
    if re.match('[EW]01', area_code):
        args['type__code'] = 'OLF'
    elif re.match('[EW]02', area_code):
        args['type__code'] = 'OMF'

    area = get_object_or_404(Area, **args)
    area_kwargs = {'area_id': area.id}
    if format:
        area_kwargs['format'] = format
    # We're called either by area or area_polygon
    try:
        redirect_path = reverse('area', kwargs=area_kwargs)
    except NoReverseMatch:
        redirect_path = reverse('area_polygon', kwargs=area_kwargs)
    # If there was a query string, make sure it's passed on in the
    # redirect:
    if request.META['QUERY_STRING']:
        redirect_path += "?" + request.META['QUERY_STRING']
    return HttpResponseRedirect(redirect_path)
开发者ID:mysociety,项目名称:mapit,代码行数:32,代码来源:countries.py


示例14: area_intersect

def area_intersect(query_type, title, request, area_id, format):
    area = get_object_or_404(Area, format=format, id=area_id)
    if isinstance(area, HttpResponse): return area

    if not area.polygons.count():
        return output_error(format, 'No polygons found', 404)

    generation = Generation.objects.current()
    args = {
        'generation_low__lte': generation,
        'generation_high__gte': generation,
    }

    type = request.REQUEST.get('type', '')
    if ',' in type:
        args['type__code__in'] = type.split(',')
    elif type:
        args['type__code'] = type
    elif area.type.code in ('EUR'):
        args['type__code'] = area.type.code

    set_timeout(format)
    try:
        areas = list(Area.objects.intersect(query_type, area).filter(**args).distinct())
        areas = add_codes(areas)
    except QueryCanceledError:
        return output_error(format, 'That query was taking too long to compute - try restricting to a specific type, if you weren\'t already doing so.', 500)
    except DatabaseError, e:
        # Django 1.2+ catches QueryCanceledError and throws its own DatabaseError instead
        if 'canceling statement due to statement timeout' not in e.args[0]: raise
        return output_error(format, 'That query was taking too long to compute - try restricting to a specific type, if you weren\'t already doing so.', 500)
开发者ID:nvkelso,项目名称:mapit,代码行数:31,代码来源:areas.py


示例15: _area_geometry

def _area_geometry(area_id):
    area = get_object_or_404(Area, id=area_id)
    if isinstance(area, HttpResponse): return area
    all_areas = area.polygons.all().collect()
    if not all_areas:
        return output_json({ 'error': 'No polygons found' }, code=404)
    out = {
        'parts': all_areas.num_geom,
    }
    if int(mysociety.config.get('AREA_SRID')) != 4326:
        out['srid_en'] = mysociety.config.get('AREA_SRID')
        out['area'] = all_areas.area
        out['min_e'], out['min_n'], out['max_e'], out['max_n'] = all_areas.extent
        out['centre_e'], out['centre_n'] = all_areas.centroid
        all_areas.transform(4326)
        out['min_lon'], out['min_lat'], out['max_lon'], out['max_lat'] = all_areas.extent
        out['centre_lon'], out['centre_lat'] = all_areas.centroid
    elif mysociety.config.get('COUNTRY') == 'NO':
        out['min_lon'], out['min_lat'], out['max_lon'], out['max_lat'] = all_areas.extent
        out['centre_lon'], out['centre_lat'] = all_areas.centroid
        all_areas.transform(32633)
        out['srid_en'] = 32633
        out['area'] = all_areas.area
        out['min_e'], out['min_n'], out['max_e'], out['max_n'] = all_areas.extent
        out['centre_e'], out['centre_n'] = all_areas.centroid
    return out
开发者ID:michaelmcandrew,项目名称:mapit,代码行数:26,代码来源:views.py


示例16: area

def area(request, area_id, format='json'):
    if re.match('\d\d([A-Z]{2}|[A-Z]{4}|[A-Z]{2}\d\d\d|[A-Z]|[A-Z]\d\d)$', area_id):
        area = get_object_or_404(Area, format=format, codes__type='ons', codes__code=area_id)
    elif re.match('[ENSW]\d{8}$', area_id):
        area = get_object_or_404(Area, format=format, codes__type='gss', codes__code=area_id)
    elif not re.match('\d+$', area_id):
        return output_error(format, 'Bad area ID specified', 400)
    else:
        area = get_object_or_404(Area, format=format, id=area_id)
    if isinstance(area, HttpResponse): return area
    if format == 'html':
        return render(request, 'area.html', {
            'area': area,
            'show_geometry': (area.type not in ('EUR', 'SPE', 'WAE'))
        })
    return output_json( area.as_dict() )
开发者ID:michaelmcandrew,项目名称:mapit,代码行数:16,代码来源:views.py


示例17: area_polygon

def area_polygon(request, srid='', area_id='', format='kml'):
    if not srid and hasattr(countries, 'area_code_lookup'):
        resp = countries.area_code_lookup(area_id, format)
        if resp: return resp

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

    if not srid:
        srid = 4326 if format in ('kml', 'json', 'geojson') else settings.MAPIT_AREA_SRID
    srid = int(srid)

    area = get_object_or_404(Area, id=area_id)
    if isinstance(area, HttpResponse): return area
    all_areas = area.polygons.all()
    if len(all_areas) > 1:
        all_areas = all_areas.collect()
    elif len(all_areas) == 1:
        all_areas = all_areas[0].polygon
    else:
        return output_json({ 'error': 'No polygons found' }, code=404)
    if srid != settings.MAPIT_AREA_SRID:
        all_areas.transform(srid)

    try:
        simplify_tolerance = float(request.GET.get('simplify_tolerance', 0))
    except:
        return output_error(format, 'Badly specified tolerance', 400)
    if simplify_tolerance:
        all_areas = all_areas.simplify(simplify_tolerance)

    if format=='kml':
        out = '''<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
    <Style id="transBluePoly">
        <LineStyle>
            <color>70ff0000</color>
            <width>2</width>
        </LineStyle>
        <PolyStyle>
            <color>3dff5500</color>
        </PolyStyle>
    </Style>
    <Placemark>
        <styleUrl>#transBluePoly</styleUrl>
        <name>%s</name>
        %s
    </Placemark>
</kml>''' % (escape(area.name), all_areas.kml)
        content_type = 'application/vnd.google-earth.kml+xml'
    elif format in ('json', 'geojson'):
        out = all_areas.json
        content_type = 'application/json'
    elif format=='wkt':
        out = all_areas.wkt
        content_type = 'text/plain'
    return HttpResponse(out, content_type='%s; charset=utf-8' % content_type)
开发者ID:nvkelso,项目名称:mapit,代码行数:57,代码来源:areas.py


示例18: area_children

def area_children(request, area_id, legacy=False, format='json'):
    area = get_object_or_404(Area, id=area_id)
    if isinstance(area, HttpResponse): return area
    generation = Generation.objects.current()
    children = add_codes(area.children.filter(
        generation_low__lte=generation, generation_high__gte=generation
    ))
    if legacy: return output_json( [ child.id for child in children ] )
    if format == 'html': return output_html( children )
    return output_json( dict( (child.id, child.as_dict() ) for child in children ) )
开发者ID:annapowellsmith,项目名称:mapit,代码行数:10,代码来源:views.py


示例19: postcode

def postcode(request, postcode, format=None):
    if hasattr(countries, 'canonical_postcode'):
        canon_postcode = countries.canonical_postcode(postcode)
        postcode = canon_postcode
        # if (postcode != canon_postcode and format is None) or format == 'json':
        #     return redirect('mapit.views.postcodes.postcode', postcode=canon_postcode)
    if format is None:
        format = 'json'
    if not is_valid_postcode(postcode):
        raise ViewException(format, "Postcode '%s' is not valid." % postcode, 400)
    postcode = get_object_or_404(Postcode, format=format, postcode=postcode)
    try:
        generation = int(request.GET['generation'])
    except:
        generation = Generation.objects.current()
    if not hasattr(countries, 'is_special_postcode') or not countries.is_special_postcode(postcode.postcode):
        areas = list(add_codes(Area.objects.by_postcode(postcode, generation)))
    else:
        areas = []

    # Shortcuts
    shortcuts = {}
    for area in areas:
        if area.type.code in ('COP', 'LBW', 'LGE', 'MTW', 'UTE', 'UTW'):
            shortcuts['ward'] = area.id
            shortcuts['council'] = area.parent_area_id
        elif area.type.code == 'CED':
            shortcuts.setdefault('ward', {})['county'] = area.id
            shortcuts.setdefault('council', {})['county'] = area.parent_area_id
        elif area.type.code == 'DIW':
            shortcuts.setdefault('ward', {})['district'] = area.id
            shortcuts.setdefault('council', {})['district'] = area.parent_area_id
        elif area.type.code in ('WMC',):
            # XXX Also maybe 'EUR', 'NIE', 'SPC', 'SPE', 'WAC', 'WAE', 'OLF', 'OLG', 'OMF', 'OMG'):
            shortcuts[area.type.code] = area.id

    # Add manual enclosing areas.
    extra = []
    for area in areas:
        if area.type.code in enclosing_areas.keys():
            extra.extend(enclosing_areas[area.type.code])
    areas = itertools.chain(areas, Area.objects.filter(id__in=extra))

    if format == 'html':
        return render(request, 'mapit/postcode.html', {
            'postcode': postcode.as_dict(),
            'areas': areas,
            'json_view': 'mapit-postcode',
        })

    out = postcode.as_dict()
    out['areas'] = dict((area.id, area.as_dict()) for area in areas)
    if shortcuts:
        out['shortcuts'] = shortcuts
    return output_json(out)
开发者ID:mysociety,项目名称:mapit,代码行数:55,代码来源:postcodes.py


示例20: area_code_lookup

def area_code_lookup(area_id, format):
    from mapit.models import Area, CodeType
    area_code = None
    if re.match('\d\d([A-Z]{2}|[A-Z]{4}|[A-Z]{2}\d\d\d|[A-Z]|[A-Z]\d\d)$', area_id):
        area_code = CodeType.objects.get(code='ons')
    if re.match('[ENSW]\d{8}$', area_id):
        area_code = CodeType.objects.get(code='gss')
    if not area_code:
        return None
    area = get_object_or_404(Area, format=format, codes__type=area_code, codes__code=area_id)
    return HttpResponseRedirect('/area/%d%s' % (area.id, '.%s' % format if format else ''))
开发者ID:MorusAB,项目名称:mapit,代码行数:11,代码来源:gb.py



注:本文中的mapit.shortcuts.get_object_or_404函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python shortcuts.output_html函数代码示例发布时间:2022-05-27
下一篇:
Python models.Area类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap