Removed pre_syncdb and post_syncdb signals per deprecation timeline.
This commit is contained in:
parent
fed25f1105
commit
f4f24d30e0
|
@ -102,4 +102,4 @@ Are you sure you want to do this?
|
|||
all_models = []
|
||||
for app_config in apps.get_app_configs():
|
||||
all_models.extend(router.get_migratable_models(app_config, database, include_auto_created=True))
|
||||
emit_post_migrate_signal(set(all_models), verbosity, interactive, database)
|
||||
emit_post_migrate_signal(verbosity, interactive, database)
|
||||
|
|
|
@ -3,7 +3,6 @@ from __future__ import unicode_literals
|
|||
|
||||
from collections import OrderedDict
|
||||
from importlib import import_module
|
||||
import itertools
|
||||
import time
|
||||
import traceback
|
||||
import warnings
|
||||
|
@ -163,17 +162,13 @@ class Command(BaseCommand):
|
|||
% (targets[0][1], targets[0][0])
|
||||
)
|
||||
|
||||
emit_pre_migrate_signal(self.verbosity, self.interactive, connection.alias)
|
||||
|
||||
# Run the syncdb phase.
|
||||
# If you ever manage to get rid of this, I owe you many, many drinks.
|
||||
# Note that pre_migrate is called from inside here, as it needs
|
||||
# the list of models about to be installed.
|
||||
if run_syncdb and executor.loader.unmigrated_apps:
|
||||
if self.verbosity >= 1:
|
||||
self.stdout.write(self.style.MIGRATE_HEADING("Synchronizing apps without migrations:"))
|
||||
created_models = self.sync_apps(connection, executor.loader.unmigrated_apps)
|
||||
else:
|
||||
created_models = []
|
||||
emit_pre_migrate_signal([], self.verbosity, self.interactive, connection.alias)
|
||||
self.sync_apps(connection, executor.loader.unmigrated_apps)
|
||||
|
||||
# The test runner requires us to flush after a syncdb but before migrations,
|
||||
# so do that here.
|
||||
|
@ -214,7 +209,7 @@ class Command(BaseCommand):
|
|||
|
||||
# Send the post_migrate signal, so individual apps can do whatever they need
|
||||
# to do at this point.
|
||||
emit_post_migrate_signal(created_models, self.verbosity, self.interactive, connection.alias)
|
||||
emit_post_migrate_signal(self.verbosity, self.interactive, connection.alias)
|
||||
|
||||
def migration_progress_callback(self, action, migration=None, fake=False):
|
||||
if self.verbosity >= 1:
|
||||
|
@ -279,9 +274,6 @@ class Command(BaseCommand):
|
|||
for app_name, model_list in all_models
|
||||
)
|
||||
|
||||
create_models = set(itertools.chain(*manifest.values()))
|
||||
emit_pre_migrate_signal(create_models, self.verbosity, self.interactive, connection.alias)
|
||||
|
||||
# Create the tables for each model
|
||||
if self.verbosity >= 1:
|
||||
self.stdout.write(" Creating tables...\n")
|
||||
|
|
|
@ -242,7 +242,7 @@ def custom_sql_for_model(model, style, connection):
|
|||
return output
|
||||
|
||||
|
||||
def emit_pre_migrate_signal(create_models, verbosity, interactive, db):
|
||||
def emit_pre_migrate_signal(verbosity, interactive, db):
|
||||
# Emit the pre_migrate signal for every application.
|
||||
for app_config in apps.get_app_configs():
|
||||
if app_config.models_module is None:
|
||||
|
@ -255,17 +255,9 @@ def emit_pre_migrate_signal(create_models, verbosity, interactive, db):
|
|||
verbosity=verbosity,
|
||||
interactive=interactive,
|
||||
using=db)
|
||||
# For backwards-compatibility -- remove in Django 1.9.
|
||||
models.signals.pre_syncdb.send(
|
||||
sender=app_config.models_module,
|
||||
app=app_config.models_module,
|
||||
create_models=create_models,
|
||||
verbosity=verbosity,
|
||||
interactive=interactive,
|
||||
db=db)
|
||||
|
||||
|
||||
def emit_post_migrate_signal(created_models, verbosity, interactive, db):
|
||||
def emit_post_migrate_signal(verbosity, interactive, db):
|
||||
# Emit the post_migrate signal for every application.
|
||||
for app_config in apps.get_app_configs():
|
||||
if app_config.models_module is None:
|
||||
|
@ -278,11 +270,3 @@ def emit_post_migrate_signal(created_models, verbosity, interactive, db):
|
|||
verbosity=verbosity,
|
||||
interactive=interactive,
|
||||
using=db)
|
||||
# For backwards-compatibility -- remove in Django 1.9.
|
||||
models.signals.post_syncdb.send(
|
||||
sender=app_config.models_module,
|
||||
app=app_config.models_module,
|
||||
created_models=created_models,
|
||||
verbosity=verbosity,
|
||||
interactive=interactive,
|
||||
db=db)
|
||||
|
|
|
@ -67,6 +67,3 @@ m2m_changed = ModelSignal(
|
|||
|
||||
pre_migrate = Signal(providing_args=["app_config", "verbosity", "interactive", "using"])
|
||||
post_migrate = Signal(providing_args=["app_config", "verbosity", "interactive", "using"])
|
||||
|
||||
pre_syncdb = Signal(providing_args=["app", "create_models", "verbosity", "interactive", "db"])
|
||||
post_syncdb = Signal(providing_args=["class", "app", "created_models", "verbosity", "interactive", "db"])
|
||||
|
|
|
@ -405,52 +405,6 @@ Arguments sent with this signal:
|
|||
``using``
|
||||
The alias of database on which a command will operate.
|
||||
|
||||
pre_syncdb
|
||||
----------
|
||||
|
||||
.. data:: django.db.models.signals.pre_syncdb
|
||||
:module:
|
||||
|
||||
.. deprecated:: 1.7
|
||||
|
||||
This signal has been replaced by :data:`~django.db.models.signals.pre_migrate`.
|
||||
|
||||
Sent by the :djadmin:`syncdb` command before it starts to install an
|
||||
application.
|
||||
|
||||
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_migrate
|
||||
------------
|
||||
|
||||
|
@ -518,67 +472,6 @@ For example, you could register a callback in an
|
|||
when settings are overridden) and such signals should be connected for each
|
||||
new ``AppConfig`` instance.
|
||||
|
||||
post_syncdb
|
||||
-----------
|
||||
|
||||
.. data:: django.db.models.signals.post_syncdb
|
||||
:module:
|
||||
|
||||
.. deprecated:: 1.7
|
||||
|
||||
This signal has been replaced by :data:`~django.db.models.signals.post_migrate`.
|
||||
|
||||
Sent by the :djadmin:`syncdb` command after it installs an application, and the
|
||||
:djadmin:`flush` command.
|
||||
|
||||
It is important that handlers of this signal perform idempotent changes (e.g.
|
||||
no database alterations) as this may cause the :djadmin:`flush` management
|
||||
command to fail if it also ran during the :djadmin:`syncdb` command.
|
||||
|
||||
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``.
|
||||
|
||||
``created_models``
|
||||
A list of the model classes from any app which :djadmin:`syncdb` has
|
||||
created so far.
|
||||
|
||||
``verbosity``
|
||||
Indicates how much information manage.py is printing on screen. See
|
||||
the :djadminopt:`--verbosity` flag for details.
|
||||
|
||||
Functions which listen for :data:`post_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 database alias used for synchronization. Defaults to the ``default``
|
||||
database.
|
||||
|
||||
For example, ``yourapp/management/__init__.py`` could be written like::
|
||||
|
||||
from django.db.models.signals import post_syncdb
|
||||
import yourapp.models
|
||||
|
||||
def my_callback(sender, **kwargs):
|
||||
# Your specific logic here
|
||||
pass
|
||||
|
||||
post_syncdb.connect(my_callback, sender=yourapp.models)
|
||||
|
||||
Request/response signals
|
||||
========================
|
||||
|
||||
|
|
|
@ -51,8 +51,8 @@ but a few of the key features are:
|
|||
* A new ``makemigrations`` command provides an easy way to autodetect changes
|
||||
to your models and make migrations for them.
|
||||
|
||||
:data:`~django.db.models.signals.pre_syncdb` and
|
||||
:data:`~django.db.models.signals.post_syncdb` have been deprecated,
|
||||
``django.db.models.signals.pre_syncdb`` and
|
||||
``django.db.models.signals.post_syncdb`` have been deprecated,
|
||||
to be replaced by :data:`~django.db.models.signals.pre_migrate` and
|
||||
:data:`~django.db.models.signals.post_migrate` respectively. These
|
||||
new signals have slightly different arguments. Check the
|
||||
|
|
Loading…
Reference in New Issue