Skip to content

Commit

Permalink
chore(deps): handle enum in filter
Browse files Browse the repository at this point in the history
  • Loading branch information
René Birrer authored and winged committed Dec 20, 2021
1 parent 74ec48a commit 83e6e49
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 213 deletions.
4 changes: 3 additions & 1 deletion caluma/caluma_form/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ def filter(self, qs, value):

def apply_expr(self, qs, expr):
lookup = expr.get("lookup", self.lookup_expr)
lookup_expr = (hasattr(lookup, "value") and lookup.value) or lookup

question_slug = expr["question"]
match_value = expr.get("value")
Expand Down Expand Up @@ -243,7 +244,7 @@ def apply_expr(self, qs, expr):
else:
answers = answers.filter(
**{
f"{answer_value}__{lookup}": match_value,
f"{answer_value}__{lookup_expr}": match_value,
"question__slug": question_slug,
}
)
Expand All @@ -268,6 +269,7 @@ def _validate_lookup(self, question, lookup):
)

if lookup not in valid_lookups:
lookup = (hasattr(lookup, "value") and lookup.value) or lookup
raise exceptions.ValidationError(
f"Invalid lookup for question slug={question.slug} ({question.type.upper()}): {lookup.upper()}"
)
Expand Down
Loading

0 comments on commit 83e6e49

Please sign in to comment.