Exemplo n.º 1
0
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
Exemplo n.º 2
0
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
Exemplo n.º 3
0
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
Exemplo n.º 4
0
class BaseConditionModelMultipleChoice(ModelQueryChoiceMixin,
                                       BaseConditionChoice):
    """Base class for a standard multi-model-based condition choice.

    This is a convenience for choices that are based on comparing against
    multiple instances of models. It provides some standard operators that work
    well with comparing sets of models.

    Subclasses should provide a :py:attr:`queryset` attribute, or override
    :py:meth:`get_queryset` to provide a more dynamic queryset.
    """

    operators = ConditionOperators([
        AnyOperator.with_overrides(name=_('Any')),
        UnsetOperator.with_overrides(name=_('None')),
        IsOneOfOperator,
        IsNotOneOfOperator,
    ])

    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 ConditionValueMultipleModelField(queryset=self.get_queryset)
Exemplo n.º 5
0
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