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

get_filter_name is now a classmethod #775

Merged
merged 1 commit into from
Oct 17, 2017
Merged
Changes from all commits
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
34 changes: 17 additions & 17 deletions django_filters/filterset.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,6 @@
)


def get_filter_name(field_name, lookup_expr):
"""
Combine a field name and lookup expression into a usable filter name.
Exact lookups are the implicit default, so "exact" is stripped from the
end of the filter name.
"""
filter_name = LOOKUP_SEP.join([field_name, lookup_expr])

# This also works with transformed exact lookups, such as 'date__exact'
_exact = LOOKUP_SEP + 'exact'
if filter_name.endswith(_exact):
filter_name = filter_name[:-len(_exact)]

return filter_name


def _together_valid(form, fieldset):
field_presence = [
form.cleaned_data.get(field) not in EMPTY_VALUES
Expand Down Expand Up @@ -285,6 +269,22 @@ def get_fields(cls):

return OrderedDict(fields)

@classmethod
def get_filter_name(cls, field_name, lookup_expr):
"""
Combine a field name and lookup expression into a usable filter name.
Exact lookups are the implicit default, so "exact" is stripped from the
end of the filter name.
"""
filter_name = LOOKUP_SEP.join([field_name, lookup_expr])

# This also works with transformed exact lookups, such as 'date__exact'
_exact = LOOKUP_SEP + 'exact'
if filter_name.endswith(_exact):
filter_name = filter_name[:-len(_exact)]

return filter_name

@classmethod
def get_filters(cls):
"""
Expand Down Expand Up @@ -314,7 +314,7 @@ def get_filters(cls):
continue

for lookup_expr in lookups:
filter_name = get_filter_name(field_name, lookup_expr)
filter_name = cls.get_filter_name(field_name, lookup_expr)

# If the filter is explicitly declared on the class, skip generation
if filter_name in cls.declared_filters:
Expand Down