Ticket #4528: pre_sync_updated.patch
File pre_sync_updated.patch, 4.2 KB (added by , 13 years ago) |
---|
-
django/core/management/commands/syncdb.py
diff --git a/django/core/management/commands/syncdb.py b/django/core/management/commands/syncdb.py
a b 5 5 from django.conf import settings 6 6 from django.core.management.base import NoArgsCommand 7 7 from django.core.management.color import no_style 8 from django.core.management.sql import custom_sql_for_model, emit_post_sync_signal 8 from django.core.management.sql import custom_sql_for_model, emit_post_sync_signal, emit_pre_sync_signal 9 9 from django.db import connections, router, transaction, models, DEFAULT_DB_ALIAS 10 10 from django.utils.datastructures import SortedDict 11 11 from django.utils.importlib import import_module … … 54 54 55 55 db = options.get('database') 56 56 connection = connections[db] 57 emit_pre_sync_signal(verbosity, interactive, db) 57 58 cursor = connection.cursor() 58 59 59 60 # Get a list of already installed *models* so that references work right. -
django/core/management/sql.py
diff --git a/django/core/management/sql.py b/django/core/management/sql.py
a b 178 178 return output 179 179 180 180 181 def emit_pre_sync_signal(verbosity, interactive, db): 182 # Emit the pre_sync signal for every application. 183 for app in models.get_apps(): 184 app_name = app.__name__.split('.')[-2] 185 if verbosity >= 2: 186 print "Running pre-sync handlers for application", app_name 187 models.signals.pre_syncdb.send(sender=app, app=app, 188 verbosity=verbosity, 189 interactive=interactive, 190 db=db) 191 192 181 193 def emit_post_sync_signal(created_models, verbosity, interactive, db): 182 194 # Emit the post_sync signal for every application. 183 195 for app in models.get_apps(): … … 187 199 models.signals.post_syncdb.send(sender=app, app=app, 188 200 created_models=created_models, verbosity=verbosity, 189 201 interactive=interactive, db=db) 202 -
django/db/models/signals.py
diff --git a/django/db/models/signals.py b/django/db/models/signals.py
a b 11 11 pre_delete = Signal(providing_args=["instance", "using"]) 12 12 post_delete = Signal(providing_args=["instance", "using"]) 13 13 14 pre_syncdb = Signal(providing_args=["app", "verbosity", "interactive", "db"]) 14 15 post_syncdb = Signal(providing_args=["class", "app", "created_models", "verbosity", "interactive"]) 15 16 16 17 m2m_changed = Signal(providing_args=["action", "instance", "reverse", "model", "pk_set", "using"]) -
new file tests/regressiontests/syncdb/__init__.py
diff --git a/tests/regressiontests/syncdb/__init__.py b/tests/regressiontests/syncdb/__init__.py new file mode 100644
- + 1 -
new file tests/regressiontests/syncdb/tests.py
diff --git a/tests/regressiontests/syncdb/models.py b/tests/regressiontests/syncdb/models.py new file mode 100644 diff --git a/tests/regressiontests/syncdb/tests.py b/tests/regressiontests/syncdb/tests.py new file mode 100644
- + 1 from django.db.models import signals 2 from django.dispatch import receiver 3 from django.test import TestCase 4 from django.core import management 5 6 import models 7 8 9 PRE_SYNCDB_ARGS = ['app', 'verbosity', 'interactive', 'db'] 10 SYNCDB_VERBOSITY = 1 11 SYNCDB_INTERACTIVE = False 12 13 14 class PreSyncdbReceiver(object): 15 def __init__(self): 16 self.run_counter = 0 17 self.args = None 18 19 def __call__(self, signal, sender, **kwargs): 20 self.run_counter = self.run_counter + 1 21 self.args = kwargs 22 23 24 class SyncdbSignalTests(TestCase): 25 def test_pre_syncdb_signal(self): 26 r = PreSyncdbReceiver() 27 signals.pre_syncdb.connect(r, sender=models) 28 management.call_command('syncdb', verbosity=SYNCDB_VERBOSITY, 29 interactive=SYNCDB_INTERACTIVE) 30 31 self.assertEqual(r.run_counter, 1) 32 self.assertItemsEqual(r.args, PRE_SYNCDB_ARGS) 33 self.assertEqual(r.args['app'], models) 34 self.assertEqual(r.args['verbosity'], SYNCDB_VERBOSITY) 35 self.assertEqual(r.args['interactive'], SYNCDB_INTERACTIVE) 36 self.assertEqual(r.args['db'], 'default')