Jump to >

reviewboard.diffviewer.renderers

class DiffRenderer(diff_file, chunk_index=None, highlighting=False, collapse_all=True, lines_of_context=None, extra_context=None, allow_caching=True, template_name=u'diffviewer/diff_file_fragment.html', show_deleted=False)[source]

Bases: object

Renders a file’s diffs.

A DiffRenderer is constructed as needed and set up for render, and then thrown away. The rendered diff can show that of a whole file (in a collapsed or fully expanded state), or a particular chunk within a file.

The rendered diff will be optimistically pulled out of cache, if it exists. Otherwise, a new one will be rendered and placed in the cache.

The diff_file (from get_diff_files) is the only required parameter. The renderer may modify the contents of this, and should make a copy if it needs to be left untouched.

Note that any of the render functions are meant to be called only once per DiffRenderer. It will alter the state of the renderer, possibly disrupting future render calls.

default_template_name = u'diffviewer/diff_file_fragment.html'[source]
__init__(diff_file, chunk_index=None, highlighting=False, collapse_all=True, lines_of_context=None, extra_context=None, allow_caching=True, template_name=u'diffviewer/diff_file_fragment.html', show_deleted=False)[source]

x.__init__(…) initializes x; see help(type(x)) for signature

render_to_response(request)[source]

Renders the diff to an HttpResponse.

render_to_string(request)[source]

Returns the diff as a string.

The resulting diff may optimistically be pulled from the cache, if not rendering a custom line range. This makes diff rendering very quick.

If operating with a cache, and the diff doesn’t exist in the cache, it will be stored after render.

render_to_string_uncached(request)[source]

Renders a diff to a string without caching.

This is a potentially expensive operation, and so is meant to be called only as often as necessary. render_to_string will call this if it’s not already in the cache.

make_cache_key()[source]

Creates and returns a cache key representing the diff to render.

make_context()[source]

Creates and returns context for a diff render.

get_diff_renderer_class()[source]

Returns the DiffRenderer class used for rendering diffs.

set_diff_renderer_class(renderer)[source]

Sets the DiffRenderer class used for rendering diffs.

get_diff_renderer(*args, **kwargs)[source]

Returns a DiffRenderer instance used for rendering diffs.