Example #1
0
def render_to_response(template_name,
        dictionary=None, context_instance=None, filename=None, format='odt',
        cache=CacheManager, preprocessors=None, inline=None, iterator=False,
    ):
    """
    Using same options as :func:`render_to`, return :class:`django.http.HttpResponse`
    object. The document is automatically removed after the last byte of the
    response have been read.

    :keyword iterator: is a flag which determines whether returned
                       :class:`HttpResponse` object should be initialized with
                       a string or with an iterator.

    Consider using iterator if you tend to send large documents only, otherwise
    set this flag to :const:`False`. Be aware that some middlewares can "eat"
    your iterator-based HTTP responses. See `Ticket #6527
    <https://code.djangoproject.com/ticket/6527>`_ for more details.
    """
    mimetype = get_mimetype(format)
    content_fd = render_to(format, template_name, dictionary, context_instance,
        delete_on_close=True, cache=cache, preprocessors=preprocessors
    )
    if iterator:
        content = _ifile(content_fd)
    else:
        content = content_fd.read()
    response = HttpResponse(content, mimetype=mimetype)
    if not filename:
        filename = os.path.basename(template_name)
        filename += '.%s' % format
    response['Content-Disposition'] = (
        inline and 'inline' or 'attachment; filename="%s"' % filename
    )
    return response
Example #2
0
def render_to_response(template_name,
        dictionary=None, context_instance=None, filename=None, format='odt',
        cache=CacheManager, preprocessors=None, inline=None, serve=None
    ):
    """
    Using same options as `render_to`, return `django.http.HttpResponse`
    object. The document is automatically removed when the last byte of the
    response is read.
    """
    mimetype = get_mimetype(format)
    content_fd = render_to(format, template_name, dictionary, context_instance,
        delete_on_close=True, cache=cache, preprocessors=preprocessors
    )
    if serve is None:
        serve = True
    if serve:
        content = _ifile(content_fd)
    else:
        content = content_fd.read()
    response = HttpResponse(content, mimetype=mimetype)
    if not filename:
        filename = os.path.basename(template_name)
        filename += '.%s' % format
    response['Content-Disposition'] = (
        inline and 'inline' or 'attachment; filename="%s"' % filename
    )
    return response
Example #3
0
def render_to_response(template_name,
        dictionary=None, context_instance=None, filename=None, format='odt',
        cache=CacheManager, preprocessors=None, inline=None, iterator=False,
    ):
    """
    Using same options as :func:`render_to`, return :class:`django.http.HttpResponse`
    object. The document is automatically removed after the last byte of the
    response have been read.

    :keyword iterator: is a flag which determines whether returned
                       :class:`HttpResponse` object should be initialized with
                       a string or with an iterator.

    Consider using iterator if you tend to send large documents only, otherwise
    set this flag to :const:`False`. Be aware that some middlewares can "eat"
    your iterator-based HTTP responses. See `Ticket #6527
    <https://code.djangoproject.com/ticket/6527>`_ for more details.
    """
    mimetype = get_mimetype(format)
    content_fd = render_to(format, template_name, dictionary, context_instance,
        delete_on_close=True, cache=cache, preprocessors=preprocessors
    )
    if iterator:
        content = _ifile(content_fd)
    else:
        content = content_fd.read()
    response = HttpResponse(content, content_type=mimetype)
    if not filename:
        filename = os.path.basename(template_name)
        filename += '.%s' % format
    response['Content-Disposition'] = (
        inline and 'inline' or 'attachment; filename="%s"' % filename
    )
    return response
Example #4
0
def render_to_response(template_name,
                       dictionary=None,
                       context_instance=None,
                       filename=None,
                       format='odt',
                       cache=CacheManager,
                       preprocessors=None,
                       inline=None):
    """
    Using same options as `render_to`, return `django.http.HttpResponse`
    object. The document is automatically removed when the last byte of the
    response is read.
    """
    mimetype = get_mimetype(format)
    content_fd = render_to(format,
                           template_name,
                           dictionary,
                           context_instance,
                           delete_on_close=True,
                           cache=cache,
                           preprocessors=preprocessors)
    response = HttpResponse(_ifile(content_fd), mimetype=mimetype)
    if not filename:
        filename = os.path.basename(template_name)
        filename += '.%s' % format
    response['Content-Disposition'] = (inline and 'inline' or
                                       'attachment; filename="%s"' % filename)
    return response
Example #5
0
def render_to_response(template_name,
        dictionary=None, context_instance=None, filename=None, format='odt', cache=CacheManager):
    """
    Using same options as `render_to`, return `django.http.HttpResponse`
    object. The document is automatically removed when the last byte of the
    response is read.
    """
    mimetype = get_mimetype(format)
    content_fd = render_to(format, template_name, dictionary, context_instance,
                           delete_on_close=True, cache=cache)
    response = HttpResponse(_ifile(content_fd), mimetype=mimetype)
    if not filename:
        filename = os.path.basename(template_name)
        filename += '.%s' % format
    response['Content-Disposition'] = 'attachment; filename="%s"' % filename
    return response