Skip to content

Commit

Permalink
add filters
Browse files Browse the repository at this point in the history
  • Loading branch information
jhnnsrs committed Jan 31, 2024
1 parent 620a5c8 commit d8db06d
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 5 deletions.
8 changes: 5 additions & 3 deletions bridge/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

@strawberry.input
class IDFilterMixin:
ids: list[strawberry.ID] | None
ids: list[strawberry.ID] | None = None

def filter_ids(self, queryset, info):
if self.ids is None:
Expand All @@ -18,7 +18,7 @@ def filter_ids(self, queryset, info):

@strawberry.input
class SearchFilterMixin:
search: str | None
search: str | None = None

def filter_search(self, queryset, info):
if self.search is None:
Expand All @@ -30,7 +30,9 @@ def filter_search(self, queryset, info):


@strawberry.input
class ProjectFilter(IDFilterMixin, SearchFilterMixin):
class ProjectFilter:
ids: list[strawberry.ID] | None = None
search: str | None = None
pass

@strawberry.input
Expand Down
13 changes: 13 additions & 0 deletions bridge/queries/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,20 @@
import strawberry

def datasets(filters: filters.DatasetFilter | None = None, pagination: pagination.OffsetPaginationInput | None = None) -> types.Dataset:

x = get_conn().listDatasets()

if filters:
if filters.ids:
x = [y for y in x if str(y.getId()) in filters.ids]
print(x.getID() for x in x)
if filters.search:
x = [y for y in x if filters.search in y.getName()]

if pagination:
x = x[pagination.offset : pagination.offset + pagination.limit]


return [types.Dataset(value=y) for y in x]


Expand Down
12 changes: 12 additions & 0 deletions bridge/queries/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@

def images(filters: filters.ImageFilter | None = None, pagination: pagination.OffsetPaginationInput | None = None) -> types.Image:
x = get_conn().listImages()

if filters:
if filters.ids:
x = [y for y in x if str(y.getId()) in filters.ids]
print(x.getID() for x in x)
if filters.search:
x = [y for y in x if filters.search in y.getName()]

if pagination:
x = x[pagination.offset : pagination.offset + pagination.limit]


return [types.Image(value=y) for y in x]


Expand Down
11 changes: 11 additions & 0 deletions bridge/queries/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@

def projects(filters: filters.ProjectFilter | None = None, pagination: pagination.OffsetPaginationInput | None = None) -> types.Project:
x = get_conn().listProjects()

if filters:
if filters.ids:
x = [y for y in x if str(y.getId()) in filters.ids]
print(x.getID() for x in x)
if filters.search:
x = [y for y in x if filters.search in y.getName()]

if pagination:
x = x[pagination.offset : pagination.offset + pagination.limit]

return [types.Project(value=y) for y in x]


Expand Down
6 changes: 4 additions & 2 deletions bridge/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,12 @@ def render_thumbnail(request, id):
@param request: http request
@param iid: Image ID
"""
print(request)

size = request.GET.get("size", 200)

jpeg_data = _render_thumbnail(
id=id,
size=request.GET.get("size", (200,))
size=(size,)
)
rsp = HttpResponse(jpeg_data, content_type="image/jpeg")
return rsp
Expand Down

0 comments on commit d8db06d

Please sign in to comment.