reviewboard.reviews.managers¶
Managers for reviewboard.reviews.models.
- class CommentManager(*args, **kwargs)[source]¶
Bases:
Manager
A manager for Comment models.
This handles concurrency issues with Comment models.
New in version 5.0.
- accessible(user, extra_query=None, local_site=None, distinct=False)[source]¶
Return a queryset for comments accessible by the given user.
For superusers, all comments in all reviews will be returned.
For regular users, only comments in reviews that they own or that are in the repositories, local sites, and review groups which the user has access to will be returned.
For anonymous users, only comments that are in public repositories and whose review requests are not targeted by invite-only review groups will be returned.
- Parameters:
user (
django.contrib.auth.models.User
) – The User object that must have access to any returned comments.extra_query (
django.db.models.Q
, optional) – Additional query parameters to add for filtering down the resulting queryset.local_site (
reviewboard.site.models.LocalSite
or :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:``reviewboard.site.models.LocalSite.ALL
, optional) –A specific Local Site that the comments must be associated with. It is assumed that the given user has access to the Local Site. By default, this will only return comments not part of a site.
This may be
LocalSite.ALL
.distinct (
bool
, optional) –Whether to return distinct results.
Turning this on can decrease performance. It’s off by default.
- Returns:
The resulting queryset.
- Return type:
- from_user(user, *args, **kwargs)[source]¶
Return the query for comments created by a user.
- Parameters:
user (
django.contrib.auth.models.User
) – The User object to query for.*args (
tuple
) – Additional positional arguments to pass to the common_query()
function.**kwargs (
dict
) – Additional keyword arguments to pass to the common_query()
function.
- Returns:
A queryset for all the comments created by the given user.
- Return type:
- __annotations__ = {}¶
- __slotnames__ = []¶
- class DefaultReviewerManager(*args, **kwargs)[source]¶
Bases:
Manager
A manager for DefaultReviewer models.
- for_repository(repository, local_site)[source]¶
Returns all DefaultReviewers that represent a repository.
These include both DefaultReviewers that have no repositories (for backwards-compatibility) and DefaultReviewers that are associated with the given repository.
- __annotations__ = {}¶
- __slotnames__ = []¶
- class ReviewGroupManager(*args, **kwargs)[source]¶
Bases:
Manager
A manager for Group models.
- accessible(user, *, visible_only=True, local_site=None, distinct=True)[source]¶
Return a queryset for review groups accessible by the given user.
For superusers, all public and invite-only review groups will be returned.
For regular users, only review groups that are public or that the user is on the access list for will be returned.
For anonymous users, only public review groups will be returned.
The returned list is further filtered down based on the
visible_only
andlocal_site
parameters.Note
This is not responsible for checking if a user has access to a given
local_site
. This function assumes that access has already been checked.Changed in version 6.0: Removed the
show_all_local_sites
argument.Changed in version 5.0: Deprecated
show_all_local_sites
and added support for settinglocal_site
toLocalSite.ALL
.Changed in version 3.0.24: Added the
distinct
parameter.- Parameters:
user (
django.contrib.auth.models.User
) – The user that must have access to any returned groups.visible_only (
bool
, optional) – Whether only visible review groups should be returned.local_site (
reviewboard.site.models.LocalSite
or :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:``reviewboard.site.models.LocalSite.ALL
, optional) –A specific Local Site that the groups must be associated with. By default, this will only return groups not part of a site.
This may be
LocalSite.ALL
.Changed in version 5.0: Added support for
LocalSite.ALL
.distinct (
bool
, optional) –Whether to return distinct results.
Turning this off can increase performance. It’s on by default for backwards-compatibility.
- Returns:
The resulting queryset.
- Return type:
- accessible_ids(*args, **kwargs)[source]¶
Return IDs of groups that are accessible by the given user.
This wraps
accessible()
and takes the same arguments (with the exception ofdistinct
, which is ignored).Changed in version 3.0.24: In prior versions, the order was not specified, but was generally numeric order. This should still be true, but officially, we no longer guarantee any order of results.
- Parameters:
*args (
tuple
) – Positional arguments to pass toaccessible()
.**kwargs (
dict
) – Keyword arguments to pass toaccessible()
.
- Returns:
The list of IDs.
- Return type:
- __annotations__ = {}¶
- __slotnames__ = []¶
- class ReviewRequestQuerySet(model=None, query=None, using=None, hints=None)[source]¶
Bases:
QuerySet
- __annotations__ = {}¶
- class ReviewRequestManager(*args, **kwargs)[source]¶
Bases:
Manager
A manager for review requests. Provides specialized queries to retrieve review requests with specific targets or origins, and to create review requests based on certain data.
- get_queryset()[source]¶
Return a QuerySet for ReviewRequest models.
- Returns:
The new QuerySet instance.
- Return type:
- create(user, repository, commit_id=None, local_site=None, create_from_commit_id=False, create_with_history=False)[source]¶
Create a new review request.
- Parameters:
user (
django.contrib.auth.models.User
) – The user creating the review request. They will be tracked as the submitter.repository (
reviewboard.scmtools.Models.Repository
) –The repository, if any, the review request is associated with.
If
None
, diffs cannot be added to the review request.commit_id (
unicode
, optional) – An optional commit ID.local_site (
reviewboard.site.models.LocalSite
, optional) – An optional LocalSite to associate the review request with.create_from_commit_id (
bool
, optional) – Whether or not the givencommit_id
should be used to pre-populate the review request data. IfTrue
, the givenrepository
will be used to do so.create_with_history (
bool
, optional) –Whether or not the created review request will support attaching multiple commits per diff revision.
If
False
, it will not be possible to use theDiffResource
to upload diffs; theDiffCommitResource
must be used instead.
- Returns:
The created review request.
- Return type:
- Raises:
reviewboard.hostingsvcs.errors.HostingServiceError – The hosting service backing the repository encountered an error.
reviewboard.scmtools.errors.ChangeNumberInUseError – The commit ID is already in use by another review request.
reviewboard.scmtools.errors.SCMError – The repository tool encountered an error.
ValueError – An invalid value was passed for an argument.
- get_to_group_query(group_name, local_site)[source]¶
Return a Q() query object targeting a group.
This is meant to be passed as an
extra_query
argument topublic()
.- Parameters:
group_name (
str
) – The name of the review group the review requests must be assigned to.local_site (
reviewboard.site.models.LocalSite
) –The Local Site that the review requests must be on, if any.
This does not accept
LocalSite.ALL
.Callers should first validate that the user has access to the Local Site, if provided.
- Returns:
The query object.
- Return type:
- get_to_user_groups_query(user_or_username)[source]¶
Return a Q() query object targeting groups joined by a user.
This is meant to be passed as an
extra_query
argument topublic()
.- Parameters:
user_or_username (
django.contrib.auth.models.User
orstr
) – The User instance or username that all review requests must be assigned to indirectly.- Returns:
The query object.
- Return type:
- Raises:
django.contrib.auth.models.User.DoesNotExist – A username was provided, and that user does not exist.
- get_to_user_directly_query(user_or_username)[source]¶
Returns the query targeting a user directly.
This will include review requests where the user has been listed as a reviewer, or the user has starred.
This is meant to be passed as an
extra_query
argument topublic()
.- Parameters:
user_or_username (
django.contrib.auth.models.User
orstr
) – The User instance or username that all review requests must be assigned to directly.- Returns:
The query object.
- Return type:
- Raises:
django.contrib.auth.models.User.DoesNotExist – A username was provided, and that user does not exist.
- get_to_user_query(user_or_username)[source]¶
Return a Q() query object targeting a user indirectly.
This will include review requests where the user has been listed as a reviewer, or a group that the user belongs to has been listed, or the user has starred.
This is meant to be passed as an
extra_query
argument topublic()
.- Parameters:
user_or_username (
django.contrib.auth.models.User
orstr
) – The User instance or username that all review requests must be assigned to (directly to indirectly).- Returns:
The query object.
- Return type:
- Raises:
django.contrib.auth.models.User.DoesNotExist – A username was provided, and that user does not exist.
- get_from_user_query(user_or_username)[source]¶
Return a Q() query object for review requests owned by a user.
This is meant to be passed as an
extra_query
argument topublic()
.- Parameters:
user_or_username (
django.contrib.auth.models.User
orstr
) – The User instance or username that all review requests must be owned by.- Returns:
The query object.
- Return type:
- get_to_or_from_user_query(user_or_username)[source]¶
Return a Q() query object for review requests involving a user.
This is meant to be passed as an
extra_query
argument topublic()
.- Parameters:
user_or_username (
django.contrib.auth.models.User
orunicode
) – The User instance or username that all review requests must either be owned by or assigned to (directly to indirectly).- Returns:
The query object.
- Return type:
- Raises:
django.contrib.auth.models.User.DoesNotExist – A username was provided, and that user does not exist.
- public(filter_private=True, *args, **kwargs)[source]¶
Query public review requests, filtered by given criteria.
- Parameters:
filter_private (
bool
, optional) –Whether to filter out any review requests on private repositories or invite-only review groups that the user does not have access to.
By default, they are filtered out.
This requires
user
to be provided.*args (
tuple
) – Additional positional arguments to pass to the common_query()
function.**kwargs (
dict
) – Additional keyword arguments to pass to the common_query()
function.
- Returns:
The resulting queryset.
- Return type:
- to_group(group_name, local_site, *args, **kwargs)[source]¶
Query review requests made to a review group.
The result will be review requests assigned to a review group.
By default, the results will not be filtered based on whether a user has access to the review requests (via private repository or invite-only review group ACLs). To filter based on access, pass
filter_private=True
.- Parameters:
group_name (
str
) – The name of the review group the review requests must be assigned to.local_site (
reviewboard.site.models.LocalSite
) –The Local Site that the review requests must be on, if any.
This does not accept
LocalSite.ALL
.Callers should first validate that the user has access to the Local Site, if provided.
*args (
tuple
) – Additional positional arguments to pass to the common_query()
function.**kwargs (
dict
) – Additional keyword arguments to pass to the common_query()
function.
- Returns:
The resulting queryset.
- Return type:
- to_or_from_user(user_or_username, *args, **kwargs)[source]¶
Query review requests a user is involved in.
The result will be review requests from a user, assigned to the user, or assigned to a group the user is in.
By default, the results will not be filtered based on whether a user has access to the review requests (via private repository or invite-only review group ACLs). To filter based on access, pass
filter_private=True
.- Parameters:
user_or_username (
django.contrib.auth.models.User
orunicode
) – The User instance or username that all review requests must either be owned by or assigned to (directly to indirectly).*args (
tuple
) – Additional positional arguments to pass to the common_query()
function.**kwargs (
dict
) – Additional keyword arguments to pass to the common_query()
function.
- Returns:
A queryset of all review requests the users is involved in as either a submitter or a reviewer (either directly assigned or indirectly as a member of a group).
- Return type:
- Raises:
django.contrib.auth.models.User.DoesNotExist – A username was provided, and that user does not exist.
- to_user_groups(username, *args, **kwargs)[source]¶
Query review requests made to a user’s review groups.
The result will be review requests assigned to a group the user is in.
By default, the results will not be filtered based on whether a user has access to the review requests (via private repository or invite-only review group ACLs). To filter based on access, pass
filter_private=True
.- Parameters:
username (
django.contrib.auth.models.User
orstr
) – The User instance or username.- Returns:
A queryset of all review requests the users is involved in as either a submitter or a reviewer (either directly assigned or indirectly as a member of a group).
- Return type:
- Raises:
django.contrib.auth.models.User.DoesNotExist – A username was provided, and that user does not exist.
- to_user_directly(user_or_username, *args, **kwargs)[source]¶
Query review requests assigned directly to a user.
The result will be review requests assigned to the user.
By default, the results will not be filtered based on whether a user has access to the review requests (via private repository or invite-only review group ACLs). To filter based on access, pass
filter_private=True
.- Parameters:
user_or_username (
django.contrib.auth.models.User
orunicode
) – The user object or username to query for.*args (
tuple
) – Additional positional arguments to pass to the common_query()
function.**kwargs (
dict
) – Additional keyword arguments to pass to the common_query()
function.
- Returns:
The resulting queryset.
- Return type:
- Raises:
django.contrib.auth.models.User.DoesNotExist – A username was provided, and that user does not exist.
- to_user(user_or_username, *args, **kwargs)[source]¶
Query review requests assigned directly or indirectly to a user.
The result will be review requests assigned to the user or to a group the user is in.
By default, the results will not be filtered based on whether a user has access to the review requests (via private repository or invite-only review group ACLs). To filter based on access, pass
filter_private=True
.- Parameters:
user_or_username (
django.contrib.auth.models.User
orunicode
) – The user object or username to query for.*args (
tuple
) – Additional positional arguments to pass to the common_query()
function.**kwargs (
dict
) – Additional keyword arguments to pass to the common_query()
function.
- Returns:
The resulting queryset.
- Return type:
- Raises:
django.contrib.auth.models.User.DoesNotExist – A username was provided, and that user does not exist.
- from_user(user_or_username, *args, **kwargs)[source]¶
Query review requests from a user.
The result will be review requests created or currently owned by a user.
By default, the results will not be filtered based on whether a user has access to the review requests (via private repository or invite-only review group ACLs). To filter based on access, pass
filter_private=True
.- Parameters:
user_or_username (
django.contrib.auth.models.User
orunicode
) – The user object or username to query for.*args (
tuple
) – Additional positional arguments to pass to the common_query()
function.**kwargs (
dict
) – Additional keyword arguments to pass to the common_query()
function.
- Returns:
The resulting queryset.
- Return type:
- for_id(pk, local_site=None)[source]¶
Returns the review request matching the given ID and LocalSite.
If a LocalSite is provided, then the ID will be matched against the displayed ID for the LocalSite, rather than the in-database ID.
- __annotations__ = {}¶
- __slotnames__ = []¶
- class ReviewManager(*args, **kwargs)[source]¶
Bases:
Manager
A manager for Review models.
This handles concurrency issues with Review models. In particular, it will try hard not to save two reviews at the same time, and if it does manage to do that (which may happen for pending reviews while a server is under heavy load), it will repair and consolidate the reviews on load. This prevents errors and lost data.
- accessible(user: User, extra_query: Optional[Q] = None, local_site: Optional[LocalSite] = None, public: Optional[bool] = None, base_reply_to: Optional[Union[Review, _ReviewANY]] = None, distinct: Optional[bool] = False) QuerySet [source]¶
Return a queryset for reviews accessible by the given user.
For superusers, all public (published) and unpublished reviews will be returned.
For regular users, only reviews that are owned by the user or that are public in the repositories, local sites, and review groups which the user has access to will be returned.
For anonymous users, only public reviews that are on public repositories and whose review requests are not targeted by invite-only review groups will be returned.
Changed in version 6.0: Added the
base_reply_to
argument.New in version 5.0.
- Parameters:
user (
django.contrib.auth.models.User
) – The User object that must have access to any returned reviews.extra_query (
django.db.models.Q
, optional) – Additional query parameters to add for filtering down the resulting queryset.local_site (
reviewboard.site.models.LocalSite
or :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:``reviewboard.site.models.LocalSite.ALL
, optional) –A specific Local Site that the reviews must be associated with. It is assumed that the given user has access to the Local Site. By default, this will only return reviews not part of a site.
This may be
LocalSite.ALL
.public (
bool
orNone
, optional) – Whether to filter for public (published) reviews. If set toNone
, both published and unpublished reviews will be included.base_reply_to (
reviewboard.reviews.models.review.Review
, optional) – If provided, limit results to reviews that are part of the thread of replies to this review.distinct (
bool
, optional) –Whether to return distinct results.
Turning this on can decrease performance. It’s off by default.
- Returns:
The resulting queryset.
- Return type:
- get_pending_review(review_request, user)[source]¶
Return a user’s pending review on a review request.
This will handle fixing duplicate reviews if more than one pending review is found.
- Parameters:
review_request (
reviewboard.reviews.models.review_request.ReviewRequest
) – The review request being reviewed.user (
django.contrib.auth.models.User
) – The user making the review.
- Returns:
The pending review object.
- Return type:
- get_pending_reply(review, user)[source]¶
Return a user’s pending reply to a given review.
This will handle fixing duplicate reviews if more than one pending review reply is found.
- Parameters:
review (
reviewboard.reviews.models.review.Review
) – The review being replied to.user (
django.contrib.auth.models.User
) – The user making the reply.
- Returns:
The pending review object.
- Return type:
- fix_duplicate_reviews(reviews)[source]¶
Fix duplicate reviews, condensing them into a single review.
This will consolidate the data from all reviews into the first review in the list, and return the first review.
- Parameters:
reviews (
list
ofreviewboard.reviews.models.review.Review
) – The list of duplicate reviews.- Returns:
The first review in the list containing the consolidated data.
- Return type:
- from_user(user_or_username, *args, **kwargs)[source]¶
Return the query for reviews created by a user.
- Parameters:
user_or_username (
django.contrib.auth.models.User
orstr
) – The User object or username.*args (
tuple
) – Additional positional arguments to pass to the common_query()
function.**kwargs (
dict
) – Additional keyword arguments to pass to the common_query()
function.
- Returns:
A queryset for all the reviews created by the given user.
- Return type:
- __annotations__ = {}¶
- __slotnames__ = []¶
- class StatusUpdateManager(*args, **kwargs)[source]¶
Bases:
Manager
A manager for StatusUpdate models.
This offers conveniences around creating
StatusUpdate
models for custom integrations.New in version 5.0.3.
- create_for_integration(integration: Integration, *, config: IntegrationConfig, user: User, review_request: ReviewRequest, change_description: Optional[ChangeDescription] = None, service_id: Optional[str] = None, summary: Optional[str] = None, description: Optional[str] = None, state: Optional[str] = None, can_retry: bool = False, extra_data: Dict = {}, starting_description: str = 'starting...', waiting_description: str = 'waiting to run.', **kwargs) StatusUpdate [source]¶
Return a new status update for a given integration.
This helps with generating defaults for a status update, and putting it in the correct initial state when running manually.
The integration configuration will be associated with the status update, which is important for manually running integrations when multiple integrations are present on a review request.
- Parameters:
integration (
reviewboard.integrations.base.Integration
) – The integration that this status update will be associated with.config (
reviewboard.integrations.models.IntegrationConfig
) – The configuration for the integration, used to provide defaults and used for later manual runs.user (
django.contrib.auth.models.User
) – The user that the status update will be associated with.review_request (
reviewboard.reviews.models.review_request.ReviewRequest
) – The review request that the status update will be associated with.change_description (
reviewboard.changedescs.models.ChangeDescription
, optional) – The optional change description that the status update will be associated with.service_id (
str
, optional) –An explicit service ID for the status update.
If not provided (or if
None
), a slugified version of the integration’s name will be used.summary (
str
, optional) –An explicit summary for the status update.
If not provided (or if
None
), the integration name will be used.description (
str
, optional) –An explicit description for the status update.
If not provided (or if
None
), a standardized description will be used depending on whether the status update will be created in manual run mode.See
starting_description
andwaiting_description
to customize these strings.state (
str
, optional) –An explicit state for the status update.
If not provided (or if
None
), the state will be in Not Yet Run if creating in manual run mode, or Pending otherwise.can_retry (
bool
, optional) – Whether the status update can be retried after being run.extra_data (
dict
, optional) – Extra data to store in the status update.starting_description (
str
, optional) – The description to use if creating a status update that is immediately starting.waiting_description (
str
, optional) – The description to use if creating a status update that is in manual run mode.**kwargs (
dict
, optional) – Additional keyword arguments for the model.
- Returns:
The new status update.
- Return type:
reviewboard.reviews.status_update.StatusUpdate
- __annotations__ = {}¶
- __slotnames__ = []¶