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)
|
||||
|
||||
filter_specs = []
|
||||
if self.list_filter:
|
||||
for list_filter in self.list_filter:
|
||||
if callable(list_filter):
|
||||
# This is simply a custom list filter class.
|
||||
spec = list_filter(request, lookup_params, self.model, self.model_admin)
|
||||
for list_filter in self.list_filter:
|
||||
if callable(list_filter):
|
||||
# This is simply a custom list filter class.
|
||||
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:
|
||||
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:
|
||||
# This is simply a field name, so use the default
|
||||
# FieldListFilter class that has been registered for
|
||||
# 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]
|
||||
# This is simply a field name, so use the default
|
||||
# FieldListFilter class that has been registered for 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)
|
||||
spec = field_list_filter_class(
|
||||
field, request, lookup_params,
|
||||
self.model, self.model_admin, field_path=field_path
|
||||
)
|
||||
# field_list_filter_class removes any lookup_params it
|
||||
# processes. If that happened, check if distinct() is
|
||||
# needed to remove duplicate results.
|
||||
if lookup_params_count > len(lookup_params):
|
||||
use_distinct = use_distinct or lookup_needs_distinct(self.lookup_opts, field_path)
|
||||
if spec and spec.has_output():
|
||||
filter_specs.append(spec)
|
||||
lookup_params_count = len(lookup_params)
|
||||
spec = field_list_filter_class(
|
||||
field, request, lookup_params,
|
||||
self.model, self.model_admin, field_path=field_path,
|
||||
)
|
||||
# field_list_filter_class removes any lookup_params it
|
||||
# processes. If that happened, check if distinct() is needed to
|
||||
# remove duplicate results.
|
||||
if lookup_params_count > len(lookup_params):
|
||||
use_distinct = use_distinct or lookup_needs_distinct(self.lookup_opts, field_path)
|
||||
if spec and spec.has_output():
|
||||
filter_specs.append(spec)
|
||||
|
||||
# At this point, all the parameters used by the various ListFilters
|
||||
# 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)
|
||||
for row in compiler.results_iter(results):
|
||||
obj = model_cls.from_db(db, init_list, row[model_fields_start:model_fields_end])
|
||||
if related_populators:
|
||||
for rel_populator in related_populators:
|
||||
rel_populator.populate(row, obj)
|
||||
for rel_populator in related_populators:
|
||||
rel_populator.populate(row, obj)
|
||||
if annotation_col_map:
|
||||
for attr_name, col_pos in annotation_col_map.items():
|
||||
setattr(obj, attr_name, row[col_pos])
|
||||
|
@ -1771,9 +1770,8 @@ class RelatedPopulator:
|
|||
obj = None
|
||||
else:
|
||||
obj = self.model_cls.from_db(self.db, self.init_list, obj_data)
|
||||
if self.related_populators:
|
||||
for rel_iter in self.related_populators:
|
||||
rel_iter.populate(row, obj)
|
||||
for rel_iter in self.related_populators:
|
||||
rel_iter.populate(row, obj)
|
||||
self.local_setter(from_obj, obj)
|
||||
if obj is not None:
|
||||
self.remote_setter(obj, from_obj)
|
||||
|
|
|
@ -1363,16 +1363,15 @@ def url(parser, token):
|
|||
asvar = bits[-1]
|
||||
bits = bits[:-2]
|
||||
|
||||
if bits:
|
||||
for bit in bits:
|
||||
match = kwarg_re.match(bit)
|
||||
if not match:
|
||||
raise TemplateSyntaxError("Malformed arguments to url tag")
|
||||
name, value = match.groups()
|
||||
if name:
|
||||
kwargs[name] = parser.compile_filter(value)
|
||||
else:
|
||||
args.append(parser.compile_filter(value))
|
||||
for bit in bits:
|
||||
match = kwarg_re.match(bit)
|
||||
if not match:
|
||||
raise TemplateSyntaxError("Malformed arguments to url tag")
|
||||
name, value = match.groups()
|
||||
if name:
|
||||
kwargs[name] = parser.compile_filter(value)
|
||||
else:
|
||||
args.append(parser.compile_filter(value))
|
||||
|
||||
return URLNode(viewname, args, kwargs, asvar)
|
||||
|
||||
|
|
Loading…
Reference in New Issue