Ticket #7561: final_post_sync.diff

File final_post_sync.diff, 3.1 KB (added by aneil, 14 years ago)

Adds a signal django.db.models.signals.final_post_syncdb as suggested in comments (see also ticket 13826)

  • django/db/models/signals.py

     
    1212post_delete = Signal(providing_args=["instance"])
    1313
    1414post_syncdb = Signal(providing_args=["class", "app", "created_models", "verbosity", "interactive"])
     15final_post_syncdb = Signal(providing_args=["class", "app", "created_models", "verbosity", "interactive"])
    1516
    1617m2m_changed = Signal(providing_args=["action", "instance", "reverse", "model", "pk_set"])
  • django/core/management/commands/syncdb.py

     
    44from django.conf import settings
    55from django.core.management.base import NoArgsCommand
    66from django.core.management.color import no_style
    7 from django.core.management.sql import custom_sql_for_model, emit_post_sync_signal
     7from django.core.management.sql import custom_sql_for_model, emit_post_sync_signal,emit_final_post_sync_signal
    88from django.db import connections, router, transaction, models, DEFAULT_DB_ALIAS
    99from django.utils.datastructures import SortedDict
    1010from django.utils.importlib import import_module
     
    148148                        else:
    149149                            transaction.commit_unless_managed(using=db)
    150150
     151# Send the post_syncdb signal, so individual apps can do whatever they need
     152        # to do at this point.
     153        emit_final_post_sync_signal(created_models, verbosity, interactive, db)
     154
     155        # The connection may have been closed by a syncdb handler.
     156        cursor = connection.cursor()
     157
    151158        from django.core.management import call_command
    152159        call_command('loaddata', 'initial_data', verbosity=verbosity, database=db)
  • django/core/management/sql.py

     
    175175
    176176
    177177def emit_post_sync_signal(created_models, verbosity, interactive, db):
     178    return emit_signal_to_models(models.signals.post_syncdb,"post-sync",created_models,verbosity,interactive,db)
     179
     180def emit_final_post_sync_signal(created_models,verbosity,interactive,db):
     181    return emit_signal_to_models(models.signals.final_post_syncdb,"final-post-sync",created_models,verbosity,interactive,db)
     182
     183def emit_signal_to_models(signal,signal_name,created_models,verbosity,interactive,db):
    178184    # Emit the post_sync signal for every application.
    179185    for app in models.get_apps():
    180186        app_name = app.__name__.split('.')[-2]
    181187        if verbosity >= 2:
    182             print "Running post-sync handlers for application", app_name
    183         models.signals.post_syncdb.send(sender=app, app=app,
     188            print "Running", signal_name,"handlers for application", app_name
     189        signal.send(sender=app, app=app,
    184190            created_models=created_models, verbosity=verbosity,
    185191            interactive=interactive, db=db)
Back to Top