reviewboard.reviews.views.mixins¶
Mixins for review request views.
- class ReviewRequestViewMixin[source]¶
Bases:
CheckRequestMethodViewMixin
,CheckLoginRequiredViewMixin
,CheckLocalSiteAccessViewMixin
,PrePostDispatchViewMixin
Common functionality for all review request-related pages.
This performs checks to ensure that the user has access to the page, returning an error page if not. It also provides common functionality for fetching a review request for the given page, returning suitable context for the template, and generating an image used to represent the site when posting to social media sites.
- class StatusExtraInfo[source]¶
Bases:
TypedDict
Extra info to include in the status rendering.
This is used in
get_review_request_status_html()
.- __annotations__ = {'extra_vars': ForwardRef('dict', module='reviewboard.reviews.views.mixins'), 'text': ForwardRef('str', module='reviewboard.reviews.views.mixins'), 'timestamp': ForwardRef('Optional[datetime]', module='reviewboard.reviews.views.mixins')}¶
- __optional_keys__ = frozenset({})¶
- __orig_bases__ = (<function TypedDict>,)¶
- __required_keys__ = frozenset({'extra_vars', 'text', 'timestamp'})¶
- __total__ = True¶
- pre_dispatch(request: HttpRequest, review_request_id: int, *args, **kwargs) Optional[HttpResponse] [source]¶
Look up objects and permissions before dispatching the request.
This will first look up the review request, returning an error page if it’s not accessible. It will then store the review request before calling the handler for the HTTP request.
- Parameters:
request (
django.http.HttpRequest
) – The HTTP request from the client.review_request_id (
int
) – The ID of the review request being accessed.*args (
tuple
) – Positional arguments to pass to the handler.**kwargs (
dict
) –Keyword arguments to pass to the handler.
These will be arguments provided by the URL pattern.
- Returns:
The resulting HTTP response to send to the client, if there’s a Permission Denied.
- Return type:
- render_permission_denied(request: HttpRequest) HttpResponse [source]¶
Render a Permission Denied page.
This will be shown to the user if they’re not able to view the review request.
- Parameters:
request (
django.http.HttpRequest
) – The HTTP request from the client.- Returns:
The resulting HTTP response to send to the client.
- Return type:
- get_review_request(review_request_id: int, local_site: Optional[LocalSite] = None) ReviewRequest [source]¶
Return the review request for the given display ID.
- Parameters:
review_request_id (
int
) – The review request’s display ID.local_site (
reviewboard.site.models.LocalSite
) – The Local Site the review request is on.
- Returns:
The review request for the given display ID and Local Site.
- Return type:
- Raises:
django.http.Http404 – The review request could not be found.
- get_diff(revision: Optional[int] = None, draft: Optional[ReviewRequestDraft] = None) DiffSet [source]¶
Return a diff on the review request matching the given criteria.
If a draft is provided, and
revision
is eitherNone
or matches the revision on the draft’s DiffSet, that DiffSet will be returned.- Parameters:
revision (
int
, optional) – The revision of the diff to retrieve. If not provided, the latest DiffSet will be returned.draft (
reviewboard.reviews.models.review_request_draft.ReviewRequestDraft
, optional) – The draft of the review request.
- Returns:
The resulting DiffSet.
- Return type:
- Raises:
django.http.Http404 – The diff does not exist.
- get_social_page_image_url(file_attachments: FileAttachmentSequence) Optional[str] [source]¶
Return the URL to an image used for social media sharing.
This will look for the first attachment in a list of attachments that can be used to represent the review request on social media sites and chat services. If a suitable attachment is found, its URL will be returned.
- Parameters:
file_attachments (
list
ofreviewboard.attachments.models.FileAttachment
) – A list of file attachments used on a review request.- Returns:
The URL to the first image file attachment, if found, or
None
if no suitable attachments were found.- Return type:
- get_review_request_status_html(review_request_details: BaseReviewRequestDetails, close_info: ReviewRequestCloseInfo, extra_info: List[StatusExtraInfo] = []) SafeString [source]¶
Return HTML describing the current status of a review request.
This will return a description of the submitted, discarded, or open state for the review request, for use in the rendering of the page.
- Parameters:
review_request_details (
reviewboard.reviews.models.base_review_request_details.BaseReviewRequestDetails
) – The review request or draft being viewed.close_info (
dict
) – A dictionary of information on the closed state of the review request.extra_info (
list
ofdict
) – A list of dictionaries showing additional status information. Each must have atext
field containing a format string using{keyword}
-formatted variables, atimestamp
field (which will be normalized to the local timestamp), and an optionalextra_vars
for the format string.
- Returns:
The status text as HTML for the page.
- Return type:
- __annotations__ = {}¶