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

WIP filters: when invalid filter value, use default value if there is one #1308

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions adhocracy4/filters/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ def __init__(self, data, *args, **kwargs):
data[key] = value
super().__init__(data, *args, **kwargs)

# if filter has invalid value, set it to default value
for field in self.form.errors:
if field in self.data and field in self.defaults:
self.data[field] = self.defaults[field]


class DistinctOrderingFilter(django_filters.OrderingFilter):
"""Makes sure, that every queryset gets a distinct ordering.
Expand Down