コード例 #1
0
ファイル: view.py プロジェクト: project-koku/koku
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"
        ]
コード例 #2
0
ファイル: view.py プロジェクト: lcouzens/koku
class ProviderFilter(FilterSet):
    """Provider custom filters."""

    name = CharListFilter(field_name="name", lookup_expr="name__icontains")
    type = CharListFilter(field_name="type", lookup_expr="type__iexact")

    class Meta:
        model = Provider
        fields = ["type", "name"]
コード例 #3
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__iexact")

    class Meta:
        model = Sources
        fields = ["source_type", "name"]
コード例 #4
0
class ProviderFilter(FilterSet):
    """Provider custom filters."""

    name = CharListFilter(field_name='name', lookup_expr='name__icontains')
    type = CharListFilter(field_name='type', lookup_expr='type__iexact')

    class Meta:
        model = Provider
        fields = ['type', 'name']
コード例 #5
0
ファイル: views.py プロジェクト: project-koku/koku
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",
        ]
コード例 #6
0
ファイル: view.py プロジェクト: lcouzens/koku
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"]
コード例 #7
0
ファイル: view.py プロジェクト: coskunbalta/koku
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',
        ]