Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor filter apply filter method #194

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 0 additions & 3 deletions search_events_app/filters/buyer_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,3 @@ def get_join_query(self):
') AS at ON at.event = dw_event.event_id'
]
return ['']

def get_where_query(self):
return ''
5 changes: 1 addition & 4 deletions search_events_app/filters/category_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class CategoryFilter(Filter):
def apply_filter(self, request):
category_code = request.GET.get('category', '')
category_code = request.GET.get('category')
new_filter = None
if category_code:
try:
Expand All @@ -17,9 +17,6 @@ def apply_filter(self, request):
if self.has_changed:
self.value = new_filter

def get_join_query(self):
return ['']

def get_where_query(self):
if self.value:
return f"AND dw_cat.event_category_desc = '{self.value.name}'"
Expand Down
7 changes: 2 additions & 5 deletions search_events_app/filters/city_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,18 @@ class CityFilter(Filter):

def apply_filter(self, request):
country_name = request.GET.get('country', '')
city_name = request.GET.get('city', '')
city_name = request.GET.get('city')
new_filter = None
if city_name:
try:
country = Country.objects.get(name=country_name)
new_filter = City.objects.get(name=city_name, country=country.alpha_2_code )
new_filter = City.objects.get(name=city_name, country=country.alpha_2_code)
except ObjectDoesNotExist:
new_filter = None
self.has_changed = new_filter != self.value
if self.has_changed:
self.value = new_filter

def get_join_query(self):
return ['']

def get_where_query(self):
if self.value:
if self.value.code:
Expand Down
3 changes: 0 additions & 3 deletions search_events_app/filters/country_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ def apply_filter(self, request):
if self.has_changed:
self.value = new_filter

def get_join_query(self):
return ['']

def get_where_query(self):
if self.value:
return f"AND country_desc='{self.value.alpha_2_code}'"
Expand Down
5 changes: 1 addition & 4 deletions search_events_app/filters/currency_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class CurrencyFilter(Filter):
def apply_filter(self, request):
currency_code = request.GET.get('currency', '')
currency_code = request.GET.get('currency')
new_filter = None
if currency_code:
try:
Expand All @@ -17,9 +17,6 @@ def apply_filter(self, request):
if self.has_changed:
self.value = new_filter

def get_join_query(self):
return ['']

def get_where_query(self):
if self.value:
return f"AND dw_event.event_currency = '{self.value.code}'"
Expand Down
5 changes: 1 addition & 4 deletions search_events_app/filters/event_name_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@

class EventNameFilter(Filter):
def apply_filter(self, request):
event_name = request.GET.get('event_name', '')
event_name = request.GET.get('event_name')
new_filter = None
if event_name:
new_filter = event_name
self.has_changed = new_filter != self.value
if self.has_changed:
self.value = new_filter

def get_join_query(self):
return ['']

def get_where_query(self):
if self.value:
return f"AND LOWER(dw_event.event_title) LIKE '%{self.value.lower().strip()}%'"
Expand Down
4 changes: 2 additions & 2 deletions search_events_app/filters/feature_filter_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ def __init__(self):
]

def apply_filter(self, request):
features_codes = request.GET.get('feature', '').split('-')
feature_codes = request.GET.get('feature', '').split('-')
for latest_filter in self.value:
latest_filter.apply_filter(features_codes)
latest_filter.apply_filter(feature_codes)
self.has_changed = len([latest_filter for latest_filter in self.value if latest_filter.has_changed]) > 0

def get_select_query(self):
Expand Down
10 changes: 2 additions & 8 deletions search_events_app/filters/features/add_ons_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,8 @@


class AddOnsFilter(Filter):
def apply_filter(self, features_codes):
new_filter = FeatureCodes.add_ons in features_codes
self.has_changed = new_filter != self.value
if self.has_changed:
self.value = new_filter

def get_join_query(self):
return ['']
def apply_filter(self, feature_codes):
super().apply_filter(FeatureCodes.add_ons, feature_codes)

def get_where_query(self):
if self.value:
Expand Down
11 changes: 2 additions & 9 deletions search_events_app/filters/features/custom_question_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,9 @@

class CustomQuestionFilter(Filter):
def apply_filter(self, feature_codes):
new_filter = FeatureCodes.custom_question in feature_codes
self.has_changed = new_filter != self.value
if self.has_changed:
self.value = new_filter
super().apply_filter(FeatureCodes.custom_question, feature_codes)

def get_join_query(self):
if self.value:
query = ['INNER JOIN eb.questions q ON q.asset = dw_event.event_id']
return query
return ['INNER JOIN eb.questions q ON q.asset = dw_event.event_id']
return ['']

def get_where_query(self):
return ''
8 changes: 1 addition & 7 deletions search_events_app/filters/features/donation_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@

class DonationFilter(Filter):
def apply_filter(self, feature_codes):
new_filter = FeatureCodes.donation in feature_codes
self.has_changed = new_filter != self.value
if self.has_changed:
self.value = new_filter

def get_join_query(self):
return ['']
super().apply_filter(FeatureCodes.donation, feature_codes)

def get_where_query(self):
if self.value:
Expand Down
10 changes: 2 additions & 8 deletions search_events_app/filters/features/eb_studio_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,8 @@


class EBStudioFilter(Filter):
def apply_filter(self, features_codes):
new_filter = FeatureCodes.eventbrite_studio in features_codes
self.has_changed = new_filter != self.value
if self.has_changed:
self.value = new_filter

def get_join_query(self):
return ['']
def apply_filter(self, feature_codes):
super().apply_filter(FeatureCodes.eventbrite_studio, feature_codes)

def get_where_query(self):
if self.value:
Expand Down
10 changes: 2 additions & 8 deletions search_events_app/filters/features/facebook_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@


class FacebookFilter(Filter):
def apply_filter(self, features_codes):
new_filter = FeatureCodes.facebook in features_codes
self.has_changed = new_filter != self.value
if self.has_changed:
self.value = new_filter
def apply_filter(self, feature_codes):
super().apply_filter(FeatureCodes.facebook, feature_codes)

def get_select_query(self):
if self.value:
Expand All @@ -24,9 +21,6 @@ def get_join_query(self):
]
return ['']

def get_where_query(self):
return ''

def get_group_query(self):
if self.value:
return ', fb.facebook_event_id'
Expand Down
10 changes: 2 additions & 8 deletions search_events_app/filters/features/group_registration_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@


class GroupRegistrationFilter(Filter):
def apply_filter(self, features_codes):
new_filter = FeatureCodes.group_registration in features_codes
self.has_changed = new_filter != self.value
if self.has_changed:
self.value = new_filter
def apply_filter(self, feature_codes):
super().apply_filter(FeatureCodes.group_registration, feature_codes)

def get_join_query(self):
if self.value:
Expand All @@ -18,6 +15,3 @@ def get_join_query(self):
') AS team ON dw_event.event_id = team.event_id'
]
return ['']

def get_where_query(self):
return ''
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,9 @@

class RepeatingEventsFilter(Filter):
def apply_filter(self, feature_codes):
new_filter = FeatureCodes.repeating_events in feature_codes
self.has_changed = new_filter != self.value
if self.has_changed:
self.value = new_filter

def get_join_query(self):
return ['']
super().apply_filter(FeatureCodes.repeating_events, feature_codes)

def get_where_query(self):
if self.value:
return "AND dw_event.is_repeating_event = 'Y'"
return ''

Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@

class ReservedSeatingFilter(Filter):
def apply_filter(self, feature_codes):
new_filter = FeatureCodes.reserved_seating in feature_codes
self.has_changed = new_filter != self.value
if self.has_changed:
self.value = new_filter

def get_join_query(self):
return ['']
super().apply_filter(FeatureCodes.reserved_seating, feature_codes)

def get_where_query(self):
if self.value:
Expand Down
8 changes: 1 addition & 7 deletions search_events_app/filters/features/wait_list_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@

class WaitlistFilter(Filter):
def apply_filter(self, feature_codes):
new_filter = FeatureCodes.wait_list in feature_codes
self.has_changed = new_filter != self.value
if self.has_changed:
self.value = new_filter
super().apply_filter(FeatureCodes.wait_list, feature_codes)

def get_join_query(self):
if self.value:
Expand All @@ -30,6 +27,3 @@ def get_join_query(self):
') AS waitlist ON waitlist.event = dw_event.event_id'
]
return ['']

def get_where_query(self):
return ''
7 changes: 2 additions & 5 deletions search_events_app/filters/features/website_widgets_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@


class WebsiteWidgetsFilter(Filter):
def apply_filter(self, features_codes):
new_filter = FeatureCodes.website_widgets in features_codes
self.has_changed = new_filter != self.value
if self.has_changed:
self.value = new_filter
def apply_filter(self, feature_codes):
super().apply_filter(FeatureCodes.website_widgets, feature_codes)

def get_join_query(self):
if self.value:
Expand Down
17 changes: 7 additions & 10 deletions search_events_app/filters/filter.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
from abc import abstractmethod


class Filter:

def __init__(self):
self.value = None
self.has_changed = False

@abstractmethod
def apply_filter(self, request):
pass
def apply_filter(self, code, feature_codes):
new_filter = code in feature_codes
self.has_changed = new_filter != self.value
if self.has_changed:
self.value = new_filter

def get_select_query(self):
return ''

@abstractmethod
def get_join_query(self):
pass
return ['']

@abstractmethod
def get_where_query(self):
pass
return ''

def get_group_query(self):
return ''
3 changes: 0 additions & 3 deletions search_events_app/filters/format_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ def get_value(self):
if self.value:
return self.value.name

def get_join_query(self):
return ['']

def get_where_query(self):
if self.value:
return f"AND dw_cat.event_format_desc='{self.value.name}'"
Expand Down
3 changes: 0 additions & 3 deletions search_events_app/filters/language_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ def apply_filter(self, request):
if self.has_changed:
self.value = new_filter

def get_join_query(self):
return ['']

def get_where_query(self):
if self.value:
return f"AND dw_event.event_language LIKE '%{self.value.code}_%'"
Expand Down
5 changes: 1 addition & 4 deletions search_events_app/filters/last_four_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
class LastFourFilter(Filter):

def apply_filter(self, request):
last_four = request.GET.get('card', '')
last_four = request.GET.get('card')
new_filter = None
if last_four:
new_filter = last_four
Expand All @@ -27,6 +27,3 @@ def get_join_query(self):
') AS o on o.event = dw_event.event_id'
]
return ['']

def get_where_query(self):
return ''
12 changes: 4 additions & 8 deletions search_events_app/filters/online_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,14 @@ class OnlineFilter(Filter):
def apply_filter(self, request):
online = request.GET.get('online')
new_filter = None
if online:
if online == 'on':
new_filter = OnlineParameters.ONLINE
elif online == 'off':
new_filter = OnlineParameters.OFFLINE
if online == 'on':
new_filter = OnlineParameters.ONLINE
elif online == 'off':
new_filter = OnlineParameters.OFFLINE
self.has_changed = new_filter != self.value
if self.has_changed:
self.value = new_filter

def get_join_query(self):
return ['']

def get_where_query(self):
if self.value:
return f"AND dw_event.online_flag='{self.value.get('query_value')}' "\
Expand Down
3 changes: 0 additions & 3 deletions search_events_app/filters/organizer_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ def apply_filter(self, request):
if self.has_changed:
self.value = new_filter

def get_join_query(self):
return ['']

def get_where_query(self):
if self.value:
return 'AND ('\
Expand Down
Loading