示例#1
0
def output_html(request, title, areas, **kwargs):
    kwargs['json_url'] = request.get_full_path().replace('.html', '')
    kwargs['title'] = title
    tpl = render_to_string('mapit/data.html', kwargs, request=request)
    wraps = tpl.split('!!!DATA!!!')

    indent_areas = kwargs.get('indent_areas', False)
    item_tpl = loader.get_template('mapit/areas_item.html')
    areas = map(
        lambda area: item_tpl.render(
            Context({
                'area': area,
                'indent_areas': indent_areas
            })), areas)
    areas = defaultiter(areas,
                        '<li>' + _('No matching areas found.') + '</li>')
    content = itertools.chain(wraps[0:1], areas, wraps[1:])
    content = map(smart_str, content)  # Workaround Django bug #24240

    if django.get_version() >= '1.5':
        response_type = http.StreamingHttpResponse
    else:
        response_type = http.HttpResponse
        # Django 1.4 middleware messes up iterable content
        content = list(content)

    return response_type(content)
示例#2
0
def output_html(request, title, areas, **kwargs):
    kwargs['json_url'] = request.get_full_path().replace('.html', '')
    kwargs['title'] = title
    tpl = loader.render_to_string('mapit/data.html', kwargs, request=request)
    wraps = tpl.split('!!!DATA!!!')

    indent_areas = kwargs.get('indent_areas', False)
    item_tpl = loader.get_template('mapit/areas_item.html')
    areas = map(lambda area: item_tpl.render({'area': area, 'indent_areas': indent_areas}), areas)
    areas = defaultiter(areas, '<li>' + _('No matching areas found.') + '</li>')
    content = itertools.chain(wraps[0:1], areas, wraps[1:])

    return http.StreamingHttpResponse(content)
示例#3
0
def output_html(request, title, areas, **kwargs):
    kwargs['json_url'] = re.sub(r'(\.map)?\.html', '', request.get_full_path())
    kwargs['title'] = title
    tpl = loader.render_to_string('mapit/data.html', kwargs, request=request)
    wraps = tpl.split('!!!DATA!!!')

    indent_areas = kwargs.get('indent_areas', False)
    show_map = kwargs.get('show_map', False)
    item_tpl = loader.get_template('mapit/areas_item.html')
    areas = map(lambda area: item_tpl.render({
        'area': area, 'indent_areas': indent_areas, 'show_map': show_map,
    }), areas)
    areas = defaultiter(areas, '<li>' + _('No matching areas found.') + '</li>')
    content = itertools.chain(wraps[0:1], areas, wraps[1:])

    return http.StreamingHttpResponse(content)
示例#4
0
def output_html(request, title, areas, **kwargs):
    kwargs['json_url'] = request.get_full_path().replace('.html', '')
    kwargs['title'] = title
    tpl = render_to_string('mapit/data.html', kwargs, request=request)
    wraps = tpl.split('!!!DATA!!!')

    indent_areas = kwargs.get('indent_areas', False)
    item_tpl = loader.get_template('mapit/areas_item.html')
    areas = map(lambda area: item_tpl.render(Context({'area': area, 'indent_areas': indent_areas})), areas)
    areas = defaultiter(areas, '<li>' + _('No matching areas found.') + '</li>')
    content = itertools.chain(wraps[0:1], areas, wraps[1:])
    content = map(smart_bytes, content)  # Workaround Django bug #24240

    if django.get_version() >= '1.5':
        response_type = http.StreamingHttpResponse
    else:
        response_type = http.HttpResponse
        # Django 1.4 middleware messes up iterable content
        content = list(content)

    return response_type(content)