Skip to content
This repository has been archived by the owner on Apr 22, 2024. It is now read-only.

fix(kernel): improve API filters #744

Merged
merged 2 commits into from
Dec 11, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions aether-kernel/aether/kernel/api/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,16 @@ class Meta:


class AttachmentFilter(filters.FilterSet):
project = filters.CharFilter(
method='project_filter',
)

def project_filter(self, queryset, name, value):
if is_uuid(value):
return queryset.filter(submission__project__pk=value)
else:
return queryset.filter(submission__project__name=value)

class Meta:
exclude = ('attachment_file',)
model = models.Attachment
Expand Down Expand Up @@ -180,7 +190,7 @@ class EntityFilter(filters.FilterSet):
method='mapping_filter',
)
family = filters.CharFilter(
field_name='schemadecorator__schema__family',
field_name='schema__family',
lookup_expr='iexact', # case-insensitive
)
passthrough = filters.CharFilter(
Expand All @@ -195,9 +205,9 @@ def project_filter(self, queryset, name, value):

def schema_filter(self, queryset, name, value):
if is_uuid(value):
return queryset.filter(schemadecorator__schema__pk=value)
return queryset.filter(schema__pk=value)
else:
return queryset.filter(schemadecorator__schema__name=value)
return queryset.filter(schema__name=value)

def mapping_filter(self, queryset, name, value):
if is_uuid(value):
Expand All @@ -208,7 +218,7 @@ def mapping_filter(self, queryset, name, value):
def passthrough__filter(self, queryset, name, value):
if value == 'true':
return queryset.filter(
schemadecorator__schema__family=Cast('project__pk', TextField()),
schema__family=Cast('project__pk', TextField()),
mapping__is_read_only=True,
)
return queryset
Expand Down