diff --git a/django/contrib/admin/helpers.py b/django/contrib/admin/helpers.py
a
|
b
|
class AdminReadonlyField:
|
203 | 203 | result_repr = self.empty_value_display |
204 | 204 | else: |
205 | 205 | if f is None: |
206 | | boolean = getattr(attr, "boolean", False) |
207 | | if boolean: |
| 206 | if getattr(attr, "boolean", False): |
208 | 207 | result_repr = _boolean_icon(value) |
209 | 208 | else: |
210 | 209 | if hasattr(value, "__html__"): |
… |
… |
class InlineAdminForm(AdminForm):
|
332 | 331 | |
333 | 332 | def needs_explicit_pk_field(self): |
334 | 333 | # Auto fields are editable (oddly), so need to check for auto or non-editable pk |
335 | | if self.form._meta.model._meta.auto_field or not self.form._meta.model._meta.pk.editable: |
336 | | return True |
337 | | # Also search any parents for an auto field. (The pk info is propagated to child |
338 | | # models so that does not need to be checked in parents.) |
339 | | return any( |
340 | | parent._meta.auto_field or not parent._meta.model._meta.pk.editable |
341 | | for parent in self.form._meta.model._meta.get_parent_list() |
| 334 | return (self.form._meta.model._meta.auto_field or not self.form._meta.model._meta.pk.editable or |
| 335 | # Also search any parents for an auto field. (The pk info is propagated to child |
| 336 | # models so that does not need to be checked in parents.) |
| 337 | any(parent._meta.auto_field or not parent._meta.model._meta.pk.editable |
| 338 | for parent in self.form._meta.model._meta.get_parent_list()) |
342 | 339 | ) |
343 | 340 | |
344 | 341 | def pk_field(self): |
diff --git a/django/contrib/admin/models.py b/django/contrib/admin/models.py
a
|
b
|
class LogEntry(models.Model):
|
122 | 122 | sub_message['deleted']['name'] = gettext(sub_message['deleted']['name']) |
123 | 123 | messages.append(gettext('Deleted {name} "{object}".').format(**sub_message['deleted'])) |
124 | 124 | |
125 | | change_message = ' '.join(msg[0].upper() + msg[1:] for msg in messages) |
| 125 | change_message = ' '.join(msg.capitalize() for msg in messages) |
126 | 126 | return change_message or gettext('No fields changed.') |
127 | 127 | else: |
128 | 128 | return self.change_message |
diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py
a
|
b
|
class ModelAdmin(BaseModelAdmin):
|
841 | 841 | actions = filter(None, actions) |
842 | 842 | |
843 | 843 | # Convert the actions into an OrderedDict keyed by name. |
844 | | actions = OrderedDict( |
| 844 | return OrderedDict( |
845 | 845 | (name, (func, name, desc)) |
846 | 846 | for func, name, desc in actions |
847 | 847 | ) |
848 | 848 | |
849 | | return actions |
850 | | |
851 | 849 | def get_action_choices(self, request, default_choices=BLANK_CHOICE_DASH): |
852 | 850 | """ |
853 | 851 | Return a list of choices for use in a form object. Each choice is a |
diff --git a/django/contrib/sessions/backends/base.py b/django/contrib/sessions/backends/base.py
a
|
b
|
class SessionBase:
|
151 | 151 | while True: |
152 | 152 | session_key = get_random_string(32, VALID_KEY_CHARS) |
153 | 153 | if not self.exists(session_key): |
154 | | break |
155 | | return session_key |
| 154 | return session_key |
156 | 155 | |
157 | 156 | def _get_or_create_session_key(self): |
158 | 157 | if self._session_key is None: |
diff --git a/django/core/serializers/__init__.py b/django/core/serializers/__init__.py
a
|
b
|
def sort_dependencies(app_list):
|
216 | 216 | # If all of the models in the dependency list are either already |
217 | 217 | # on the final model list, or not on the original serialization list, |
218 | 218 | # then we've found another model with all it's dependencies satisfied. |
219 | | found = True |
220 | | for candidate in ((d not in models or d in model_list) for d in deps): |
221 | | if not candidate: |
222 | | found = False |
223 | | if found: |
| 219 | if all(candidate for candidate in ((d not in models or d in model_list) for d in deps)): |
224 | 220 | model_list.append(model) |
225 | 221 | changed = True |
226 | 222 | else: |
diff --git a/django/db/migrations/autodetector.py b/django/db/migrations/autodetector.py
a
|
b
|
class MigrationAutodetector:
|
301 | 301 | if deps_satisfied: |
302 | 302 | chopped.append(operation) |
303 | 303 | dependencies.update(operation_dependencies) |
304 | | self.generated_operations[app_label] = self.generated_operations[app_label][1:] |
| 304 | del self.generated_operations[app_label][0] |
305 | 305 | else: |
306 | 306 | break |
307 | 307 | # Make a migration! Well, only if there's stuff to put in it |
diff --git a/django/db/migrations/graph.py b/django/db/migrations/graph.py
a
|
b
|
class MigrationGraph:
|
304 | 304 | """ |
305 | 305 | roots = set() |
306 | 306 | for node in self.nodes: |
307 | | if not any(key[0] == node[0] for key in self.node_map[node].parents) and (not app or app == node[0]): |
| 307 | if all(key[0] != node[0] for key in self.node_map[node].parents) and (not app or app == node[0]): |
308 | 308 | roots.add(node) |
309 | 309 | return sorted(roots) |
310 | 310 | |
… |
… |
class MigrationGraph:
|
318 | 318 | """ |
319 | 319 | leaves = set() |
320 | 320 | for node in self.nodes: |
321 | | if not any(key[0] == node[0] for key in self.node_map[node].children) and (not app or app == node[0]): |
| 321 | if all(key[0] != node[0] for key in self.node_map[node].children) and (not app or app == node[0]): |
322 | 322 | leaves.add(node) |
323 | 323 | return sorted(leaves) |
324 | 324 | |
diff --git a/django/db/models/fields/files.py b/django/db/models/fields/files.py
a
|
b
|
class FieldFile(File):
|
39 | 39 | |
40 | 40 | def _get_file(self): |
41 | 41 | self._require_file() |
42 | | if not hasattr(self, '_file') or self._file is None: |
| 42 | if getattr(self, '_file', None) is None: |
43 | 43 | self._file = self.storage.open(self.name, 'rb') |
44 | 44 | return self._file |
45 | 45 | |
diff --git a/django/dispatch/dispatcher.py b/django/dispatch/dispatcher.py
a
|
b
|
class Signal:
|
215 | 215 | # Note: caller is assumed to hold self.lock. |
216 | 216 | if self._dead_receivers: |
217 | 217 | self._dead_receivers = False |
218 | | new_receivers = [] |
219 | | for r in self.receivers: |
220 | | if isinstance(r[1], weakref.ReferenceType) and r[1]() is None: |
221 | | continue |
222 | | new_receivers.append(r) |
223 | | self.receivers = new_receivers |
| 218 | self.receivers = [r for r in self.receivers if not(isinstance(r[1], weakref.ReferenceType) and r[1]() is None)] |
224 | 219 | |
225 | 220 | def _live_receivers(self, sender): |
226 | 221 | """ |
diff --git a/django/test/runner.py b/django/test/runner.py
a
|
b
|
class DiscoverRunner:
|
531 | 531 | # Since tests are distributed across processes on a per-TestCase |
532 | 532 | # basis, there's no need for more processes than TestCases. |
533 | 533 | parallel_units = len(parallel_suite.subsuites) |
534 | | if self.parallel > parallel_units: |
535 | | self.parallel = parallel_units |
| 534 | self.parallel = min(self.parallel, parallel_units) |
536 | 535 | |
537 | 536 | # If there's only one TestCase, parallelization isn't needed. |
538 | 537 | if self.parallel > 1: |
diff --git a/django/utils/synch.py b/django/utils/synch.py
a
|
b
|
class RWLock:
|
60 | 60 | def writer_enters(self): |
61 | 61 | with self.mutex: |
62 | 62 | if self.active_writers == 0 and self.waiting_writers == 0 and self.active_readers == 0: |
63 | | self.active_writers += 1 |
| 63 | self.active_writers = 1 |
64 | 64 | self.can_write.release() |
65 | 65 | else: |
66 | 66 | self.waiting_writers += 1 |
diff --git a/tests/auth_tests/test_context_processors.py b/tests/auth_tests/test_context_processors.py
a
|
b
|
from .settings import AUTH_MIDDLEWARE, AUTH_TEMPLATES
|
10 | 10 | |
11 | 11 | class MockUser: |
12 | 12 | def has_module_perms(self, perm): |
13 | | if perm == 'mockapp': |
14 | | return True |
15 | | return False |
| 13 | return perm == 'mockapp' |
16 | 14 | |
17 | 15 | def has_perm(self, perm): |
18 | | if perm == 'mockapp.someperm': |
19 | | return True |
20 | | return False |
| 16 | return perm == 'mockapp.someperm' |
21 | 17 | |
22 | 18 | |
23 | 19 | class PermWrapperTests(SimpleTestCase): |
diff --git a/tests/inspectdb/tests.py b/tests/inspectdb/tests.py
a
|
b
|
class InspectDBTestCase(TestCase):
|
189 | 189 | table_name_filter=lambda tn: tn.startswith('inspectdb_special'), |
190 | 190 | stdout=out) |
191 | 191 | output = out.getvalue() |
192 | | base_name = 'Field' if not connection.features.uppercases_column_names else 'field' |
| 192 | base_name = 'field' if connection.features.uppercases_column_names else 'Field' |
193 | 193 | self.assertIn("field = models.IntegerField()", output) |
194 | 194 | self.assertIn("field_field = models.IntegerField(db_column='%s_')" % base_name, output) |
195 | 195 | self.assertIn("field_field_0 = models.IntegerField(db_column='%s__')" % base_name, output) |
diff --git a/tests/modeladmin/tests.py b/tests/modeladmin/tests.py
a
|
b
|
class ModelAdminPermissionTests(SimpleTestCase):
|
671 | 671 | |
672 | 672 | class MockUser: |
673 | 673 | def has_module_perms(self, app_label): |
674 | | if app_label == "modeladmin": |
675 | | return True |
676 | | return False |
| 674 | return app_label == "modeladmin" |
677 | 675 | |
678 | 676 | class MockAddUser(MockUser): |
679 | 677 | def has_perm(self, perm): |
680 | | if perm == "modeladmin.add_band": |
681 | | return True |
682 | | return False |
| 678 | return perm == "modeladmin.add_band" |
683 | 679 | |
684 | 680 | class MockChangeUser(MockUser): |
685 | 681 | def has_perm(self, perm): |
686 | | if perm == "modeladmin.change_band": |
687 | | return True |
688 | | return False |
| 682 | return perm == "modeladmin.change_band" |
689 | 683 | |
690 | 684 | class MockDeleteUser(MockUser): |
691 | 685 | def has_perm(self, perm): |
692 | | if perm == "modeladmin.delete_band": |
693 | | return True |
694 | | return False |
| 686 | return perm == "modeladmin.delete_band" |
695 | 687 | |
696 | 688 | def test_has_add_permission(self): |
697 | 689 | """ |
diff --git a/tests/serializers/test_json.py b/tests/serializers/test_json.py
a
|
b
|
class JsonSerializerTestCase(SerializersTestBase, TestCase):
|
55 | 55 | |
56 | 56 | @staticmethod |
57 | 57 | def _get_pk_values(serial_str): |
58 | | ret_list = [] |
59 | 58 | serial_list = json.loads(serial_str) |
60 | | for obj_dict in serial_list: |
61 | | ret_list.append(obj_dict["pk"]) |
62 | | return ret_list |
| 59 | return [obj_dict["pk"] for obj_dict in serial_list] |
63 | 60 | |
64 | 61 | @staticmethod |
65 | 62 | def _get_field_values(serial_str, field_name): |
66 | | ret_list = [] |
67 | 63 | serial_list = json.loads(serial_str) |
68 | | for obj_dict in serial_list: |
69 | | if field_name in obj_dict["fields"]: |
70 | | ret_list.append(obj_dict["fields"][field_name]) |
71 | | return ret_list |
| 64 | return [obj_dict["fields"][field_name] for obj_dict in serial_list if field_name in obj_dict["fields"]] |
72 | 65 | |
73 | 66 | def test_indentation_whitespace(self): |
74 | 67 | s = serializers.json.Serializer() |