class MyChoice(BaseConditionChoice): operators = ConditionOperators([ MyOperator, ]) def default_value_field(self, **kwargs): return _my_value_field
class ReviewRequestOwnerChoice(LocalSiteModelChoiceMixin, ReviewRequestConditionChoiceMixin, BaseConditionModelMultipleChoice): """A condition choice for matching a review request's owner.""" queryset = User.objects.all() choice_id = 'owner' name = _('Owner') operators = ConditionOperators([ IsOneOfOperator, IsNotOneOfOperator, ]) def get_match_value(self, review_request, **kwargs): """Return the owner used for matching. Args: review_request (reviewboard.reviews.models.review_request. ReviewRequest): The provided review request. **kwargs (dict): Unused keyword arguments. Returns: django.contrib.auth.models.User: The review request's owner. """ return review_request.owner
class BaseConditionModelChoice(ModelQueryChoiceMixin, BaseConditionChoice): """Base class for a standard model-based condition choice. This is a convenience for choices that are based on a single model. It provides some standard operators that work well with comparing models. Subclasses should provide a :py:attr:`queryset` attribute, or override :py:meth:`get_queryset` to provide a more dynamic queryset. """ operators = ConditionOperators([ UnsetOperator, IsOperator, IsNotOperator, ]) def default_value_field(self, **kwargs): """Return the default value field for this choice. This will call out to :py:meth:`get_queryset` before returning the field, allowing subclasses to simply set :py:attr:`queryset` or to perform more dynamic queries before constructing the form field. Args: **kwargs (dict): Extra keyword arguments for this function, for future expansion. Returns: djblets.conditions.values.ConditionValueMultipleModelField: The form field for the value. """ return ConditionValueModelField(queryset=self.get_queryset)
class ReviewRequestParticipantChoice(LocalSiteModelChoiceMixin, ReviewRequestConditionChoiceMixin, BaseConditionModelMultipleChoice): """A condition choice for matching a review request's participant.""" queryset = User.objects.all() choice_id = 'participant' name = _('Participant') operators = ConditionOperators([ ContainsAnyOperator, DoesNotContainAnyOperator, ]) def get_match_value(self, review_request, **kwargs): """Return the participants used for matching. Args: review_request (reviewboard.reviews.models.review_request. ReviewRequest): The provided review request. **kwargs (dict, unused): Unused keyword arguments. Returns: set of django.contrib.auth.models.User: The review request's participants. """ return review_request.review_participants
class RepositoriesChoice(RepositoryConditionChoiceMixin, BaseConditionModelMultipleChoice): """A condition choice for matching repositories. This is used to match a :py:class:`~reviewboard.scmtools.models.Repository` against a list of repositories, against no repository (``None``), or against a repository public/private state. """ choice_id = 'repository' name = _('Repository') operators = ConditionOperators([ AnyOperator.with_overrides(name=_('Any repository')), UnsetOperator.with_overrides(name=_('No repository')), IsOneOfOperator, IsNotOneOfOperator, IsRepositoryPublicOperator, IsRepositoryPrivateOperator, ]) def get_queryset(self): """Return the queryset used to look up repository choices. Returns: django.db.models.query.QuerySet: The queryset for repositories. """ request = self.extra_state['request'] if 'local_site' in self.extra_state: local_site = self.extra_state['local_site'] show_all_local_sites = False else: local_site = None show_all_local_sites = True return Repository.objects.accessible( user=request.user, local_site=local_site, show_all_local_sites=show_all_local_sites) def get_match_value(self, repository, **kwargs): """Return the value used for matching. This will return the provided repository directly. Args: repository (reviewboard.scmtools.models.Repository): The provided repository. **kwargs (dict): Unused keyword arguments. Returns: reviewboard.scmtools.models.Repository: The provided repository. """ return repository
class BaseConditionBooleanChoice(BaseConditionChoice): """Base class for a standard boolean-based condition choice. This is a convenience for choices that cover boolean values. """ operators = ConditionOperators([ IsOperator, ]) default_value_field = ConditionValueBooleanField()
class BaseConditionRequiredModelChoice(BaseConditionModelChoice): """Base class for a model-based condition that requires a value. This is simply a variation on :py:class:`BaseConditionModelChoice` that doesn't include a :py:class:`~djblets.conditions.operators.UnsetOperator`. """ operators = ConditionOperators([ IsOperator, IsNotOperator, ])
class BaseConditionIntegerChoice(BaseConditionChoice): """Base class for a standard integer-based condition choice. This is a convenience for choices that are based on integers. It provides some standard operators that work well with integers for checking. """ operators = ConditionOperators([ IsOperator, IsNotOperator, GreaterThanOperator, LessThanOperator, ]) default_value_field = ConditionValueIntegerField()
class ReviewGroupsChoice(LocalSiteModelChoiceMixin, BaseConditionModelMultipleChoice): """A condition choice for matching review groups. This is used to match a :py:class:`~reviewboard.reviews.models.group.Group` against a list of groups, against no group (empty list), or against a group's public/invite-only state. """ queryset = Group.objects.all() choice_id = 'review-groups' name = _('Review groups') value_kwarg = 'review_groups' operators = ConditionOperators([ AnyOperator.with_overrides(name=_('Any review groups')), UnsetOperator.with_overrides(name=_('No review groups')), ContainsAnyOperator, DoesNotContainAnyOperator, AnyReviewGroupsPublicOperator, AllReviewGroupsInviteOnlyOperator, ]) def get_match_value(self, review_groups, value_state_cache, **kwargs): """Return the review groups used for matching. Args: review_groups (django.db.models.query.QuerySet): The provided queryset for review groups. **kwargs (dict): Unused keyword arguments. Returns: list of reviewboard.reviews.models.group.Group: The list of review groups. """ try: result = value_state_cache['review_groups'] except KeyError: result = list(review_groups.all()) value_state_cache['review_groups'] = result return result
class BaseConditionStringChoice(BaseConditionChoice): """Base class for a standard string-based condition choice. This is a convenience for choices that are based on strings. It provides some standard operators that work well with strings for checking. """ operators = ConditionOperators([ IsOperator, IsNotOperator, ContainsOperator, DoesNotContainOperator, StartsWithOperator, EndsWithOperator, MatchesRegexOperator, DoesNotMatchRegexOperator, ]) default_value_field = ConditionValueCharField()
class RepositoriesChoice(LocalSiteModelChoiceMixin, RepositoryConditionChoiceMixin, BaseConditionModelMultipleChoice): """A condition choice for matching repositories. This is used to match a :py:class:`~reviewboard.scmtools.models.Repository` against a list of repositories, against no repository (``None``), or against a repository public/private state. """ queryset = Repository.objects.all() choice_id = 'repository' name = _('Repository') operators = ConditionOperators([ AnyOperator.with_overrides(name=_('Any repository')), UnsetOperator.with_overrides(name=_('No repository')), IsOneOfOperator, IsNotOneOfOperator, IsRepositoryPublicOperator, IsRepositoryPrivateOperator, ]) def get_match_value(self, repository, **kwargs): """Return the value used for matching. This will return the provided repository directly. Args: repository (reviewboard.scmtools.models.Repository): The provided repository. **kwargs (dict): Unused keyword arguments. Returns: reviewboard.scmtools.models.Repository: The provided repository. """ return repository
class RepositoryTypeChoice(RepositoryConditionChoiceMixin, BaseConditionModelMultipleChoice): """A condition choice for matching repository types. This is used to match a :py:ref:`~reviewboard.scmtools.models.Repository` of a certain type (based on the :py:class:`~reviewboard.scmtools.models.Tool`). """ queryset = Tool.objects.all() choice_id = 'repository_type' name = _('Repository type') operators = ConditionOperators([ IsOneOfOperator, IsNotOneOfOperator, ]) def get_match_value(self, repository, **kwargs): """Return the value used for matching. This will return the :py:class:`~reviewboard.scmtools.models.Tool` for the provided repository. Args: repository (reviewboard.scmtools.models.Repository): The provided repository. **kwargs (dict): Unused keyword arguments. Returns: reviewboard.scmtools.models.Tool: The repository's tool. """ if repository: return repository.tool else: return None
def test_get_operator_with_invalid_id(self): """Testing ConditionOperators.get_operator with invalid ID""" operators = ConditionOperators() with self.assertRaises(ConditionOperatorNotFoundError): operators.get_operator('invalid', None)
class MyChoice(BaseConditionChoice): operators = ConditionOperators([MyOperator1])
class EqualsTestChoice(BaseConditionChoice): choice_id = 'equals-test-choice' operators = ConditionOperators([EqualsTestOperator]) default_value_field = ConditionValueFormField(forms.CharField())
def test_get_operator_with_invalid_id(self): """Testing ConditionOperators.get_operator with invalid ID""" operators = ConditionOperators() with self.assertRaises(ConditionOperatorNotFoundError): operators.get_operator('invalid', None)
class MyChoice(BaseConditionChoice): choice_id = 'my-choice' operators = ConditionOperators([BooleanTestOperator]) default_value_field = ConditionValueFormField(forms.CharField())
class MyChoice2(BaseConditionChoice): choice_id = 'my-choice-2' name = 'My Choice 2' operators = ConditionOperators([MyOperator3])
class MyChoice1(BaseConditionChoice): choice_id = 'my-choice-1' name = 'My Choice 1' operators = ConditionOperators([MyOperator1, MyOperator2])
class BasicTestChoice(BaseConditionChoice): choice_id = 'basic-test-choice' operators = ConditionOperators([BasicTestOperator]) default_value_field = ConditionValueFormField(forms.CharField())
class MyChoice(BaseConditionChoice): choice_id = 'my-choice' name = 'My Choice' operators = ConditionOperators([MyOperator])
class ReviewGroupsChoice(BaseConditionModelMultipleChoice): """A condition choice for matching review groups. This is used to match a :py:class:`~reviewboard.reviews.models.group.Group` against a list of groups, against no group (empty list), or against a group's public/invite-only state. """ choice_id = 'review-groups' name = _('Review groups') value_kwarg = 'review_groups' operators = ConditionOperators([ AnyOperator.with_overrides(name=_('Any review groups')), UnsetOperator.with_overrides(name=_('No review groups')), ContainsAnyOperator, DoesNotContainAnyOperator, AnyReviewGroupsPublicOperator, AllReviewGroupsInviteOnlyOperator, ]) def get_queryset(self): """Return the queryset used to look up review group choices. Returns: django.db.models.query.QuerySet: The queryset for review groups. """ if self.extra_state.get('matching'): return (Group.objects.filter( local_site=self.extra_state['local_site'])) else: request = self.extra_state.get('request') assert request is not None if 'local_site' in self.extra_state: local_site = self.extra_state['local_site'] show_all_local_sites = False else: local_site = None show_all_local_sites = True return Group.objects.accessible( user=request.user, local_site=local_site, show_all_local_sites=show_all_local_sites) def get_match_value(self, review_groups, value_state_cache, **kwargs): """Return the review groups used for matching. Args: review_groups (django.db.models.query.QuerySet): The provided queryset for review groups. **kwargs (dict): Unused keyword arguments. Returns: list of reviewboard.reviews.models.group.Group: The list of review groups. """ try: result = value_state_cache['review_groups'] except KeyError: result = list(review_groups.all()) value_state_cache['review_groups'] = result return result
class MyChoice(BaseConditionChoice): operators = ConditionOperators([ MyOperator, ]) default_value_field = BaseConditionValueField()
class MyChoice(BaseConditionChoice): choice_id = 'my-choice' operators = ConditionOperators([BasicTestOperator])