Merge branch 'feature/reformat-filter-requests' into develop
This commit is contained in:
commit
df00ceaa02
|
|
@ -78,9 +78,30 @@ class FiltersTagCategoryViewSet(mixins.ListModelMixin, viewsets.GenericViewSet):
|
|||
result_list = serializer.data
|
||||
query_params = request.query_params
|
||||
|
||||
params_type = query_params['type']
|
||||
params_type = query_params.get('type')
|
||||
if query_params.get('establishment_type'):
|
||||
params_type = query_params.get('establishment_type')
|
||||
elif query_params.get('product_type'):
|
||||
params_type = query_params.get('product_type')
|
||||
|
||||
if params_type == 'restaurant' and 'toque_number__in' in query_params:
|
||||
week_days = ("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday")
|
||||
flags = ('toque_number', 'wine_region', 'works_noon', 'works_evening', 'works_now', 'works_at_weekday')
|
||||
filter_flags = {flag_name: False for flag_name in flags}
|
||||
additional_flags = []
|
||||
|
||||
if params_type == 'restaurant':
|
||||
additional_flags += ['toque_number', 'works_noon', 'works_evening', 'works_now']
|
||||
|
||||
elif params_type == 'winery':
|
||||
additional_flags += ['wine_region']
|
||||
|
||||
elif params_type == 'artisan':
|
||||
additional_flags += ['works_now', 'works_at_weekday']
|
||||
|
||||
for flag_name in additional_flags:
|
||||
filter_flags[flag_name] = True
|
||||
|
||||
if filter_flags['toque_number']:
|
||||
toques = {
|
||||
"index_name": "toque_number",
|
||||
"label_translated": "Toques",
|
||||
|
|
@ -93,28 +114,29 @@ class FiltersTagCategoryViewSet(mixins.ListModelMixin, viewsets.GenericViewSet):
|
|||
}
|
||||
result_list.append(toques)
|
||||
|
||||
if params_type == 'winery' and 'wine_region_id__in' in query_params:
|
||||
try:
|
||||
wine_region_id = int(query_params['wine_region_id__in'])
|
||||
if filter_flags['wine_region']:
|
||||
wine_region_id = query_params.get('wine_region_id__in')
|
||||
|
||||
wine_regions = {
|
||||
"index_name": "wine_region",
|
||||
"label_translated": "Wine region",
|
||||
"param_name": "wine_region_id__in",
|
||||
"filters": [{
|
||||
"id": obj.id,
|
||||
"index_name": obj.name.lower().replace(' ', '_'),
|
||||
"label_translated": obj.name
|
||||
} for obj in WineRegion.objects.filter(id=wine_region_id)]
|
||||
}
|
||||
if str(wine_region_id).isdigit():
|
||||
queryset = WineRegion.objects.filter(id=int(wine_region_id))
|
||||
|
||||
result_list.append(wine_regions)
|
||||
else:
|
||||
queryset = WineRegion.objects.all()
|
||||
|
||||
except ValueError:
|
||||
pass
|
||||
wine_regions = {
|
||||
"index_name": "wine_region",
|
||||
"label_translated": "Wine region",
|
||||
"param_name": "wine_region_id__in",
|
||||
"filters": [{
|
||||
"id": obj.id,
|
||||
"index_name": obj.name.lower().replace(' ', '_'),
|
||||
"label_translated": obj.name
|
||||
} for obj in queryset]
|
||||
}
|
||||
|
||||
if params_type == 'restaurant' and 'works_noon__in' in query_params:
|
||||
week_days = ("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday")
|
||||
result_list.append(wine_regions)
|
||||
|
||||
if filter_flags['works_noon']:
|
||||
works_noon = {
|
||||
"index_name": "works_noon",
|
||||
"label_translated": "Open noon",
|
||||
|
|
@ -127,8 +149,8 @@ class FiltersTagCategoryViewSet(mixins.ListModelMixin, viewsets.GenericViewSet):
|
|||
}
|
||||
result_list.append(works_noon)
|
||||
|
||||
if params_type == 'restaurant' and 'works_evening__in' in query_params:
|
||||
week_days = ("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday")
|
||||
if filter_flags['works_evening']:
|
||||
|
||||
works_evening = {
|
||||
"index_name": "works_evening",
|
||||
"label_translated": "Open evening",
|
||||
|
|
@ -141,7 +163,7 @@ class FiltersTagCategoryViewSet(mixins.ListModelMixin, viewsets.GenericViewSet):
|
|||
}
|
||||
result_list.append(works_evening)
|
||||
|
||||
if params_type in ('restaurant', 'artisan') and 'works_now' in query_params:
|
||||
if filter_flags['works_now']:
|
||||
works_now = {
|
||||
"index_name": "open_now",
|
||||
"label_translated": "Open now",
|
||||
|
|
@ -150,6 +172,19 @@ class FiltersTagCategoryViewSet(mixins.ListModelMixin, viewsets.GenericViewSet):
|
|||
}
|
||||
result_list.append(works_now)
|
||||
|
||||
if filter_flags['works_at_weekday']:
|
||||
works_at_weekday = {
|
||||
"index_name": "works_at_weekday",
|
||||
"label_translated": "Works at weekday",
|
||||
"param_name": "works_at_weekday__in",
|
||||
"filters": [{
|
||||
"id": weekday,
|
||||
"index_name": week_days[weekday].lower(),
|
||||
"label_translated": week_days[weekday]
|
||||
} for weekday in range(7)]
|
||||
}
|
||||
result_list.append(works_at_weekday)
|
||||
|
||||
if 'tags_id__in' in query_params:
|
||||
# filtering by params_type and tags id
|
||||
# todo: result_list.append( filtering_data )
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user