Ticket #28984: various_shortcuts.patch

File various_shortcuts.patch, 11.8 KB (added by Дилян Палаузов, 7 years ago)
  • django/contrib/admin/helpers.py

    diff --git a/django/contrib/admin/helpers.py b/django/contrib/admin/helpers.py
    a b class AdminReadonlyField:  
    203203            result_repr = self.empty_value_display
    204204        else:
    205205            if f is None:
    206                 boolean = getattr(attr, "boolean", False)
    207                 if boolean:
     206                if getattr(attr, "boolean", False):
    208207                    result_repr = _boolean_icon(value)
    209208                else:
    210209                    if hasattr(value, "__html__"):
    class InlineAdminForm(AdminForm):  
    332331
    333332    def needs_explicit_pk_field(self):
    334333        # 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())
    342339        )
    343340
    344341    def pk_field(self):
  • django/contrib/admin/models.py

    diff --git a/django/contrib/admin/models.py b/django/contrib/admin/models.py
    a b class LogEntry(models.Model):  
    122122                    sub_message['deleted']['name'] = gettext(sub_message['deleted']['name'])
    123123                    messages.append(gettext('Deleted {name} "{object}".').format(**sub_message['deleted']))
    124124
    125             change_message = ' '.join(msg[0].upper() + msg[1:] for msg in messages)
     125            change_message = ' '.join(msg.capitalize() for msg in messages)
    126126            return change_message or gettext('No fields changed.')
    127127        else:
    128128            return self.change_message
  • django/contrib/admin/options.py

    diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py
    a b class ModelAdmin(BaseModelAdmin):  
    841841        actions = filter(None, actions)
    842842
    843843        # Convert the actions into an OrderedDict keyed by name.
    844         actions = OrderedDict(
     844        return OrderedDict(
    845845            (name, (func, name, desc))
    846846            for func, name, desc in actions
    847847        )
    848848
    849         return actions
    850 
    851849    def get_action_choices(self, request, default_choices=BLANK_CHOICE_DASH):
    852850        """
    853851        Return a list of choices for use in a form object.  Each choice is a
  • django/contrib/sessions/backends/base.py

    diff --git a/django/contrib/sessions/backends/base.py b/django/contrib/sessions/backends/base.py
    a b class SessionBase:  
    151151        while True:
    152152            session_key = get_random_string(32, VALID_KEY_CHARS)
    153153            if not self.exists(session_key):
    154                 break
    155         return session_key
     154                return session_key
    156155
    157156    def _get_or_create_session_key(self):
    158157        if self._session_key is None:
  • django/core/serializers/__init__.py

    diff --git a/django/core/serializers/__init__.py b/django/core/serializers/__init__.py
    a b def sort_dependencies(app_list):  
    216216            # If all of the models in the dependency list are either already
    217217            # on the final model list, or not on the original serialization list,
    218218            # 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)):
    224220                model_list.append(model)
    225221                changed = True
    226222            else:
  • django/db/migrations/autodetector.py

    diff --git a/django/db/migrations/autodetector.py b/django/db/migrations/autodetector.py
    a b class MigrationAutodetector:  
    301301                    if deps_satisfied:
    302302                        chopped.append(operation)
    303303                        dependencies.update(operation_dependencies)
    304                         self.generated_operations[app_label] = self.generated_operations[app_label][1:]
     304                        del self.generated_operations[app_label][0]
    305305                    else:
    306306                        break
    307307                # Make a migration! Well, only if there's stuff to put in it
  • django/db/migrations/graph.py

    diff --git a/django/db/migrations/graph.py b/django/db/migrations/graph.py
    a b class MigrationGraph:  
    304304        """
    305305        roots = set()
    306306        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]):
    308308                roots.add(node)
    309309        return sorted(roots)
    310310
    class MigrationGraph:  
    318318        """
    319319        leaves = set()
    320320        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]):
    322322                leaves.add(node)
    323323        return sorted(leaves)
    324324
  • django/db/models/fields/files.py

    diff --git a/django/db/models/fields/files.py b/django/db/models/fields/files.py
    a b class FieldFile(File):  
    3939
    4040    def _get_file(self):
    4141        self._require_file()
    42         if not hasattr(self, '_file') or self._file is None:
     42        if getattr(self, '_file', None) is None:
    4343            self._file = self.storage.open(self.name, 'rb')
    4444        return self._file
    4545
  • django/dispatch/dispatcher.py

    diff --git a/django/dispatch/dispatcher.py b/django/dispatch/dispatcher.py
    a b class Signal:  
    215215        # Note: caller is assumed to hold self.lock.
    216216        if self._dead_receivers:
    217217            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)]
    224219
    225220    def _live_receivers(self, sender):
    226221        """
  • django/test/runner.py

    diff --git a/django/test/runner.py b/django/test/runner.py
    a b class DiscoverRunner:  
    531531            # Since tests are distributed across processes on a per-TestCase
    532532            # basis, there's no need for more processes than TestCases.
    533533            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)
    536535
    537536            # If there's only one TestCase, parallelization isn't needed.
    538537            if self.parallel > 1:
  • django/utils/synch.py

    diff --git a/django/utils/synch.py b/django/utils/synch.py
    a b class RWLock:  
    6060    def writer_enters(self):
    6161        with self.mutex:
    6262            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
    6464                self.can_write.release()
    6565            else:
    6666                self.waiting_writers += 1
  • tests/auth_tests/test_context_processors.py

    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  
    1010
    1111class MockUser:
    1212    def has_module_perms(self, perm):
    13         if perm == 'mockapp':
    14             return True
    15         return False
     13        return perm == 'mockapp'
    1614
    1715    def has_perm(self, perm):
    18         if perm == 'mockapp.someperm':
    19             return True
    20         return False
     16        return perm == 'mockapp.someperm'
    2117
    2218
    2319class PermWrapperTests(SimpleTestCase):
  • tests/inspectdb/tests.py

    diff --git a/tests/inspectdb/tests.py b/tests/inspectdb/tests.py
    a b class InspectDBTestCase(TestCase):  
    189189                     table_name_filter=lambda tn: tn.startswith('inspectdb_special'),
    190190                     stdout=out)
    191191        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'
    193193        self.assertIn("field = models.IntegerField()", output)
    194194        self.assertIn("field_field = models.IntegerField(db_column='%s_')" % base_name, output)
    195195        self.assertIn("field_field_0 = models.IntegerField(db_column='%s__')" % base_name, output)
  • tests/modeladmin/tests.py

    diff --git a/tests/modeladmin/tests.py b/tests/modeladmin/tests.py
    a b class ModelAdminPermissionTests(SimpleTestCase):  
    671671
    672672    class MockUser:
    673673        def has_module_perms(self, app_label):
    674             if app_label == "modeladmin":
    675                 return True
    676             return False
     674            return app_label == "modeladmin"
    677675
    678676    class MockAddUser(MockUser):
    679677        def has_perm(self, perm):
    680             if perm == "modeladmin.add_band":
    681                 return True
    682             return False
     678            return perm == "modeladmin.add_band"
    683679
    684680    class MockChangeUser(MockUser):
    685681        def has_perm(self, perm):
    686             if perm == "modeladmin.change_band":
    687                 return True
    688             return False
     682            return perm == "modeladmin.change_band"
    689683
    690684    class MockDeleteUser(MockUser):
    691685        def has_perm(self, perm):
    692             if perm == "modeladmin.delete_band":
    693                 return True
    694             return False
     686            return perm == "modeladmin.delete_band"
    695687
    696688    def test_has_add_permission(self):
    697689        """
  • tests/serializers/test_json.py

    diff --git a/tests/serializers/test_json.py b/tests/serializers/test_json.py
    a b class JsonSerializerTestCase(SerializersTestBase, TestCase):  
    5555
    5656    @staticmethod
    5757    def _get_pk_values(serial_str):
    58         ret_list = []
    5958        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]
    6360
    6461    @staticmethod
    6562    def _get_field_values(serial_str, field_name):
    66         ret_list = []
    6763        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"]]
    7265
    7366    def test_indentation_whitespace(self):
    7467        s = serializers.json.Serializer()
Back to Top