Ticket #4528: db_pre_sync_r6799.patch

File db_pre_sync_r6799.patch, 2.4 KB (added by George Vilches, 17 years ago)
  • django/db/models/signals.py

     
    99pre_delete = object()
    1010post_delete = object()
    1111
     12pre_syncdb = object()
    1213post_syncdb = object()
  • django/core/management/commands/syncdb.py

     
    2121    def handle_noargs(self, **options):
    2222        from django.db import connection, transaction, models
    2323        from django.conf import settings
    24         from django.core.management.sql import table_list, installed_models, sql_model_create, sql_for_pending_references, many_to_many_sql_for_model, custom_sql_for_model, sql_indexes_for_model, emit_post_sync_signal
     24        from django.core.management.sql import table_list, installed_models, sql_model_create, sql_for_pending_references, many_to_many_sql_for_model, custom_sql_for_model, sql_indexes_for_model, emit_post_sync_signal, emit_pre_sync_signal
    2525
    2626        verbosity = int(options.get('verbosity', 1))
    2727        interactive = options.get('interactive')
     
    3636            except ImportError:
    3737                pass
    3838
     39        emit_pre_sync_signal(verbosity, interactive)
    3940        cursor = connection.cursor()
    4041
    4142        if connection.features.uses_case_insensitive_names:
  • django/core/management/sql.py

     
    473473            )
    474474    return output
    475475
     476def emit_pre_sync_signal(verbosity, interactive):
     477    from django.db import models
     478    from django.dispatch import dispatcher
     479    # Emit the pre_sync signal for every application.
     480    for app in models.get_apps():
     481        app_name = app.__name__.split('.')[-2]
     482        if verbosity >= 2:
     483            print "Running pre-sync handlers for application", app_name
     484        dispatcher.send(signal=models.signals.pre_syncdb, sender=app,
     485            app=app, verbosity=verbosity, interactive=interactive)
     486
    476487def emit_post_sync_signal(created_models, verbosity, interactive):
    477488    from django.db import models
    478489    from django.dispatch import dispatcher
Back to Top