diff --git a/django/contrib/admin/filters.py b/django/contrib/admin/filters.py index 4216f2ea64..af5ec34995 100644 --- a/django/contrib/admin/filters.py +++ b/django/contrib/admin/filters.py @@ -37,9 +37,11 @@ class ListFilter(object): """ raise NotImplementedError('subclasses of ListFilter must provide a has_output() method') - def choices(self, cl): + def choices(self, changelist): """ Returns choices ready to be output in the template. + + `changelist` is the ChangeList to be displayed. """ raise NotImplementedError('subclasses of ListFilter must provide a choices() method') @@ -98,18 +100,16 @@ class SimpleListFilter(ListFilter): def expected_parameters(self): return [self.parameter_name] - def choices(self, cl): + def choices(self, changelist): yield { 'selected': self.value() is None, - 'query_string': cl.get_query_string({}, [self.parameter_name]), + 'query_string': changelist.get_query_string({}, [self.parameter_name]), 'display': _('All'), } for lookup, title in self.lookup_choices: yield { 'selected': self.value() == force_text(lookup), - 'query_string': cl.get_query_string({ - self.parameter_name: lookup, - }, []), + 'query_string': changelist.get_query_string({self.parameter_name: lookup}, []), 'display': title, } @@ -197,17 +197,17 @@ class RelatedFieldListFilter(FieldListFilter): def field_choices(self, field, request, model_admin): return field.get_choices(include_blank=False) - def choices(self, cl): + def choices(self, changelist): yield { 'selected': self.lookup_val is None and not self.lookup_val_isnull, - 'query_string': cl.get_query_string({}, + 'query_string': changelist.get_query_string({}, [self.lookup_kwarg, self.lookup_kwarg_isnull]), 'display': _('All'), } for pk_val, val in self.lookup_choices: yield { 'selected': self.lookup_val == smart_text(pk_val), - 'query_string': cl.get_query_string({ + 'query_string': changelist.get_query_string({ self.lookup_kwarg: pk_val, }, [self.lookup_kwarg_isnull]), 'display': val, @@ -215,7 +215,7 @@ class RelatedFieldListFilter(FieldListFilter): if self.include_empty_choice: yield { 'selected': bool(self.lookup_val_isnull), - 'query_string': cl.get_query_string({ + 'query_string': changelist.get_query_string({ self.lookup_kwarg_isnull: 'True', }, [self.lookup_kwarg]), 'display': self.empty_value_display, @@ -236,14 +236,14 @@ class BooleanFieldListFilter(FieldListFilter): def expected_parameters(self): return [self.lookup_kwarg, self.lookup_kwarg2] - def choices(self, cl): + def choices(self, changelist): for lookup, title in ( (None, _('All')), ('1', _('Yes')), ('0', _('No'))): yield { 'selected': self.lookup_val == lookup and not self.lookup_val2, - 'query_string': cl.get_query_string({ + 'query_string': changelist.get_query_string({ self.lookup_kwarg: lookup, }, [self.lookup_kwarg2]), 'display': title, @@ -251,7 +251,7 @@ class BooleanFieldListFilter(FieldListFilter): if isinstance(self.field, models.NullBooleanField): yield { 'selected': self.lookup_val2 == 'True', - 'query_string': cl.get_query_string({ + 'query_string': changelist.get_query_string({ self.lookup_kwarg2: 'True', }, [self.lookup_kwarg]), 'display': _('Unknown'), @@ -271,17 +271,16 @@ class ChoicesFieldListFilter(FieldListFilter): def expected_parameters(self): return [self.lookup_kwarg] - def choices(self, cl): + def choices(self, changelist): yield { 'selected': self.lookup_val is None, - 'query_string': cl.get_query_string({}, [self.lookup_kwarg]), + 'query_string': changelist.get_query_string({}, [self.lookup_kwarg]), 'display': _('All') } for lookup, title in self.field.flatchoices: yield { 'selected': smart_text(lookup) == self.lookup_val, - 'query_string': cl.get_query_string({ - self.lookup_kwarg: lookup}), + 'query_string': changelist.get_query_string({self.lookup_kwarg: lookup}), 'display': title, } @@ -338,12 +337,11 @@ class DateFieldListFilter(FieldListFilter): def expected_parameters(self): return [self.lookup_kwarg_since, self.lookup_kwarg_until] - def choices(self, cl): + def choices(self, changelist): for title, param_dict in self.links: yield { 'selected': self.date_params == param_dict, - 'query_string': cl.get_query_string( - param_dict, [self.field_generic]), + 'query_string': changelist.get_query_string(param_dict, [self.field_generic]), 'display': title, } @@ -377,11 +375,11 @@ class AllValuesFieldListFilter(FieldListFilter): def expected_parameters(self): return [self.lookup_kwarg, self.lookup_kwarg_isnull] - def choices(self, cl): + def choices(self, changelist): yield { 'selected': (self.lookup_val is None and self.lookup_val_isnull is None), - 'query_string': cl.get_query_string({}, + 'query_string': changelist.get_query_string({}, [self.lookup_kwarg, self.lookup_kwarg_isnull]), 'display': _('All'), } @@ -393,7 +391,7 @@ class AllValuesFieldListFilter(FieldListFilter): val = smart_text(val) yield { 'selected': self.lookup_val == val, - 'query_string': cl.get_query_string({ + 'query_string': changelist.get_query_string({ self.lookup_kwarg: val, }, [self.lookup_kwarg_isnull]), 'display': val, @@ -401,7 +399,7 @@ class AllValuesFieldListFilter(FieldListFilter): if include_none: yield { 'selected': bool(self.lookup_val_isnull), - 'query_string': cl.get_query_string({ + 'query_string': changelist.get_query_string({ self.lookup_kwarg_isnull: 'True', }, [self.lookup_kwarg]), 'display': self.empty_value_display,