mirror of https://github.com/django/django.git
Fixed #28907 -- Removed unnecessary if statements.
This commit is contained in:
parent
c6864a01b2
commit
02d9419fe3
|
@ -104,37 +104,36 @@ class ChangeList:
|
||||||
raise DisallowedModelAdminLookup("Filtering by %s not allowed" % key)
|
raise DisallowedModelAdminLookup("Filtering by %s not allowed" % key)
|
||||||
|
|
||||||
filter_specs = []
|
filter_specs = []
|
||||||
if self.list_filter:
|
for list_filter in self.list_filter:
|
||||||
for list_filter in self.list_filter:
|
if callable(list_filter):
|
||||||
if callable(list_filter):
|
# This is simply a custom list filter class.
|
||||||
# This is simply a custom list filter class.
|
spec = list_filter(request, lookup_params, self.model, self.model_admin)
|
||||||
spec = list_filter(request, lookup_params, self.model, self.model_admin)
|
else:
|
||||||
|
field_path = None
|
||||||
|
if isinstance(list_filter, (tuple, list)):
|
||||||
|
# This is a custom FieldListFilter class for a given field.
|
||||||
|
field, field_list_filter_class = list_filter
|
||||||
else:
|
else:
|
||||||
field_path = None
|
# This is simply a field name, so use the default
|
||||||
if isinstance(list_filter, (tuple, list)):
|
# FieldListFilter class that has been registered for the
|
||||||
# This is a custom FieldListFilter class for a given field.
|
# type of the given field.
|
||||||
field, field_list_filter_class = list_filter
|
field, field_list_filter_class = list_filter, FieldListFilter.create
|
||||||
else:
|
if not isinstance(field, models.Field):
|
||||||
# This is simply a field name, so use the default
|
field_path = field
|
||||||
# FieldListFilter class that has been registered for
|
field = get_fields_from_path(self.model, field_path)[-1]
|
||||||
# the type of the given field.
|
|
||||||
field, field_list_filter_class = list_filter, FieldListFilter.create
|
|
||||||
if not isinstance(field, models.Field):
|
|
||||||
field_path = field
|
|
||||||
field = get_fields_from_path(self.model, field_path)[-1]
|
|
||||||
|
|
||||||
lookup_params_count = len(lookup_params)
|
lookup_params_count = len(lookup_params)
|
||||||
spec = field_list_filter_class(
|
spec = field_list_filter_class(
|
||||||
field, request, lookup_params,
|
field, request, lookup_params,
|
||||||
self.model, self.model_admin, field_path=field_path
|
self.model, self.model_admin, field_path=field_path,
|
||||||
)
|
)
|
||||||
# field_list_filter_class removes any lookup_params it
|
# field_list_filter_class removes any lookup_params it
|
||||||
# processes. If that happened, check if distinct() is
|
# processes. If that happened, check if distinct() is needed to
|
||||||
# needed to remove duplicate results.
|
# remove duplicate results.
|
||||||
if lookup_params_count > len(lookup_params):
|
if lookup_params_count > len(lookup_params):
|
||||||
use_distinct = use_distinct or lookup_needs_distinct(self.lookup_opts, field_path)
|
use_distinct = use_distinct or lookup_needs_distinct(self.lookup_opts, field_path)
|
||||||
if spec and spec.has_output():
|
if spec and spec.has_output():
|
||||||
filter_specs.append(spec)
|
filter_specs.append(spec)
|
||||||
|
|
||||||
# At this point, all the parameters used by the various ListFilters
|
# At this point, all the parameters used by the various ListFilters
|
||||||
# have been removed from lookup_params, which now only contains other
|
# have been removed from lookup_params, which now only contains other
|
||||||
|
|
|
@ -62,9 +62,8 @@ class ModelIterable(BaseIterable):
|
||||||
related_populators = get_related_populators(klass_info, select, db)
|
related_populators = get_related_populators(klass_info, select, db)
|
||||||
for row in compiler.results_iter(results):
|
for row in compiler.results_iter(results):
|
||||||
obj = model_cls.from_db(db, init_list, row[model_fields_start:model_fields_end])
|
obj = model_cls.from_db(db, init_list, row[model_fields_start:model_fields_end])
|
||||||
if related_populators:
|
for rel_populator in related_populators:
|
||||||
for rel_populator in related_populators:
|
rel_populator.populate(row, obj)
|
||||||
rel_populator.populate(row, obj)
|
|
||||||
if annotation_col_map:
|
if annotation_col_map:
|
||||||
for attr_name, col_pos in annotation_col_map.items():
|
for attr_name, col_pos in annotation_col_map.items():
|
||||||
setattr(obj, attr_name, row[col_pos])
|
setattr(obj, attr_name, row[col_pos])
|
||||||
|
@ -1771,9 +1770,8 @@ class RelatedPopulator:
|
||||||
obj = None
|
obj = None
|
||||||
else:
|
else:
|
||||||
obj = self.model_cls.from_db(self.db, self.init_list, obj_data)
|
obj = self.model_cls.from_db(self.db, self.init_list, obj_data)
|
||||||
if self.related_populators:
|
for rel_iter in self.related_populators:
|
||||||
for rel_iter in self.related_populators:
|
rel_iter.populate(row, obj)
|
||||||
rel_iter.populate(row, obj)
|
|
||||||
self.local_setter(from_obj, obj)
|
self.local_setter(from_obj, obj)
|
||||||
if obj is not None:
|
if obj is not None:
|
||||||
self.remote_setter(obj, from_obj)
|
self.remote_setter(obj, from_obj)
|
||||||
|
|
|
@ -1363,16 +1363,15 @@ def url(parser, token):
|
||||||
asvar = bits[-1]
|
asvar = bits[-1]
|
||||||
bits = bits[:-2]
|
bits = bits[:-2]
|
||||||
|
|
||||||
if bits:
|
for bit in bits:
|
||||||
for bit in bits:
|
match = kwarg_re.match(bit)
|
||||||
match = kwarg_re.match(bit)
|
if not match:
|
||||||
if not match:
|
raise TemplateSyntaxError("Malformed arguments to url tag")
|
||||||
raise TemplateSyntaxError("Malformed arguments to url tag")
|
name, value = match.groups()
|
||||||
name, value = match.groups()
|
if name:
|
||||||
if name:
|
kwargs[name] = parser.compile_filter(value)
|
||||||
kwargs[name] = parser.compile_filter(value)
|
else:
|
||||||
else:
|
args.append(parser.compile_filter(value))
|
||||||
args.append(parser.compile_filter(value))
|
|
||||||
|
|
||||||
return URLNode(viewname, args, kwargs, asvar)
|
return URLNode(viewname, args, kwargs, asvar)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue