Skip to content

Commit

Permalink
#140: Basic implementation of ICAT order filter
Browse files Browse the repository at this point in the history
- If there's more than one order filter in a request, the others get overwritten due to the way setOrder() works in Python ICAT
  • Loading branch information
MRichards99 committed Aug 18, 2020
1 parent 78ef98e commit 578ac21
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions common/icat/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,22 @@ def apply_filter(self, query):

class PythonICATOrderFilter(OrderFilter):
def __init__(self, field, direction):
super().__init__(field, direction)
# Python ICAT doesn't automatically uppercase the direction, errors otherwise
super().__init__(field, direction.upper())

def apply_filter(self, query):
pass
result_order = [(self.field, self.direction)]
log.debug("Result Order: %s", result_order)

try:
log.info("Adding order filter")
query.setOrder(PythonICATOrderFilter.result_order)
except ValueError:
raise FilterError(
"Order Filter Error: Either an invalid attribute(s) or attribute(s)"
" contains 1-many relationship"
)



class PythonICATSkipFilter(SkipFilter):
Expand Down

0 comments on commit 578ac21

Please sign in to comment.