Jump to >

reviewboard.reviews.detail

Definitions for the review request detail view.

class ReviewRequestPageData(review_request, request, last_visited=None, entry_classes=None)[source]

Bases: object

Data for the review request page.

The review request detail page needs a lot of data from the database, and going through the standard model relations will result in a lot more queries than necessary. This class bundles all that data together and handles pre-fetching and re-associating as necessary to limit the required number of queries.

All of the attributes within the class may not be available until both query_data_pre_etag() and query_data_post_etag() are called.

This object is not meant to be public API, and may change at any time. You should not use it in extension code.

body_bottom_replies

dict – A mapping from a top-level review ID to a list of the Review objects which reply to it.

body_top_replies

dict – A mapping from a top-level review ID to a list of the Review objects which reply to it.

review_comments

dict – A dictionary of comments across all reviews. The keys are Review IDs and the values are lists of comments.

draft_body_top_replies

dict – A dictionary of draft replies to body_top fields across all reviews. The keys are are Review IDs that are being replied to and the values are lists of replies.

draft_body_bottom_replies

dict – A dictionary of draft replies to body_bottom fields across all reviews. The keys are are Review IDs that are being replied to and the values are lists of replies.

draft_reply_comments

dict – A dictionary of draft reply comments across all reviews. The keys are Review IDs that are being replied to and the values are lists of reply comments.

changedescs

list of reviewboard.changedescs.models.ChangeDescription – All the change descriptions to be shown on the page.

diffsets

list of reviewboard.diffviewer.models.DiffSet – All of the diffsets associated with the review request.

diffsets_by_id

dict – A mapping from ID to DiffSet.

draft

reviewboard.reviews.models.ReviewRequestDraft – The active draft of the review request, if any. May be None.

active file_attachments

list of reviewboard.attachments.models.FileAttachment – All the active file attachments associated with the review request.

all_file_attachments

list of reviewboard.attachments.models.FileAttachment – All the file attachments associated with the review request.

file_attachments_by_id

dict – A mapping from ID to FileAttachment

issues

list of reviewboard.reviews.models.BaseComment – A list of all the comments (of all types) which are marked as issues.

issue_counts

dict – A dictionary storing counts of the various issue states throughout the page.

latest_changedesc_timestamp

datetime.datetime – The timestamp of the most recent change description on the page.

latest_review_timestamp

datetime.datetime – The timestamp of the most recent review on the page.

latest_timestamps_by_review_id

dict – A mapping from top-level review ID to the latest timestamp of the thread.

review_request

reviewboard.reviews.models.ReviewRequest – The review request.

review_request_details

reviewboard.reviews.models.base_review_request_details.BaseReviewRequestDetails – The review request (or the active draft thereof). In practice this will either be a ReviewRequest or a ReviewRequestDraft.

reviews

list of reviewboard.reviews.models.reviews.Review – All the reviews to be shown on the page. This includes any draft reviews owned by the requesting user but not drafts owned by others.

reviews_by_id

dict – A mapping from ID to Review.

active_screenshots

list of reviewboard.reviews.models.screenshots.Screenshot – All the active screenshots associated with the review request.

all_screenshots

list of reviewboard.reviews.models.Screenshot – All the screenshots associated with the review request.

screenshots_by_id

dict – A mapping from ID to Screenshot.

all_status_updates

list of reviewboard.reviews.models.status_updates.StatusUpdate – All status updates recorded for the review request.

initial_status_updates

list of reviewboard.reviews.models.status_updates.StatusUpdate – The status updates recorded on the initial publish of the review request.

change_status_updates

dict – The status updates associated with change descriptions. Each key in the dictionary is a ChangeDescription ID, and each key is a list of reviewboard.reviews.models. status_updates.StatusUpdate instances.

status_updates_enabled

bool – Whether the status updates feature is enabled for this review request. This does not necessarily mean that there are status updates on the review request.

__init__(review_request, request, last_visited=None, entry_classes=None)[source]

Initialize the data object.

Parameters:
  • review_request (reviewboard.reviews.models.ReviewRequest) – The review request.
  • request (django.http.HttpRequest) – The HTTP request object.
  • last_visited (datetime.datetime, optional) – The date/time when the user last visited the review request.
  • entry_classes (list of BaseReviewRequestPageEntry, optional) – The list of entry classes that should be used for data generation. If not provided, all registered entry classes will be used.
query_data_pre_etag()[source]

Perform initial queries for the page.

This method will populate only the data needed to compute the ETag. We avoid everything else until later so as to do the minimum amount possible before reporting to the client that they can just use their cached copy.

query_data_post_etag()[source]

Perform remaining queries for the page.

This method will populate everything else needed for the display of the review request page other than that which was required to compute the ETag.

get_entries()[source]

Return all entries for the review request page.

This will create and populate entries for the page (based on the entry classes provided in entry_classes). The entries can then be injected into the review request page.

Returns:A dictionary of entries. This has initial and main keys, corresponding to BaseReviewRequestPageEntry.ENTRY_POS_INITIAL and BaseReviewRequestPageEntry.ENTRY_POS_MAIN entries, respectively.

The initial entries are sorted in registered entry order, while the main entries are sorted in timestamp order.

Return type:dict
class BaseReviewRequestPageEntry(data, entry_id, added_timestamp, updated_timestamp=None, avatar_user=None)[source]

Bases: object

An entry on the review detail page.

This contains backend logic and frontend templates for one of the boxes that appears below the main review request box on the review request detail page.

added_timestamp

datetime.datetime – The timestamp of the entry. This represents the added time for the entry, and is used for sorting the entry in the page. This timestamp should never change.

avatar_user

django.contrib.auth.models.User – The user to display an avatar for. This can be None, in which case no avatar will be displayed. Templates can also override the avatar HTML instead of using this.

collapsed[source]

bool – Whether the entry should be initially collapsed.

entry_id

unicode – The ID of the entry. This will be unique across this type of entry, and may refer to a database object ID.

updated_timestamp

datetime.datetime – The timestamp when the entry was last updated. This reflects new updates or activity on the entry.

ENTRY_POS_INITIAL = 1[source]

An initial entry appearing above the review-like boxes.

ENTRY_POS_MAIN = 2[source]

An entry appearing in the main area along with review-like boxes.

entry_type_id = None[source]

The ID used for entries of this type.

entry_pos = 2[source]

The type of entry on the page.

By default, this is a box type, which will appear along with other reviews and change descriptions.

needs_draft = False[source]

Whether the entry needs a review request draft to be queried.

If set, ReviewRequestPageData.draft will be set (if a draft exists).

needs_reviews = False[source]

Whether the entry needs reviews, replies, and comments to be queried.

If set, ReviewRequestPageData.reviews, ReviewRequestPageData.diffsets, ReviewRequestPageData.diffsets_by_id, ReviewRequestPageData.active_file_attachments, ReviewRequestPageData.all_file_attachments, ReviewRequestPageData.file_attachments_by_id, ReviewRequestPageData.active_file_screenshots, ReviewRequestPageData.all_file_screenshots, and ReviewRequestPageData.file_screenshots_by_id will be set.

needs_changedescs = False[source]

Whether the entry needs change descriptions to be queried.

If set, ReviewRequestPageData.changedescs will be queried.

needs_status_updates = False[source]

Whether the entry needs status updates-related data to be queried.

This will also fetch the reviews, but will not automatically fetch any comments or other related data. For that, set needs_reviews.

If set, ReviewRequestPageData.reviews, If set, ReviewRequestPageData.all_status_updates, If set, ReviewRequestPageData.initial_status_updates, and If set, ReviewRequestPageData.change_status_updates will be set.

needs_file_attachments = False[source]

Whether the entry needs file attachment data to be queried.

If set, ReviewRequestPageData.active_file_attachments, ReviewRequestPageData.all_file_attachments, and ReviewRequestPageData.file_attachments_by_id will be set.

needs_screenshots = False[source]

Whether the entry needs screenshot data to be queried.

Most entries should never need this, as screenshots are deprecated.

If set, ReviewRequestPageData.active_screenshots, ReviewRequestPageData.all_screenshots, and ReviewRequestPageData.screenshots_by_id will be set.

template_name = None[source]

The template to render for the HTML.

js_template_name = u'reviews/entries/entry.js'[source]

The template to render for any JavaScript.

js_model_class = u'RB.ReviewRequestPage.Entry'[source]

The name of the JavaScript Backbone.Model class for this entry.

js_view_class = u'RB.ReviewRequestPage.EntryView'[source]

The name of the JavaScript Backbone.View class for this entry.

has_content = True[source]

Whether this entry has displayable content.

This can be overridden as a property to calculate whether to render the entry, or disabled altogether.

classmethod build_entries(data)[source]

Generate entry instances from review request page data.

Subclasses should override this to yield any entries needed, based on the page data.

Parameters:data (ReviewRequestPageData) – The data used for the entries on the page.
Yields:BaseReviewRequestPageEntry – An entry to include on the page.
classmethod build_etag_data(data)[source]

Build ETag data for the entry.

This will be incorporated into the ETag for the page. By default, the updated timestamp is used.

Parameters:data (ReviewRequestPageData) – The computed data (pre-ETag) for the page.
Returns:The ETag data for the entry.
Return type:unicode
__init__(data, entry_id, added_timestamp, updated_timestamp=None, avatar_user=None)[source]

Initialize the entry.

Parameters:
  • data (ReviewRequestPageData) – The computed data for the page.
  • entry_id (unicode) – The ID of the entry. This must be unique across this type of entry, and may refer to a database object ID.
  • added_timestamp (datetime.datetime) – The timestamp of the entry. This represents the added time for the entry, and is used for sorting the entry in the page. This timestamp should never change.
  • updated_timestamp (datetime.datetime, optional) – The timestamp when the entry was last updated. This should reflect new updates or activity on the entry.
  • avatar_user (django.contrib.auth.models.User, optional) – The user to display an avatar for. This can be None, in which case no avatar will be displayed. Templates can also override the avatar HTML instead of using this.
__repr__()[source]

Return a string representation for this entry.

Returns:A string representation for the entry.
Return type:unicode
collapsed[source]

Whether the entry is collapsed.

This will consist of a cached value computed from calculate_collapsed(). Subclasses should override that method.

is_entry_new(last_visited, user, **kwargs)[source]

Return whether the entry is new, from the user’s perspective.

By default, this compares the last visited time to the timestamp on the object. Subclasses can override this to provide additional logic.

Parameters:
Returns:

True if the entry will be shown as new. False if it will be shown as an existing entry.

Return type:

bool

calculate_collapsed()[source]

Calculate whether the entry should currently be collapsed.

By default, this will collapse the entry if the last update is older than the last time the user visited the entry and older than the last Change Description (or there isn’t one on the page yet).

Subclasses can augment or replace this logic as needed.

Returns:True if the entry should be collapsed. False if it should be expanded.
Return type:bool
get_dom_element_id()[source]

Return the ID used for the DOM element for this entry.

By default, this returns entry_type_id and entry_id concatenated. Subclasses should override this if they need something custom.

Returns:The ID used for the element.
Return type:unicode
get_js_model_data()[source]

Return data to pass to the JavaScript Model during instantiation.

The data returned from this function will be provided to the model when constructed.

Returns:A dictionary of attributes to pass to the Model instance. By default, it will be empty.
Return type:dict
get_js_view_data()[source]

Return data to pass to the JavaScript View during instantiation.

The data returned from this function will be provided to the view when constructed.

Returns:A dictionary of options to pass to the View instance. By default, it will be empty.
Return type:dict
get_extra_context(request, context)[source]

Return extra template context for the entry.

Subclasses can override this to provide additional context needed by the template for the page. By default, this returns an empty dictionary.

Parameters:
Returns:

Extra context to use for the entry’s template.

Return type:

dict

render_to_string(request, context)[source]

Render the entry to a string.

If the entry doesn’t have a template associated, or doesn’t have any content (as determined by has_content), then this will return an empty string.

Parameters:
Returns:

The resulting HTML for the entry.

Return type:

unicode

finalize()[source]

Perform final computations after all comments have been added.

class ReviewEntryMixin[source]

Bases: object

Mixin to provide functionality for entries containing reviews.

is_review_collapsed(review)[source]

Return whether a review should be collapsed.

A review is collapsed if all the following conditions are true:

  • There are no issues currently waiting to be resolved.
  • There are no draft replies to any comments or the body fields.
  • The review has not been seen since the latest activity on it (or seen at all).
Parameters:review (reviewboard.reviews.models.review.Review) – The review to compute the collapsed state for.
Returns:True if the review should be collapsed. False if not.
Return type:bool
serialize_review_js_model_data(review)[source]

Serialize information on a review for JavaScript models.

Parameters:review (reviewboard.reviews.models.review.Review) – The review to serialize.
Returns:The serialized data for the JavaScript model.
Return type:dict
class DiffCommentsSerializerMixin[source]

Bases: object

Mixin to provide diff comment data serialization.

serialize_diff_comments_js_model_data(diff_comments)[source]

Serialize information on diff comments for JavaScript models.

Parameters:diff_comments (list of reviewboard.reviews.models.diff_comment.Comment) – The list of comments to serialize.
Returns:The serialized data for the JavaScript model.
Return type:dict
class StatusUpdatesEntryMixin[source]

Bases: reviewboard.reviews.detail.DiffCommentsSerializerMixin, reviewboard.reviews.detail.ReviewEntryMixin

A mixin for any entries which can include status updates.

This provides common functionality for the two entries that include status updates (the initial status updates entry and change description entries).

status_updates

list of reviewboard.reviews.models.StatusUpdate – The status updates in this entry.

status_updates_by_review

dict – A mapping from review ID to the matching status update.

needs_reviews = True[source]
needs_status_updates = True[source]
classmethod build_etag_data(data)[source]

Build ETag data for the entry.

This will be incorporated into the ETag for the page.

Parameters:data (ReviewRequestPageData) – The computed data (pre-ETag) for the page.
Returns:The ETag data for the entry.
Return type:unicode
__init__()[source]

Initialize the entry.

are_status_updates_collapsed(status_updates)[source]

Return whether all status updates should be collapsed.

This considers all provided status updates when computing the collapsed state. It’s meant to be used along with other logic to compute an entry’s collapsed state.

Status updates that are pending or have not yet been seen by the user (assuming they’ve viewed the page at least once) are not collapsed.

Otherwise, the result is based off the review’s collapsed state for each status update. Status updates not containing a review are considered collapsable, and ones containing a review defer to ReviewEntryMixin.is_review_collapsed() for a result.

Parameters:status_updates (list of reviewboard.reviews.models.status_update.StatusUpdate) – The list of status updates to compute the collapsed state for.
Returns:True if all status updates are marked as collapsed. False if any are not marked as collapsed.
Return type:bool
add_update(update)[source]

Add a status update to the entry.

Parameters:update (reviewboard.reviews.models.StatusUpdate) – The status update to add.
populate_status_updates(status_updates)[source]

Populate the list of status updates for the entry.

This will add all the provided status updates and all comments from their reviews. It will also uncollapse the entry if there are any draft replies owned by the user.

Parameters:status_updates (list of reviewboard.reviews.models.status_update.StatusUpdate) – The list of status updates to add.
add_comment(comment_type, comment)[source]

Add a comment to the entry.

This will associate the comment with the correct status update.

Parameters:
finalize()[source]

Perform final computations after all comments have been added.

get_js_model_data()[source]

Return data to pass to the JavaScript Model during instantiation.

The data returned from this function will be provided to the model when constructed. This consists of information on the reviews for status updates and the comments made on diffs.

Returns:A dictionary of attributes to pass to the Model instance.
Return type:dict
class ReviewRequestEntry(data, entry_id, added_timestamp, updated_timestamp=None, avatar_user=None)[source]

Bases: reviewboard.reviews.detail.BaseReviewRequestPageEntry

An entry for the main review request box.

This is used to control the data queried by ReviewRequestPageData for display in the main review request box. It does not render onto the page.

entry_type_id = u'review-request'[source]
entry_pos = 1[source]
js_template_name = None[source]
js_model_class = None[source]
js_view_class = None[source]
needs_draft = True[source]
needs_file_attachments = True[source]
needs_screenshots = True[source]
needs_reviews = True[source]
has_content = False[source]
class InitialStatusUpdatesEntry(data)[source]

Bases: reviewboard.reviews.detail.StatusUpdatesEntryMixin, reviewboard.reviews.detail.BaseReviewRequestPageEntry

An entry for any status updates posted against the initial state.

StatusUpdate reviews (those created by automated tools like static analysis checkers or CI systems) are shown separately from ordinary reviews. When status updates are related to a ChangeDescription, they’re displayed within the change description box. Otherwise, they’re shown in their own box (immediately under the review request box), which is handled by this class.

entry_type_id = u'initial_status_updates'[source]
entry_pos = 1[source]
template_name = u'reviews/entries/initial_status_updates.html'[source]
js_model_class = u'RB.ReviewRequestPage.StatusUpdatesEntry'[source]
js_view_class = u'RB.ReviewRequestPage.InitialStatusUpdatesEntryView'[source]
classmethod build_entries(data)[source]

Generate the entry instance from review request page data.

This will only generate a single instance.

Parameters:data (ReviewRequestPageData) – The data used for the initial status update entry.
Yields:InitialStatusUpdatesEntry – The entry to include on the page.
__init__(data)[source]

Initialize the entry.

Parameters:data (ReviewRequestPageData) – Pre-queried data for the review request page.
has_content[source]

Whether there are any items to display in the entry.

Returns:True if there are any initial status updates to display.
Return type:bool
get_dom_element_id()[source]

Return the ID used for the DOM element for this entry.

Returns:The ID used for the element.
Return type:unicode
is_entry_new(last_visited, user, **kwargs)[source]

Return whether the entry is new, from the user’s perspective.

The initial status updates entry is basically part of the review request, and is never shown as new.

Parameters:
Returns:

False, always.

Return type:

bool

calculate_collapsed()[source]

Calculate whether the entry should currently be collapsed.

The entry will be collapsed if there aren’t yet any Change Descriptions on the page and if there aren’t any status updates with reviews that should be expanded. See ReviewEntryMixin.is_review_collapsed() for the collapsing rules for reviews.

Returns:True if the entry should be collapsed. False if it should be expanded.
Return type:bool
class ReviewEntry(data, review)[source]

Bases: reviewboard.reviews.detail.ReviewEntryMixin, reviewboard.reviews.detail.DiffCommentsSerializerMixin, reviewboard.reviews.detail.BaseReviewRequestPageEntry

A review box.

review

reviewboard.reviews.models.Review – The review for this entry.

issue_open_count

int – The count of open issues within this review.

has_issues

bool – Whether there are any issues (open or not).

comments

dict – A dictionary of comments. Each key in this represents a comment type, and the values are lists of comment objects.

entry_type_id = u'review'[source]
needs_reviews = True[source]
template_name = u'reviews/entries/review.html'[source]
js_model_class = u'RB.ReviewRequestPage.ReviewEntry'[source]
js_view_class = u'RB.ReviewRequestPage.ReviewEntryView'[source]
classmethod build_entries(data)[source]

Generate review entry instances from review request page data.

Parameters:data (ReviewRequestPageData) – The data used for the entries on the page.
Yields:ReviewEntry – A review entry to include on the page.
__init__(data, review)[source]

Initialize the entry.

Parameters:
can_revoke_ship_it[source]

Whether the Ship It can be revoked by the current user.

get_dom_element_id()[source]

Return the ID used for the DOM element for this entry.

Returns:The ID used for the element.
Return type:unicode
is_entry_new(last_visited, user, **kwargs)[source]

Return whether the entry is new, from the user’s perspective.

Parameters:
Returns:

True if the entry will be shown as new. False if it will be shown as an existing entry.

Return type:

bool

add_comment(comment_type, comment)[source]

Add a comment to this entry.

Parameters:
get_js_model_data()[source]

Return data to pass to the JavaScript Model during instantiation.

The data returned from this function will be provided to the model when constructed. This consists of information on the review and the comments made on diffs.

Returns:A dictionary of attributes to pass to the Model instance.
Return type:dict
calculate_collapsed()[source]

Calculate whether the entry should currently be collapsed.

The entry will be collapsed if the review is marked as collapsed. See ReviewEntryMixin.is_review_collapsed() for the collapsing rules for reviews.

Returns:True if the entry should be collapsed. False if it should be expanded.
Return type:bool
class ChangeEntry(data, changedesc)[source]

Bases: reviewboard.reviews.detail.StatusUpdatesEntryMixin, reviewboard.reviews.detail.BaseReviewRequestPageEntry

A change description box.

changedesc

reviewboard.changedescs.models.ChangeDescription – The change description for this entry.

entry_type_id = u'changedesc'[source]
needs_changedescs = True[source]
needs_file_attachments = True[source]
needs_screenshots = True[source]
template_name = u'reviews/entries/change.html'[source]
js_model_class = u'RB.ReviewRequestPage.ChangeEntry'[source]
js_view_class = u'RB.ReviewRequestPage.ChangeEntryView'[source]
classmethod build_entries(data)[source]

Generate change entry instances from review request page data.

Parameters:data (ReviewRequestPageData) – The data used for the entries on the page.
Yields:ChangeEntry – A change entry to include on the page.
__init__(data, changedesc)[source]

Initialize the entry.

Parameters:
get_dom_element_id()[source]

Return the ID used for the DOM element for this entry.

Returns:The ID used for the element.
Return type:unicode
is_entry_new(last_visited, user, **kwargs)[source]

Return whether the entry is new, from the user’s perspective.

Parameters:
Returns:

True if the entry will be shown as new. False if it will be shown as an existing entry.

Return type:

bool

calculate_collapsed()[source]

Calculate whether the entry should currently be collapsed.

The entry will be collapsed if the timestamp of the Change Description is older than that of the most recent Change Description and there aren’t any status updates with reviews that should be expanded. see ReviewEntryMixin.is_review_collapsed() for the collapsing rules for reviews.

Returns:True if the entry should be collapsed. False if it should be expanded.
Return type:bool
class ReviewRequestPageEntryRegistry[source]

Bases: reviewboard.registries.registry.OrderedRegistry

A registry for types of entries on the review request page.

lookup_attrs = [u'entry_type_id'][source]
errors = {u'already_registered': u'This review request page entry is already registered.', u'attribute_registered': u'A review request page entry with the entry_type_id "%(attr_value)s" is already registered by another entry (%(duplicate)s).', u'not_registered': u'"%(attr_value)s" is not a registered review request page entry ID.'}[source]
get_entry(entry_type_id)[source]

Return an entry with the given type ID.

Parameters:entry_type_id (unicode) – The ID of the entry type to return.
Returns:The registered page entry type matching the ID, or None if it could not be found.
Return type:type
get_defaults()[source]

Return the default review request page entry types for the registry.

This is used internally by the registry to populate the list of built-in types of entries that should be used on the review request page.

Returns:The list of default entry types.
Return type:list of BaseReviewRequestPageEntry