Ticket #11398: pre_syncdb.diff

File pre_syncdb.diff, 2.8 KB (added by yrashk@…, 15 years ago)

Patch

  • django/core/management/commands/syncdb.py

    a b class Command(NoArgsCommand):  
    1919    def handle_noargs(self, **options):
    2020        from django.db import connection, transaction, models
    2121        from django.conf import settings
    22         from django.core.management.sql import custom_sql_for_model, emit_post_sync_signal
     22        from django.core.management.sql import custom_sql_for_model, emit_post_sync_signal, emit_pre_sync_signal
    2323
    2424        verbosity = int(options.get('verbosity', 1))
    2525        interactive = options.get('interactive')
    class Command(NoArgsCommand):  
    5454        created_models = set()
    5555        pending_references = {}
    5656
     57        models_to_be_created = []
     58        for app in models.get_apps():
     59            app_name = app.__name__.split('.')[-2]
     60            model_list = models.get_models(app)
     61            for model in model_list:
     62                 if connection.introspection.table_name_converter(model._meta.db_table) in tables:
     63                    continue
     64                 models_to_be_created.append(model)
     65
     66        # Send the post_syncdb signal, so individual apps can do whatever they need
     67        # to do at this point.
     68        emit_pre_sync_signal(models_to_be_created, verbosity, interactive)
     69                       
     70
    5771        # Create the tables for each model
    5872        for app in models.get_apps():
    5973            app_name = app.__name__.split('.')[-2]
  • django/core/management/sql.py

    diff --git a/django/core/management/sql.py b/django/core/management/sql.py
    a b def emit_post_sync_signal(created_models, verbosity, interactive):  
    203203        models.signals.post_syncdb.send(sender=app, app=app,
    204204            created_models=created_models, verbosity=verbosity,
    205205            interactive=interactive)
     206
     207def emit_pre_sync_signal(models_to_be_created, verbosity, interactive):
     208    from django.db import models
     209    from django.dispatch import dispatcher
     210    # Emit the pre_sync signal for every application.
     211    for app in models.get_apps():
     212        app_name = app.__name__.split('.')[-2]
     213        if verbosity >= 2:
     214           print "Running pre-sync handlers for application", app_name
     215        models.signals.pre_syncdb.send(sender=app, app=app,
     216            models_to_be_created=models_to_be_created, verbosity=verbosity,
     217            interactive=interactive)
  • django/db/models/signals.py

    diff --git a/django/db/models/signals.py b/django/db/models/signals.py
    a b pre_delete = Signal(providing_args=["instance"])  
    1212post_delete = Signal(providing_args=["instance"])
    1313
    1414post_syncdb = Signal(providing_args=["class", "app", "created_models", "verbosity", "interactive"])
     15pre_syncdb = Signal(providing_args=["class", "app", "models_to_be_created", "verbosity", "interactive"])
Back to Top