reviewboard.reviews.views.diff_fragments¶
Views for rendering diff fragments.
- class CommentFragment[source]¶
Bases:
TypedDict
A comment fragment.
New in version 6.0.
- html: SafeString¶
The rendered diff fragment HTML.
- chunks: List[Dict]¶
The diff chunks included in the fragment.
This is the information returned by
get_file_chunks_in_range()
.- Type:
- __annotations__ = {'chunks': typing.List[typing.Dict], 'comment': <class 'reviewboard.reviews.models.diff_comment.Comment'>, 'html': <class 'django.utils.safestring.SafeString'>}¶
- __optional_keys__ = frozenset({})¶
- __orig_bases__ = (<function TypedDict>,)¶
- __required_keys__ = frozenset({'chunks', 'comment', 'html'})¶
- __total__ = True¶
- build_diff_comment_fragments(*, comments: List[Comment], context: Dict[str, Any], comment_template_name: str = 'reviews/diff_comment_fragment.html', error_template_name: str = 'diffviewer/diff_fragment_error.html', lines_of_context: Optional[List[int]] = None, show_controls: bool = False, request: Optional[HttpRequest] = None) Tuple[bool, List[CommentFragment]] [source]¶
Construct and return the comment fragment data.
- Parameters:
comments (
list
ofreviewboard.reviews.models.diff_comment.Comment
) – The comments to return diff fragments for.context (
dict
) – The rendering context.comment_template_name (
str
, optional) – The template to use for rendering the comment fragment.error_template_name (
str
, optional) – The template to use for rendering errors.lines_of_context (
list
ofint
, optional) – A 2-element list containing the number of additional lines of context to render above and below each fragment.show_controls (
bool
, optional) – Whether to show expand controls in the rendered output.request (
django.http.HttpRequest
, optional) – The HTTP request from the client, if available.
- Returns:
A 2-tuple containing:
- Tuple:
0 (
bool
) – Whether any errors occurred.1 (
list
ofCommentFragment
) – The rendered comment fragments.
- Return type:
- class CommentDiffFragmentsView(**kwargs)[source]¶
Bases:
ReviewRequestViewMixin
,ETagViewMixin
,ContextMixin
,View
View for rendering a section of a diff that a comment pertains to.
This takes in one or more
Comment
IDs (comma-separated) as part of the URL and returns a payload containing data and HTML for each comment’s diff fragment, which the client can parse in order to dynamically load the fragments into the page.The resulting format is a custom, condensed format containing the comment ID and HTML for each diff fragment. It’s designed to be quick to parse and reduces the amount of data to send across the wire (unlike a format like JSON, which would add overhead to the serialization/deserialization time and data size when storing HTML, or JavaScript, which releases prior to 3.0 used to handle injecting fragments into the DOM).
Each entry in the payload is in the following format, with all entries joined together:
<comment ID>n <html length>n <html content>
The format is subject to change without notice, and should not be relied upon by third parties.
The following URL query options are supported:
allow_expansion
:Whether expansion controls should be shown to the user. To enable this, the caller must pass a value of
1
. This is disabled by default.lines_of_context
:The number of lines of context before and after the commented region of the diff. This is in the form of
pre,post
, where both are the numbers of lines. This defaults to0,0
.
- get_etag_data(request: HttpRequest, comment_ids: str, *args, **kwargs) str [source]¶
Return an ETag for the view.
This will look up state needed for the request and generate a suitable ETag. Some of the information will be stored for later computation of the template context.
- Parameters:
request (
django.http.HttpRequest
) – The HTTP request from the client.comment_ids (
str
) – A list of comment IDs to render.*args (
tuple
, unused) – Positional arguments passsed to the handler.**kwargs (
dict
, unused) – Keyword arguments passed to the handler.
- Returns:
The ETag for the page.
- Return type:
- get(request: HttpRequest, **kwargs) HttpResponse [source]¶
Handle HTTP GET requests for this view.
This will generate a payload for the diff comments being loaded and pass them in a format that can be parsed by the client.
- Parameters:
request (
django.http.HttpRequest
) – The HTTP request from the client.**kwargs (
dict
) – Keyword arguments passed to the view.
- Returns:
The HTTP response containing the fragments payload.
- Return type:
- __annotations__ = {}¶
- class ReviewsDiffFragmentView(**kwargs)[source]¶
Bases:
ReviewRequestViewMixin
,DiffFragmentView
Renders a fragment from a file in the diff viewer.
Displays just a fragment of a diff or interdiff owned by the given review request. The fragment is identified by the chunk index in the diff.
review_request_id
:The ID of the ReviewRequest containing the diff to render.
revision
:The DiffSet revision to render.
filediff_id
:The ID of the FileDiff within the DiffSet.
The following may also be provided:
interdiff_revision
:The second DiffSet revision in an interdiff revision range.
chunk_index
:The index (0-based) of the chunk to render. If left out, the entire file will be rendered.
local_site
:The LocalSite the ReviewRequest must be on, if any.
See
DiffFragmentView
for the accepted query parameters.- process_diffset_info(revision: int, interdiff_revision: Optional[int] = None, **kwargs) Dict[str, Any] [source]¶
Process and return information on the desired diff.
The diff IDs and other data passed to the view can be processed and converted into DiffSets. A dictionary with the DiffSet and FileDiff information will be returned.
If the review request cannot be accessed by the user, an HttpResponse will be returned instead.
- create_renderer(diff_file: Dict[str, Any], *args, **kwargs) DiffRenderer [source]¶
Create the DiffRenderer for this fragment.
This will augment the renderer for binary files by looking up file attachments, if review UIs are involved, disabling caching.
- Parameters:
- Returns:
The resulting diff renderer.
- Return type:
- __annotations__ = {}¶