当前位置: 首页>>代码示例>>Python>>正文


Python shortcuts.output_html函数代码示例

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


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

示例1: areas_by_name

def areas_by_name(request, name, legacy=False, format='json'):
    generation = Generation.objects.current()
    try:
        min_generation = int(request.REQUEST['min_generation'])
    except:
        min_generation = generation

    type = request.REQUEST.get('type', '')

    args = {
        'name__istartswith': name,
        'generation_low__lte': generation,
        'generation_high__gte': min_generation,
    }
    if ',' in type:
        args['type__in'] = type.split(',')
    elif type:
        args['type'] = type

    areas = add_codes(Area.objects.filter(**args))
    if legacy:
        out = dict( (area.id, {
            'area_id': area.id,
            'name': area.name,
            'type': area.type,
            'parent_area_id': area.parent_area_id,
        }) for area in areas )
    else:
        out = dict( ( area.id, area.as_dict() ) for area in areas )
    if format == 'html': return output_html(request, 'Areas starting with %s' % name, areas)
    return output_json(out)
开发者ID:michaelmcandrew,项目名称:mapit,代码行数:31,代码来源:views.py

示例2: output_areas

def output_areas(request, title, format, areas, **kwargs):
    areas = add_codes(areas)
    if format == 'map.html':
        format = 'html'
        kwargs['show_map'] = True
    if format == 'html':
        return output_html(request, title, areas, **kwargs)
    return output_json(iterdict((area.id, area.as_dict()) for area in areas))
开发者ID:mysociety,项目名称:mapit,代码行数:8,代码来源:areas.py

示例3: 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

示例4: area_touches

def area_touches(request, area_id, format='json'):
    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)
    areas = Area.objects.filter(polygons__polygon__touches=all_areas, type=area.type)
    if format == 'html': return output_html( areas )
    return output_json( dict( (a.id, a.as_dict() ) for a in areas ) )
开发者ID:annapowellsmith,项目名称:mapit,代码行数:13,代码来源:views.py

示例5: 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

    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_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__in'] = type.split(',')
    elif type:
        args['type'] = type
    elif area.type in ('EUR'):
        args['type'] = area.type

    if isinstance(query_type, list):
        or_queries = [ Q(**{'polygons__polygon__%s' % t: all_areas}) for t in query_type ]
        areas = Area.objects.exclude(id=area.id).filter(**args)
        areas = areas.filter(reduce(operator.or_, or_queries))
    elif len(all_areas) == 1:
        areas = Area.objects.intersect(query_type, area)
        areas = areas.exclude(id=area.id).filter(**args)
    else:
        areas = Area.objects.exclude(id=area.id).filter(**args)
        areas = areas.filter(**{'polygons__polygon__%s' % query_type : all_areas })

    areas = areas.distinct()

    set_timeout(format)
    try:
        if format == 'html':
            return output_html(request,
                title % ('<a href="/area/%d.html">%s</a>' % (area.id, area.name)),
                areas, norobots=True
            )
        return output_json( dict( (a.id, a.as_dict() ) for a in 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)
开发者ID:michaelmcandrew,项目名称:mapit,代码行数:49,代码来源:views.py

示例6: areas_by_point

def areas_by_point(request, srid, x, y, bb=False, format="json"):
    type = request.REQUEST.get("type", "")
    generation = request.REQUEST.get("generation", Generation.objects.current())
    if not generation:
        generation = Generation.objects.current()

    location = Point(float(x), float(y), srid=int(srid))
    gdal.UseExceptions()
    try:
        location.transform(settings.MAPIT_AREA_SRID, clone=True)
    except:
        raise ViewException(format, "Point outside the area geometry", 400)

    method = "box" if bb and bb != "polygon" else "polygon"

    args = {"generation_low__lte": generation, "generation_high__gte": generation}

    if "," in type:
        args["type__code__in"] = type.split(",")
    elif type:
        args["type__code"] = type

    if type and method == "polygon":
        args = dict(("area__%s" % k, v) for k, v in args.items())
        # So this is odd. It doesn't matter if you specify types, PostGIS will
        # do the contains test on all the geometries matching the bounding-box
        # index, even if it could be much quicker to filter some out first
        # (ie. the EUR ones).
        args["polygon__bbcontains"] = location
        shapes = Geometry.objects.filter(**args).defer("polygon")
        areas = []
        for shape in shapes:
            try:
                areas.append(Area.objects.get(polygons__id=shape.id, polygons__polygon__contains=location))
            except:
                pass
    else:
        if method == "box":
            args["polygons__polygon__bbcontains"] = location
        else:
            geoms = list(Geometry.objects.filter(polygon__contains=location).defer("polygon"))
            args["polygons__in"] = geoms
        areas = Area.objects.filter(**args)

    areas = add_codes(areas)
    if format == "html":
        return output_html(request, "Areas containing (%s,%s)" % (x, y), areas, indent_areas=True)
    return output_json(dict((area.id, area.as_dict()) for area in areas))
开发者ID:Hutspace,项目名称:mapit,代码行数:48,代码来源:areas.py

示例7: areas_by_point

def areas_by_point(request, srid, x, y, bb=False, format='json'):
    type = request.REQUEST.get('type', '')
    generation = request.REQUEST.get('generation', Generation.objects.current())
    if not generation: generation = Generation.objects.current()

    location = Point(float(x), float(y), srid=int(srid))
    gdal.UseExceptions()
    try:
        location.transform(settings.MAPIT_AREA_SRID, clone=True)
    except:
        return output_error(format, 'Point outside the area geometry', 400)

    method = 'box' if bb and bb != 'polygon' else 'polygon'

    args = { 'generation_low__lte': generation, 'generation_high__gte': generation }

    if ',' in type:
        args['type__code__in'] = type.split(',')
    elif type:
        args['type__code'] = type

    if type and method == 'polygon':
        args = dict( ("area__%s" % k, v) for k, v in args.items() )
        # So this is odd. It doesn't matter if you specify types, PostGIS will
        # do the contains test on all the geometries matching the bounding-box
        # index, even if it could be much quicker to filter some out first
        # (ie. the EUR ones).
        args['polygon__bbcontains'] = location
        shapes = Geometry.objects.filter(**args).defer('polygon')
        areas = []
        for shape in shapes:
            try:
                areas.append( Area.objects.get(polygons__id=shape.id, polygons__polygon__contains=location) )
            except:
                pass
    else:
        if method == 'box':
            args['polygons__polygon__bbcontains'] = location
        else:
            geoms = list(Geometry.objects.filter(polygon__contains=location).defer('polygon'))
            args['polygons__in'] = geoms
        areas = Area.objects.filter(**args)

    if format == 'html': return output_html(request, 'Areas containing (%s,%s)' % (x,y), areas)
    return output_json( dict( (area.id, area.as_dict() ) for area in areas ) )
开发者ID:grischard,项目名称:mapit,代码行数:45,代码来源:areas.py

示例8: area_children

def area_children(request, area_id, format="json"):
    area = get_object_or_404(Area, format=format, id=area_id)

    generation = request.REQUEST.get("generation", Generation.objects.current())
    if not generation:
        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

    children = add_codes(area.children.filter(**args))

    if format == "html":
        return output_html(request, "Children of %s" % area.name, children)
    return output_json(dict((child.id, child.as_dict()) for child in children))
开发者ID:Hutspace,项目名称:mapit,代码行数:19,代码来源:areas.py

示例9: area_children

def area_children(request, area_id, format='json'):
    area = get_object_or_404(Area, format=format, id=area_id)
    if isinstance(area, HttpResponse): return area

    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

    children = add_codes(area.children.filter(**args))

    if format == 'html': return output_html(request, 'Children of %s' % area.name, children)
    return output_json( dict( (child.id, child.as_dict() ) for child in children ) )
开发者ID:grischard,项目名称:mapit,代码行数:20,代码来源:areas.py

示例10: areas_by_name

def areas_by_name(request, name, format="json"):
    generation = Generation.objects.current()
    try:
        min_generation = int(request.REQUEST["min_generation"])
    except:
        min_generation = generation

    type = request.REQUEST.get("type", "")

    args = {"name__istartswith": name, "generation_low__lte": generation, "generation_high__gte": min_generation}
    if "," in type:
        args["type__code__in"] = type.split(",")
    elif type:
        args["type__code"] = type

    areas = add_codes(Area.objects.filter(**args))
    if format == "html":
        return output_html(request, "Areas starting with %s" % name, areas)
    out = dict((area.id, area.as_dict()) for area in areas)
    return output_json(out)
开发者ID:Hutspace,项目名称:mapit,代码行数:20,代码来源:areas.py

示例11: areas_by_type

def areas_by_type(request, type, format='json'):
    generation = Generation.objects.current()
    try:
        min_generation = int(request.REQUEST['min_generation'])
    except:
        min_generation = generation

    args = {}
    if ',' in type:
        args['type__code__in'] = type.split(',')
    elif type:
        args['type__code'] = type

    if min_generation == -1:
        areas = add_codes(Area.objects.filter(**args))
    else:
        args['generation_low__lte'] = generation
        args['generation_high__gte'] = min_generation
        areas = add_codes(Area.objects.filter(**args))
    if format == 'html':
        return output_html(request, 'Areas in %s' % type, areas)
    return output_json( dict( (a.id, a.as_dict() ) for a in areas ) )
开发者ID:grischard,项目名称:mapit,代码行数:22,代码来源:areas.py

示例12: areas_by_type

def areas_by_type(request, type, format="json"):
    generation = Generation.objects.current()
    try:
        min_generation = int(request.REQUEST["min_generation"])
    except:
        min_generation = generation

    args = {}
    if "," in type:
        args["type__code__in"] = type.split(",")
    elif type:
        args["type__code"] = type

    if min_generation == -1:
        areas = add_codes(Area.objects.filter(**args))
    else:
        args["generation_low__lte"] = generation
        args["generation_high__gte"] = min_generation
        areas = add_codes(Area.objects.filter(**args))
    if format == "html":
        return output_html(request, "Areas in %s" % type, areas)
    return output_json(dict((a.id, a.as_dict()) for a in areas))
开发者ID:Hutspace,项目名称:mapit,代码行数:22,代码来源:areas.py

示例13: 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)
    areas = Area.objects.intersect(query_type, area).exclude(id=area.id).filter(**args).distinct()

    try:
        if format == 'html':
            return output_html(request,
                title % ('<a href="%sarea/%d.html">%s</a>' % (reverse('mapit_index'), area.id, area.name)),
                areas, norobots=True
            )
        return output_json( dict( (a.id, a.as_dict() ) for a in 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:grischard,项目名称:mapit,代码行数:37,代码来源:areas.py

示例14: areas

def areas(request, area_ids, format='json'):
    area_ids = area_ids.split(',')
    areas = add_codes(Area.objects.filter(id__in=area_ids))
    if format == 'html': return output_html(request, 'Areas ID lookup', areas)
    return output_json( dict( ( area.id, area.as_dict() ) for area in areas ) )
开发者ID:grischard,项目名称:mapit,代码行数:5,代码来源:areas.py

示例15: areas

def areas(request, area_ids, format="json"):
    area_ids = area_ids.split(",")
    areas = add_codes(Area.objects.filter(id__in=area_ids))
    if format == "html":
        return output_html(request, "Areas ID lookup", areas)
    return output_json(dict((area.id, area.as_dict()) for area in areas))
开发者ID:Hutspace,项目名称:mapit,代码行数:6,代码来源:areas.py


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