Loading django/core/management/commands/syncdb.py +5 −1 Original line number Diff line number Diff line from optparse import make_option import itertools import traceback from django.conf import settings from django.core.management import call_command from django.core.management.base import NoArgsCommand from django.core.management.color import no_style from django.core.management.sql import custom_sql_for_model, emit_post_sync_signal from django.core.management.sql import custom_sql_for_model, emit_post_sync_signal, emit_pre_sync_signal from django.db import connections, router, transaction, models, DEFAULT_DB_ALIAS from django.utils.datastructures import SortedDict from django.utils.importlib import import_module Loading Loading @@ -80,6 +81,9 @@ class Command(NoArgsCommand): for app_name, model_list in all_models ) create_models = set([x for x in itertools.chain(*manifest.values())]) emit_pre_sync_signal(create_models, verbosity, interactive, db) # Create the tables for each model if verbosity >= 1: self.stdout.write("Creating tables ...\n") Loading django/core/management/sql.py +14 −0 Original line number Diff line number Diff line Loading @@ -137,6 +137,7 @@ def sql_indexes(app, style, connection): output.extend(connection.creation.sql_indexes_for_model(model, style)) return output def sql_destroy_indexes(app, style, connection): "Returns a list of the DROP INDEX SQL statements for all models in the given app." output = [] Loading Loading @@ -191,6 +192,19 @@ def custom_sql_for_model(model, style, connection): return output def emit_pre_sync_signal(create_models, verbosity, interactive, db): # Emit the pre_sync signal for every application. for app in models.get_apps(): app_name = app.__name__.split('.')[-2] if verbosity >= 2: print("Running pre-sync handlers for application %s" % app_name) models.signals.pre_syncdb.send(sender=app, app=app, create_models=create_models, verbosity=verbosity, interactive=interactive, db=db) def emit_post_sync_signal(created_models, verbosity, interactive, db): # Emit the post_sync signal for every application. for app in models.get_apps(): Loading django/db/models/signals.py +1 −0 Original line number Diff line number Diff line Loading @@ -12,6 +12,7 @@ post_save = Signal(providing_args=["instance", "raw", "created", "using", "updat pre_delete = Signal(providing_args=["instance", "using"], use_caching=True) post_delete = Signal(providing_args=["instance", "using"], use_caching=True) pre_syncdb = Signal(providing_args=["app", "create_models", "verbosity", "interactive", "db"]) post_syncdb = Signal(providing_args=["class", "app", "created_models", "verbosity", "interactive", "db"], use_caching=True) m2m_changed = Signal(providing_args=["action", "instance", "reverse", "model", "pk_set", "using"], use_caching=True) docs/ref/signals.txt +47 −0 Original line number Diff line number Diff line Loading @@ -360,6 +360,53 @@ Management signals Signals sent by :doc:`django-admin </ref/django-admin>`. pre_syncdb ---------- .. data:: django.db.models.signals.pre_syncdb :module: Sent by the :djadmin:`syncdb` command before it starts to install an application. Any handlers that listen to this signal need to be written in a particular place: a ``management`` module in one of your :setting:`INSTALLED_APPS`. If handlers are registered anywhere else they may not be loaded by :djadmin:`syncdb`. Arguments sent with this signal: ``sender`` The ``models`` module that was just installed. That is, if :djadmin:`syncdb` just installed an app called ``"foo.bar.myapp"``, ``sender`` will be the ``foo.bar.myapp.models`` module. ``app`` Same as ``sender``. ``create_models`` A list of the model classes from any app which :djadmin:`syncdb` plans to create. ``verbosity`` Indicates how much information manage.py is printing on screen. See the :djadminopt:`--verbosity` flag for details. Functions which listen for :data:`pre_syncdb` should adjust what they output to the screen based on the value of this argument. ``interactive`` If ``interactive`` is ``True``, it's safe to prompt the user to input things on the command line. If ``interactive`` is ``False``, functions which listen for this signal should not try to prompt for anything. For example, the :mod:`django.contrib.auth` app only prompts to create a superuser when ``interactive`` is ``True``. ``db`` The alias of database on which a command will operate. post_syncdb ----------- Loading tests/syncdb_signals/__init__.py 0 → 100644 +0 −0 Empty file added. Loading
django/core/management/commands/syncdb.py +5 −1 Original line number Diff line number Diff line from optparse import make_option import itertools import traceback from django.conf import settings from django.core.management import call_command from django.core.management.base import NoArgsCommand from django.core.management.color import no_style from django.core.management.sql import custom_sql_for_model, emit_post_sync_signal from django.core.management.sql import custom_sql_for_model, emit_post_sync_signal, emit_pre_sync_signal from django.db import connections, router, transaction, models, DEFAULT_DB_ALIAS from django.utils.datastructures import SortedDict from django.utils.importlib import import_module Loading Loading @@ -80,6 +81,9 @@ class Command(NoArgsCommand): for app_name, model_list in all_models ) create_models = set([x for x in itertools.chain(*manifest.values())]) emit_pre_sync_signal(create_models, verbosity, interactive, db) # Create the tables for each model if verbosity >= 1: self.stdout.write("Creating tables ...\n") Loading
django/core/management/sql.py +14 −0 Original line number Diff line number Diff line Loading @@ -137,6 +137,7 @@ def sql_indexes(app, style, connection): output.extend(connection.creation.sql_indexes_for_model(model, style)) return output def sql_destroy_indexes(app, style, connection): "Returns a list of the DROP INDEX SQL statements for all models in the given app." output = [] Loading Loading @@ -191,6 +192,19 @@ def custom_sql_for_model(model, style, connection): return output def emit_pre_sync_signal(create_models, verbosity, interactive, db): # Emit the pre_sync signal for every application. for app in models.get_apps(): app_name = app.__name__.split('.')[-2] if verbosity >= 2: print("Running pre-sync handlers for application %s" % app_name) models.signals.pre_syncdb.send(sender=app, app=app, create_models=create_models, verbosity=verbosity, interactive=interactive, db=db) def emit_post_sync_signal(created_models, verbosity, interactive, db): # Emit the post_sync signal for every application. for app in models.get_apps(): Loading
django/db/models/signals.py +1 −0 Original line number Diff line number Diff line Loading @@ -12,6 +12,7 @@ post_save = Signal(providing_args=["instance", "raw", "created", "using", "updat pre_delete = Signal(providing_args=["instance", "using"], use_caching=True) post_delete = Signal(providing_args=["instance", "using"], use_caching=True) pre_syncdb = Signal(providing_args=["app", "create_models", "verbosity", "interactive", "db"]) post_syncdb = Signal(providing_args=["class", "app", "created_models", "verbosity", "interactive", "db"], use_caching=True) m2m_changed = Signal(providing_args=["action", "instance", "reverse", "model", "pk_set", "using"], use_caching=True)
docs/ref/signals.txt +47 −0 Original line number Diff line number Diff line Loading @@ -360,6 +360,53 @@ Management signals Signals sent by :doc:`django-admin </ref/django-admin>`. pre_syncdb ---------- .. data:: django.db.models.signals.pre_syncdb :module: Sent by the :djadmin:`syncdb` command before it starts to install an application. Any handlers that listen to this signal need to be written in a particular place: a ``management`` module in one of your :setting:`INSTALLED_APPS`. If handlers are registered anywhere else they may not be loaded by :djadmin:`syncdb`. Arguments sent with this signal: ``sender`` The ``models`` module that was just installed. That is, if :djadmin:`syncdb` just installed an app called ``"foo.bar.myapp"``, ``sender`` will be the ``foo.bar.myapp.models`` module. ``app`` Same as ``sender``. ``create_models`` A list of the model classes from any app which :djadmin:`syncdb` plans to create. ``verbosity`` Indicates how much information manage.py is printing on screen. See the :djadminopt:`--verbosity` flag for details. Functions which listen for :data:`pre_syncdb` should adjust what they output to the screen based on the value of this argument. ``interactive`` If ``interactive`` is ``True``, it's safe to prompt the user to input things on the command line. If ``interactive`` is ``False``, functions which listen for this signal should not try to prompt for anything. For example, the :mod:`django.contrib.auth` app only prompts to create a superuser when ``interactive`` is ``True``. ``db`` The alias of database on which a command will operate. post_syncdb ----------- Loading