Skip to content

Commit

Permalink
Merge pull request TandoorRecipes#1352 from smilerz/fix-search
Browse files Browse the repository at this point in the history
force list params to list
  • Loading branch information
vabene1111 committed Jan 17, 2022
2 parents 90b6f9a + cc5be84 commit 418c384
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
12 changes: 11 additions & 1 deletion cookbook/helper/recipe_search.py
Expand Up @@ -172,6 +172,8 @@ def _favorite_recipes(self):
def keyword_filters(self, keywords=None, operator=True):
if not keywords:
return
if not isinstance(keywords, list):
keywords = [keywords]
if operator == True:
# TODO creating setting to include descendants of keywords a setting
self._queryset = self._queryset.filter(keywords__in=Keyword.include_descendants(Keyword.objects.filter(pk__in=keywords)))
Expand All @@ -184,6 +186,8 @@ def keyword_filters(self, keywords=None, operator=True):
def food_filters(self, foods=None, operator=True):
if not foods:
return
if not isinstance(foods, list):
foods = [foods]
if operator == True:
# TODO creating setting to include descendants of food a setting
self._queryset = self._queryset.filter(steps__ingredients__food__in=Food.include_descendants(Food.objects.filter(pk__in=foods)))
Expand All @@ -198,7 +202,9 @@ def unit_filters(self, units=None, operator=True):
raise NotImplementedError
if not units:
return
self._queryset = self._queryset.filter(steps__ingredients__unit__id=units)
if not isinstance(units, list):
units = [units]
self._queryset = self._queryset.filter(steps__ingredients__unit__in=units)

def rating_filter(self, rating=None):
if rating is None:
Expand All @@ -217,6 +223,8 @@ def internal_filter(self):
def book_filters(self, books=None, operator=True):
if not books:
return
if not isinstance(books, list):
books = [books]
if operator == True:
self._queryset = self._queryset.filter(recipebookentry__book__id__in=books)
else:
Expand All @@ -228,6 +236,8 @@ def step_filters(self, steps=None, operator=True):
raise NotImplementedError
if not steps:
return
if not isinstance(steps, list):
steps = [unistepsts]
self._queryset = self._queryset.filter(steps__id__in=steps)

def build_fulltext_filters(self, string=None):
Expand Down
3 changes: 2 additions & 1 deletion cookbook/views/api.py
Expand Up @@ -655,7 +655,8 @@ def get_queryset(self):

# self.queryset = search_recipes(self.request, self.queryset, self.request.GET)
params = {x: self.request.GET.get(x) if len({**self.request.GET}[x]) == 1 else self.request.GET.getlist(x) for x in list(self.request.GET)}
self.queryset = RecipeSearch(self.request, **params).get_queryset(self.queryset).prefetch_related('cooklog_set')
search = RecipeSearch(self.request, **params)
self.queryset = search.get_queryset(self.queryset).prefetch_related('cooklog_set')
return self.queryset

def list(self, request, *args, **kwargs):
Expand Down

0 comments on commit 418c384

Please sign in to comment.