Beispiel #1
0
class CostModelsFilter(FilterSet):
    """Cost model custom filters."""

    name = CharFilter(field_name="name", method="list_contain_filter")
    uuid = UUIDFilter(field_name="uuid")
    source_uuid = UUIDFilter(field_name="costmodelmap__provider_uuid")
    description = CharFilter(field_name="description", lookup_expr="icontains")
    source_type = CharListFilter(field_name="source_type",
                                 lookup_expr="source_type__iexact")
    currency = CharListFilter(field_name="currency", method="currency_filter")

    def currency_filter(self, qs, name, values):
        """Filter currency if a valid currency is passed in"""
        serializer = CostModelSerializer(qs)
        if serializer.validate_currency(values[0]):
            lookup = "__".join([name, "iexact"])
            queries = [Q(**{lookup: val}) for val in values]
            return qs.filter(reduce(and_, queries))

    def list_contain_filter(self, qs, name, values):
        """Filter items that contain values in their name."""
        lookup = "__".join([name, "icontains"])
        value_list = values.split(",")
        queries = [Q(**{lookup: val}) for val in value_list]
        return qs.filter(reduce(and_, queries))

    class Meta:
        model = CostModel
        fields = [
            "source_type", "name", "source_uuid", "description", "currency"
        ]
Beispiel #2
0
    class PropertyUUIDFilterSet(PropertyFilterSet):
        uuid = UUIDFilter(field_name='uuid', lookup_expr=lookup_xpr)
        prop_uuid = PropertyUUIDFilter(field_name='prop_uuid', lookup_expr=lookup_xpr)

        class Meta:
            model = UUIDFilterModel
            fields = ['prop_uuid']
Beispiel #3
0
class AllFiltersFilterSet(FilterSet):
    number_AllValuesFilter = AllValuesFilter(field_name='number', lookup_expr='exact')
    number_AllValuesMultipleFilter_OR = AllValuesMultipleFilter(field_name='number', lookup_expr='exact', conjoined=False)  # OR
    number_AllValuesMultipleFilter_AND = AllValuesMultipleFilter(field_name='number', lookup_expr='exact', conjoined=True)  # AND
    number_BaseCSVFilterNumber = BaseCSVFilterNumber(field_name='number', lookup_expr='in')
    number_BaseInFilterNumber = BaseInFilterNumber(field_name='number', lookup_expr='in')
    number_BaseRangeFilterNumber = BaseRangeFilterNumber(field_name='number', lookup_expr='range')
    is_true_BooleanFilter = BooleanFilter(field_name='is_true', lookup_expr='exact')
    text_CharFilter = CharFilter(field_name='text', lookup_expr='exact')
    number_ChoiceFilter = ChoiceFilter(field_name='number', lookup_expr='exact', choices=NUMBER_CHOICES)
    date_DateFilter = DateFilter(field_name='date', lookup_expr='exact')
    date_DateFromToRangeFilter = DateFromToRangeFilter(field_name='date', lookup_expr='range')
    date_DateRangeFilter = DateRangeFilter(field_name='date', lookup_expr='exact')
    date_time_DateTimeFilter = DateTimeFilter(field_name='date_time', lookup_expr='exact')
    date_time_DateTimeFromToRangeFilter = DateTimeFromToRangeFilter(field_name='date_time', lookup_expr='range')
    duration_DurationFilter = DurationFilter(field_name='duration', lookup_expr='exact')
    iso_date_time_IsoDateTimeFilter = IsoDateTimeFilter(field_name='iso_date_time', lookup_expr='lt')
    iso_date_time_IsoDateTimeFromToRangeFilter = IsoDateTimeFromToRangeFilter(field_name='iso_date_time', lookup_expr='range')
    number_MultipleChoiceFilter_OR = MultipleChoiceFilter(field_name='number', lookup_expr='exact', conjoined=False, choices=NUMBER_CHOICES)
    number_MultipleChoiceFilter_AND = MultipleChoiceFilter(field_name='number', lookup_expr='exact', conjoined=True, choices=NUMBER_CHOICES)
    number_NumberFilter = NumberFilter(field_name='number', lookup_expr='exact')
    number_OrderingFilter = OrderingFilter(fields=('number', 'number'))
    number_RangeFilter = RangeFilter(field_name='number', lookup_expr='range')
    time_TimeFilter = TimeFilter(field_name='time', lookup_expr='exact')
    time_TimeRangeFilter = TimeRangeFilter(field_name='time', lookup_expr='range')
    number_TypedChoiceFilter = TypedChoiceFilter(field_name='number', lookup_expr='exact', choices=NUMBER_CHOICES)
    text_TypedMultipleChoiceFilter_OR = TypedMultipleChoiceFilter(field_name='number', lookup_expr='exact', conjoined=False, choices=NUMBER_CHOICES)
    text_TypedMultipleChoiceFilter_AND = TypedMultipleChoiceFilter(field_name='number', lookup_expr='exact', conjoined=True, choices=NUMBER_CHOICES)
    uuid_UUIDFilter = UUIDFilter(field_name='uuid', lookup_expr='exact')
    number_LookupChoiceFilter = LookupChoiceFilter(field_name='number')

    class Meta:
        model = BenchmarkModel
        exclude = ['number', 'text', 'is_true', 'date', 'date_time', 'duration']
Beispiel #4
0
class CostModelsFilter(FilterSet):
    """Cost model custom filters."""

    name = CharFilter(field_name='name', method='list_contain_filter')
    uuid = UUIDFilter(field_name='uuid')
    provider_uuid = UUIDFilter(field_name='costmodelmap__provider_uuid')

    def list_contain_filter(self, qs, name, values):
        """Filter items that contain values in their name."""
        lookup = '__'.join([name, 'icontains'])
        value_list = values.split(',')
        queries = [Q(**{lookup: val}) for val in value_list]
        return qs.filter(reduce(and_, queries))

    class Meta:
        model = CostModel
        fields = ['source_type', 'name', 'provider_uuid']
Beispiel #5
0
class BookingResourceFilter(ResourceFilter):
    o = SchedulesOrderingFilter(fields=('name', 'created', 'type'))
    connected_customer_uuid = UUIDFilter(method='filter_connected_customer')

    def filter_connected_customer(self, queryset, name, value):
        return queryset.filter(
            Q(project__customer__uuid=value, )
            | Q(offering__customer__uuid=value, ))
Beispiel #6
0
class CostModelsFilter(FilterSet):
    """Cost model custom filters."""

    name = CharFilter(field_name="name", method="list_contain_filter")
    uuid = UUIDFilter(field_name="uuid")
    provider_uuid = UUIDFilter(field_name="costmodelmap__provider_uuid")
    description = CharFilter(field_name="description", lookup_expr="icontains")
    source_type = CharListFilter(field_name="source_type",
                                 lookup_expr="source_type__iexact")

    def list_contain_filter(self, qs, name, values):
        """Filter items that contain values in their name."""
        lookup = "__".join([name, "icontains"])
        value_list = values.split(",")
        queries = [Q(**{lookup: val}) for val in value_list]
        return qs.filter(reduce(and_, queries))

    class Meta:
        model = CostModel
        fields = ["source_type", "name", "provider_uuid", "description"]
Beispiel #7
0
class ArticlesFilter(rest_framework.FilterSet):
    uid = UUIDFilter(field_name="author__uid", help_text='作者uid')
    tagId = CharFilter(field_name='article2tag__tag__id', help_text='标签id')
    category = CharFilter(field_name='category', help_text='个人文章分类')
    web_category = CharFilter(field_name='web_category', help_text='网站分类,只能查子级分类')
    webCategoryId = CharFilter(method='category_filer', help_text='网站分类,子级和父级分类都能查')

    # 网站分类的父级和子级均可过滤
    def category_filer(self, queryset, name, value):
        return queryset.filter(Q(web_category=value) | Q(web_category__parent_category=value))

    class Meta:
        model = Article
        fields = ()
Beispiel #8
0
class SourceFilter(FilterSet):
    """Source custom filters."""

    name = CharListFilter(field_name="name", lookup_expr="name__icontains")
    type = CharListFilter(field_name="source_type",
                          lookup_expr="source_type__icontains")
    account_id = CharListFilter(field_name="account_id",
                                lookup_expr="account_id__icontains")
    schema_name = CharListFilter(
        field_name="provider__customer__schema_name",
        lookup_expr="provider__customer__schema_name__icontains")
    ocp_on_cloud = BooleanFilter(field_name="provider__infrastructure_id",
                                 lookup_expr="isnull",
                                 exclude=True)
    infrastructure_provider_id = UUIDFilter(
        field_name="provider__infrastructure__infrastructure_provider_id")
    cluster_id = CharListFilter(
        field_name="authentication__credentials__cluster_id",
        lookup_expr="authentication__credentials__cluster_id__icontains",
    )
    active = BooleanFilter(field_name="provider__active")
    paused = BooleanFilter(field_name="provider__paused")
    pending_delete = BooleanFilter(field_name="pending_delete")
    pending_update = BooleanFilter(field_name="pending_update")
    out_of_order_delete = BooleanFilter(field_name="out_of_order_delete")

    class Meta:
        model = Sources
        fields = [
            "source_type",
            "name",
            "account_id",
            "schema_name",
            "ocp_on_cloud",
            "infrastructure_provider_id",
            "cluster_id",
            "active",
            "paused",
            "pending_delete",
            "pending_update",
            "out_of_order_delete",
        ]
Beispiel #9
0
    class UUIDFilterSet(FilterSet):
        uuid = UUIDFilter(field_name='uuid', lookup_expr=lookup_xpr)

        class Meta:
            model = UUIDFilterModel
            fields = ['uuid']
Beispiel #10
0
class TagFilter(rest_framework.FilterSet):
    uid = UUIDFilter(field_name="blog__user_blog__uid")

    class Meta:
        model = Tag
        fields = ('uid',)