-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #158 from ral-facilities/feature/icat-order-filter…
…-#140 Implement Order Filter for Python ICAT Backend
- Loading branch information
Showing
9 changed files
with
116 additions
and
79 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
class FilterOrderHandler(object): | ||
""" | ||
The FilterOrderHandler takes in filters, sorts them according to the order of | ||
operations, then applies them. | ||
""" | ||
|
||
def __init__(self): | ||
self.filters = [] | ||
|
||
def add_filter(self, filter): | ||
self.filters.append(filter) | ||
|
||
def add_filters(self, filters): | ||
self.filters.extend(filters) | ||
|
||
def sort_filters(self): | ||
""" | ||
Sorts the filters according to the order of operations | ||
""" | ||
self.filters.sort(key=lambda x: x.precedence) | ||
|
||
def apply_filters(self, query): | ||
""" | ||
Given a query apply the filters the handler has in the correct order. | ||
:param query: The query to have filters applied to | ||
""" | ||
self.sort_filters() | ||
|
||
for filter in self.filters: | ||
filter.apply_filter(query) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters