Skip to content

Commit

Permalink
Fixed choice param issue
Browse files Browse the repository at this point in the history
  • Loading branch information
mtyton committed Jan 12, 2024
1 parent a8745ad commit da6e24f
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions audoma/drf/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,22 @@
class DocumentedTypedChoiceFilter(df_filters.TypedChoiceFilter):
"""Extended TypedChoiceFilter to generate documentation automatically"""

def _parse_choices(self, choices):
if hasattr(choices, "get_api_choices"):
return choices.get_api_choices()
if isinstance(choices, dict):
return choices
if isinstance(choices, (list, tuple)):
if isinstance(choices[0], (list, tuple)):
return choices
else:
return ((c, c) for c in choices)
raise ValueError(f"Choices must be a dict, list or tuple, not {type(choices)}")

def __init__(
self, full_choices: Union[NamedTuple, Tuple], parameter_name: str, **kwargs
) -> None:
self.parsed_choices = (
full_choices.get_api_choices()
if hasattr(full_choices, "get_api_choices")
else full_choices
)
self.parsed_choices = self._parse_choices(full_choices)
if hasattr(full_choices, "get_value_by_name"):

def coerce(value):
Expand Down

0 comments on commit da6e24f

Please sign in to comment.