reviewboard.diffviewer.renderers¶
- class DiffRenderer(diff_file, *, chunk_index=None, collapse_all=True, lines_of_context=None, extra_context=None, allow_caching=True, template_name='diffviewer/diff_file_fragment.html', show_deleted=False, diff_settings)[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.
- __init__(diff_file, *, chunk_index=None, collapse_all=True, lines_of_context=None, extra_context=None, allow_caching=True, template_name='diffviewer/diff_file_fragment.html', show_deleted=False, diff_settings)[source]¶
Initialize the renderer.
Changed in version 6.0:
Removed the
highlighting
argument.Made
diff_settings
mandatory.
Changed in version 5.0.2:
Added
diff_settings
, which will be required starting in Review Board 6.Deprecated
highlighting
in favor ofdiff_settings
.
- Parameters:
diff_file (
dict
) – The diff file information to render.chunk_index (
int
, optional) –The index of a specific chunk to render.
Deprecated since version 5.0.2: This has been replaced with
diff_settings
.collapse_all (
bool
, optional) – Whether to collapse all chunks.lines_of_context (
list
ofint
, optional) –The lines of context to include for the render.
This can be a 1-item or 2-item list.
If 1-item, the contents will represent the lines of context both before and after modified lines.
If 2-item, the first item will be the lines of context before, and the second will be after.
extra_context (
dict
, optional) – Extra context data for the template.allow_caching (
bool
, optional) – Whether to allow caching of the rendered content.template_name (
str
, optional) – The name of the template used to render.show_deleted (
bool
, optional) – Whether to show deleted file content.diff_settings (
reviewboard.diffviewer.settings.DiffSettings
) –The settings used to control the display of diffs.
New in version 5.0.2.
- diff_settings: DiffSettings¶
Settings used for the generation of the diff.
New in version 5.0.2.
- Type:
reviewboard.diffviewer.settings.DiffSettings
- 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.
- __annotations__ = {'diff_settings': <class 'reviewboard.diffviewer.settings.DiffSettings'>}¶