Skip to content

Commit

Permalink
#30: Create order handler
Browse files Browse the repository at this point in the history
  • Loading branch information
keiranjprice101 committed Aug 10, 2019
1 parent 70844ce commit bac726e
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions common/database_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,32 @@ def get_query_filter(filter):
raise BadFilterError(f" Bad filter: {filter}")


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 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)


def insert_row_into_table(table, row):
"""
Insert the given row into its table
Expand Down

0 comments on commit bac726e

Please sign in to comment.