Ticket #28907: less_ifs.patch
File less_ifs.patch, 7.4 KB (added by , 7 years ago) |
---|
-
django/contrib/admin/views/main.py
diff --git a/django/contrib/admin/views/main.py b/django/contrib/admin/views/main.py
a b class ChangeList: 104 104 raise DisallowedModelAdminLookup("Filtering by %s not allowed" % key) 105 105 106 106 filter_specs = [] 107 if self.list_filter: 108 for list_filter in self.list_filter: 109 if callable(list_filter): 110 # This is simply a custom list filter class. 111 spec = list_filter(request, lookup_params, self.model, self.model_admin) 107 for list_filter in self.list_filter: 108 if callable(list_filter): 109 # This is simply a custom list filter class. 110 spec = list_filter(request, lookup_params, self.model, self.model_admin) 111 else: 112 field_path = None 113 if isinstance(list_filter, (tuple, list)): 114 # This is a custom FieldListFilter class for a given field. 115 field, field_list_filter_class = list_filter 112 116 else: 113 field_path = None 114 if isinstance(list_filter, (tuple, list)): 115 # This is a custom FieldListFilter class for a given field. 116 field, field_list_filter_class = list_filter 117 else: 118 # This is simply a field name, so use the default 119 # FieldListFilter class that has been registered for 120 # the type of the given field. 121 field, field_list_filter_class = list_filter, FieldListFilter.create 122 if not isinstance(field, models.Field): 123 field_path = field 124 field = get_fields_from_path(self.model, field_path)[-1] 125 126 lookup_params_count = len(lookup_params) 127 spec = field_list_filter_class( 128 field, request, lookup_params, 129 self.model, self.model_admin, field_path=field_path 130 ) 131 # field_list_filter_class removes any lookup_params it 132 # processes. If that happened, check if distinct() is 133 # needed to remove duplicate results. 134 if lookup_params_count > len(lookup_params): 135 use_distinct = use_distinct or lookup_needs_distinct(self.lookup_opts, field_path) 136 if spec and spec.has_output(): 137 filter_specs.append(spec) 117 # This is simply a field name, so use the default 118 # FieldListFilter class that has been registered for 119 # the type of the given field. 120 field, field_list_filter_class = list_filter, FieldListFilter.create 121 if not isinstance(field, models.Field): 122 field_path = field 123 field = get_fields_from_path(self.model, field_path)[-1] 124 125 lookup_params_count = len(lookup_params) 126 spec = field_list_filter_class( 127 field, request, lookup_params, 128 self.model, self.model_admin, field_path=field_path 129 ) 130 # field_list_filter_class removes any lookup_params it 131 # processes. If that happened, check if distinct() is 132 # needed to remove duplicate results. 133 if lookup_params_count > len(lookup_params): 134 use_distinct = use_distinct or lookup_needs_distinct(self.lookup_opts, field_path) 135 if spec and spec.has_output(): 136 filter_specs.append(spec) 138 137 139 138 # At this point, all the parameters used by the various ListFilters 140 139 # have been removed from lookup_params, which now only contains other -
django/db/models/query.py
diff --git a/django/db/models/query.py b/django/db/models/query.py
a b class ModelIterable(BaseIterable): 63 63 related_populators = get_related_populators(klass_info, select, db) 64 64 for row in compiler.results_iter(results): 65 65 obj = model_cls.from_db(db, init_list, row[model_fields_start:model_fields_end]) 66 if related_populators: 67 for rel_populator in related_populators: 68 rel_populator.populate(row, obj) 66 for rel_populator in related_populators: 67 rel_populator.populate(row, obj) 69 68 if annotation_col_map: 70 69 for attr_name, col_pos in annotation_col_map.items(): 71 70 setattr(obj, attr_name, row[col_pos]) … … class RelatedPopulator: 1778 1777 obj = None 1779 1778 else: 1780 1779 obj = self.model_cls.from_db(self.db, self.init_list, obj_data) 1781 if self.related_populators: 1782 for rel_iter in self.related_populators: 1783 rel_iter.populate(row, obj) 1780 for rel_iter in self.related_populators: 1781 rel_iter.populate(row, obj) 1784 1782 self.local_setter(from_obj, obj) 1785 1783 if obj is not None: 1786 1784 self.remote_setter(obj, from_obj) -
django/template/defaulttags.py
diff --git a/django/template/defaulttags.py b/django/template/defaulttags.py
a b def url(parser, token): 1363 1363 asvar = bits[-1] 1364 1364 bits = bits[:-2] 1365 1365 1366 if bits: 1367 for bit in bits: 1368 match = kwarg_re.match(bit) 1369 if not match: 1370 raise TemplateSyntaxError("Malformed arguments to url tag") 1371 name, value = match.groups() 1372 if name: 1373 kwargs[name] = parser.compile_filter(value) 1374 else: 1375 args.append(parser.compile_filter(value)) 1366 for bit in bits: 1367 match = kwarg_re.match(bit) 1368 if not match: 1369 raise TemplateSyntaxError("Malformed arguments to url tag") 1370 name, value = match.groups() 1371 if name: 1372 kwargs[name] = parser.compile_filter(value) 1373 else: 1374 args.append(parser.compile_filter(value)) 1376 1375 1377 1376 return URLNode(viewname, args, kwargs, asvar) 1378 1377 -
tests/admin_scripts/tests.py
diff --git a/tests/admin_scripts/tests.py b/tests/admin_scripts/tests.py
a b class AdminScriptTestCase(unittest.TestCase): 82 82 83 83 settings_file.write("INSTALLED_APPS = %s\n" % apps) 84 84 85 if sdict: 86 for k, v in sdict.items(): 87 settings_file.write("%s = %s\n" % (k, v)) 85 for k, v in sdict.items(): 86 settings_file.write("%s = %s\n" % (k, v)) 88 87 89 88 def remove_settings(self, filename, is_dir=False): 90 89 full_name = os.path.join(self.test_dir, filename) -
tests/middleware/test_security.py
diff --git a/tests/middleware/test_security.py b/tests/middleware/test_security.py
a b class SecurityMiddlewareTest(SimpleTestCase): 15 15 16 16 def response(self, *args, headers=None, **kwargs): 17 17 response = HttpResponse(*args, **kwargs) 18 if headers: 19 for k, v in headers.items(): 20 response[k] = v 18 for k, v in headers.items(): 19 response[k] = v 21 20 return response 22 21 23 22 def process_response(self, *args, secure=False, request=None, **kwargs):