class PropertyAllValuesMultipleFilterSet(PropertyFilterSet):

    number_contains_and = AllValuesMultipleFilter(
        field_name='number',
        lookup_expr='contains',
        label='Number Contains <AND>',
        conjoined=True)
    prop_number_contains_and = PropertyAllValuesMultipleFilter(
        field_name='prop_number',
        lookup_expr='contains',
        label='Prop Number Contains <AND>',
        conjoined=True)

    class Meta:
        model = models.AllValuesMultipleFilterModel
        exclude = ['number']
        fields = ['number_contains_and', 'prop_number_contains_and']
        property_fields = [('prop_number', PropertyAllValuesMultipleFilter,
                            PropertyAllValuesMultipleFilter.supported_lookups)]

    def __init__(self, *args, **kwargs):
        add_supported_filters(
            self, AllValuesMultipleFilter, 'number',
            PropertyAllValuesMultipleFilter.supported_lookups)
        super().__init__(*args, **kwargs)
Exemple #2
0
class LDAPPropertyMappingFilter(FilterSet):
    """Filter for LDAPPropertyMapping"""

    managed = extend_schema_field(OpenApiTypes.STR)(
        AllValuesMultipleFilter(field_name="managed"))

    class Meta:
        model = LDAPPropertyMapping
        fields = "__all__"
Exemple #3
0
class ScopeMappingFilter(FilterSet):
    """Filter for ScopeMapping"""

    managed = extend_schema_field(OpenApiTypes.STR)(
        AllValuesMultipleFilter(field_name="managed"))

    class Meta:
        model = ScopeMapping
        fields = ["scope_name", "name", "managed"]
class MiscBooleanChoiceFiltersFilterSet(PropertyFilterSet):
    LOOKUP_CHOICES = [
        (True, 'Yes'),
        # (True, 'True'),
        # (True, 'GiveMeYes'),
        (False, 'No'),
        # (False, 'False'),
        # (False, 'GiveMeNo'),
    ]

    is_true_ChoiceFilter = ChoiceFilter(field_name='is_true',
                                        lookup_expr='exact',
                                        choices=LOOKUP_CHOICES)
    is_true_MultipleChoiceFilter = MultipleChoiceFilter(field_name='is_true',
                                                        lookup_expr='exact',
                                                        conjoined=False,
                                                        choices=LOOKUP_CHOICES)
    is_true_AllValuesFilter = AllValuesFilter(field_name='is_true',
                                              lookup_expr='exact')
    is_true_AllValuesMultipleFilter = AllValuesMultipleFilter(
        field_name='is_true', lookup_expr='exact', conjoined=False)
    # Typed Choice Filter might not have a blank option, skip
    #is_true_TypedChoiceFilter = TypedChoiceFilter(field_name='is_true', lookup_expr='exact', choices=LOOKUP_CHOICES, coerce=str)
    is_true_TypedMultipleChoiceFilter = TypedMultipleChoiceFilter(
        field_name='is_true',
        lookup_expr='exact',
        conjoined=False,
        choices=LOOKUP_CHOICES,
        coerce=str)

    prop_is_true_PropertyChoiceFilter = PropertyChoiceFilter(
        field_name='prop_is_true', lookup_expr='exact', choices=LOOKUP_CHOICES)
    prop_is_true_PropertyMultipleChoiceFilter = PropertyMultipleChoiceFilter(
        field_name='prop_is_true',
        lookup_expr='exact',
        conjoined=False,
        choices=LOOKUP_CHOICES)
    prop_is_true_PropertyAllValuesFilter = PropertyAllValuesFilter(
        field_name='prop_is_true', lookup_expr='exact')
    prop_is_true_PropertyAllValuesMultipleFilter = PropertyAllValuesMultipleFilter(
        field_name='prop_is_true', lookup_expr='exact', conjoined=False)
    # Typed Choice Filter might not have a blank option, skip
    #prop_is_true_PropertyTypedChoiceFilter = PropertyTypedChoiceFilter(field_name='prop_is_true', lookup_expr='exact', choices=LOOKUP_CHOICES, coerce=str)
    prop_is_true_PropertyTypedMultipleChoiceFilter = PropertyTypedMultipleChoiceFilter(
        field_name='prop_is_true',
        lookup_expr='exact',
        conjoined=False,
        choices=LOOKUP_CHOICES,
        coerce=str)

    class Meta:
        model = models.BooleanFilterModel
        exclude = ['is_true']
Exemple #5
0
class BundleFilter(FilterSet):
    """
    Filter for BundleViewSet.
    """
    uuid = AllValuesMultipleFilter(widget=CSVWidget)  # Accepts multiple comma-separated UUIDs
    text_search = CharFilter(method='search')

    def search(self, queryset, name, value):  # pylint: disable=unused-argument
        return queryset.filter(Q(title__icontains=value) | Q(description__icontains=value) | Q(slug__icontains=value))

    class Meta:
        model = Bundle
        fields = ('collection__uuid',)