reviewboard.reviews.ui.text¶
A Review UI for text-based files.
- class SerializedTextComment[source]¶
Bases:
SerializedComment
Serialized comment data for text review UIs.
This must be kept in sync with the definitions in
reviewboard/static/rb/js/reviews/models/commentData.ts
.New in version 7.0.
- viewMode: str¶
The view mode of the document when the comment was made.
This will be either “source” or “rendered”.
- __annotations__ = {'beginLineNum': ForwardRef('int', module='reviewboard.reviews.ui.text'), 'comment_id': ForwardRef('int', module='reviewboard.reviews.ui.base'), 'endLineNum': ForwardRef('int', module='reviewboard.reviews.ui.text'), 'html': ForwardRef('str', module='reviewboard.reviews.ui.base'), 'issue_opened': ForwardRef('bool', module='reviewboard.reviews.ui.base'), 'issue_status': ForwardRef('str', module='reviewboard.reviews.ui.base'), 'localdraft': ForwardRef('bool', module='reviewboard.reviews.ui.base'), 'reply_to_id': ForwardRef('int', module='reviewboard.reviews.ui.base'), 'review_id': ForwardRef('int', module='reviewboard.reviews.ui.base'), 'review_request_id': ForwardRef('int', module='reviewboard.reviews.ui.base'), 'rich_text': ForwardRef('bool', module='reviewboard.reviews.ui.base'), 'text': ForwardRef('str', module='reviewboard.reviews.ui.base'), 'url': ForwardRef('str', module='reviewboard.reviews.ui.base'), 'user': ForwardRef('SerializedCommentUser', module='reviewboard.reviews.ui.base'), 'viewMode': ForwardRef('str', module='reviewboard.reviews.ui.text')}¶
- __closed__ = False¶
- __extra_items__ = None¶
- __mutable_keys__ = frozenset({'beginLineNum', 'comment_id', 'endLineNum', 'html', 'issue_opened', 'issue_status', 'localdraft', 'reply_to_id', 'review_id', 'review_request_id', 'rich_text', 'text', 'url', 'user', 'viewMode'})¶
- __optional_keys__ = frozenset({})¶
- __orig_bases__ = (<class 'reviewboard.reviews.ui.base.SerializedComment'>,)¶
- __readonly_keys__ = frozenset({})¶
- __required_keys__ = frozenset({'beginLineNum', 'comment_id', 'endLineNum', 'html', 'issue_opened', 'issue_status', 'localdraft', 'reply_to_id', 'review_id', 'review_request_id', 'rich_text', 'text', 'url', 'user', 'viewMode'})¶
- __total__ = True¶
- user: SerializedCommentUser¶
- class TextBasedReviewUI(review_request: ReviewRequest, obj: ReviewableType)[source]¶
Bases:
ReviewUI
[FileAttachment
,FileAttachmentComment
,SerializedTextComment
]A Review UI for text-based files.
This renders the text file, applying syntax highlighting, and allows users to comment on one or more lines.
- supported_mimetypes: ClassVar[list[str]] = ['text/*', 'application/javascript', 'application/json', 'application/x-javascript', 'application/x-json', 'application/x-yaml'][source]¶
The list of MIME types that this Review UI supports.
- template_name: ClassVar[str] = 'reviews/ui/text.html'[source]¶
The template that renders the Review UI.
Generally, subclasses should use the default template and render the UI using JavaScript.
- supports_diffing: ClassVar[bool] = True[source]¶
Whether this Review UI supports diffing two objects.
- supports_file_attachments: ClassVar[bool] = True[source]¶
Whether this Review UI supports reviewing FileAttachment objects.
- source_chunk_generator_cls[source]¶
alias of
RawDiffChunkGenerator
- rendered_chunk_generator_cls[source]¶
alias of
RawDiffChunkGenerator
- get_js_model_data() JSONDict [source]¶
Return data to pass to the JavaScript Model during instantiation.
This data will be passed as attributes to the reviewable model when constructed.
- Returns:
The attributes to pass to the model.
- Return type:
- get_extra_context(request: HttpRequest) dict[str, Any] [source]¶
Return extra context to use when rendering the Review UI.
- Parameters:
request (
django.http.HttpRequest
) – The HTTP request from the client.- Returns:
The context to provide to the template.
- Return type:
- get_text() str [source]¶
Return the file contents as a string.
This will fetch the file and then cache it for future renders.
- Returns:
The file contents as a text string.
- Return type:
- get_text_lines() Sequence[str] [source]¶
Return the file contents as syntax-highlighted lines.
This will fetch the file, render it however appropriate for the review UI, and split it into reviewable lines. It will then cache it for future renders.
- get_rendered_lines() list[str] [source]¶
Return the file contents as a render, based on the raw text.
If a subclass sets
can_render_text = True
and implementsgenerate_render
, then this will render the contents in some specialized form, cache it as a list of lines, and return it.
- generate_highlighted_text() list[str] [source]¶
Generate syntax-highlighted text for the file.
This will render the text file to HTML, applying any syntax highlighting that’s appropriate. The contents will be split into reviewable lines and will be cached for future renders.
- get_source_lexer(filename: str, data: str) Lexer [source]¶
Return the lexer that should be used for the text.
By default, this will attempt to guess the lexer based on the filename, falling back to a plain-text lexer.
Subclasses can override this to choose a more specific lexer.
- generate_render() Iterator[str] [source]¶
Generate a render of the text.
By default, this won’t do anything. Subclasses should override it to turn the raw text into some form of rendered content. For example, rendering Markdown.
- Yields:
str
– The rendered lines of content.
- serialize_comments(comments: Sequence[FileAttachmentComment]) Dict[str, List[SerializedTextComment]] [source]¶
Serialize the comments for the file attachment.
- Parameters:
comments (
list
of :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:``reviewboard.reviews.models.FileAttachmentComment
) – The list of objects to serialize. This will be the result ofget_comments()
.- Returns:
The serialized comments.
- Return type:
SerializedCommentBlocks
- get_comment_thumbnail(comment: FileAttachmentComment) Optional[str] [source]¶
Generate and return a thumbnail representing this comment.
This will find the appropriate lines the comment applies to and return it as HTML suited for rendering in reviews.
- Parameters:
comment (
reviewboard.reviews.models.FileAttachmentComment
) – The comment to render the thumbnail for.- Returns:
The rendered comment thumbnail.
- Return type:
- render_comment_thumbnail(comment: FileAttachmentComment, begin_line_num: int, end_line_num: int, view_mode: str) str [source]¶
Render the content of a comment thumbnail.
This will, by default, call render() and then pull out the lines that were commented on.
Subclasses can override to do more specialized thumbnail rendering.
- Parameters:
comment (
reviewboard.reviews.models.FileAttachmentComment
) – The comment to render the thumbnail for.begin_line_num (
int
) – The starting line number for the comment.end_line_num (
int
) – The end line number for the comment.view_mode (
str
) – The view mode. One ofsource
orrendered
.
- Returns:
The rendered comment thumbnail.
- Return type:
- get_comment_link_url(comment: FileAttachmentComment) str [source]¶
Return the URL to the file and line commented on.
This will link to the correct file, view mode, and line for the given comment.
- Parameters:
comment (
reviewboard.reviews.models.FileAttachmentComment
) – The comment to link to.- Returns:
The URL to link the comment to.
- Return type:
- __annotations__ = {'allow_inline': 'ClassVar[bool]', 'css_bundle_names': 'ClassVar[list[str]]', 'diff_against_obj': 'Optional[ReviewableType]', 'diff_type_mismatch': 'ClassVar[bool]', 'extra_css_classes': 'list[str]', 'js_bundle_names': 'ClassVar[list[str]]', 'js_files': 'ClassVar[list[str]]', 'js_model_class': 'str', 'js_view_class': 'str', 'name': 'ClassVar[str]', 'obj': 'ReviewableType', 'object_key': 'str', 'request': 'Optional[HttpRequest]', 'supported_mimetypes': 'ClassVar[list[str]]', 'supports_diffing': 'ClassVar[bool]', 'supports_file_attachments': 'ClassVar[bool]', 'template_name': 'ClassVar[str]'}¶
- __orig_bases__ = (reviewboard.reviews.ui.base.ReviewUI[reviewboard.attachments.models.FileAttachment, reviewboard.reviews.models.file_attachment_comment.FileAttachmentComment, reviewboard.reviews.ui.text.SerializedTextComment],)¶
- __parameters__ = ()¶