Exemple #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)
Exemple #2
0
    def process_exception(self, request, exception):
        if not isinstance(exception, ViewException):
            return None

        format, message, code = exception.args
        if format == 'html':
            types = {
                400: http.HttpResponseBadRequest,
                404: http.HttpResponseNotFound,
                500: http.HttpResponseServerError,
            }
            response_type = types.get(code, http.HttpResponse)
            return response_type(render_to_string(
                'mapit/%s.html' % code,
                {'error': message},
                request=request
            ))
        return output_json({'error': message}, code=code)
Exemple #3
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)