Ticket #5065: post_reset_signal.patch

File post_reset_signal.patch, 2.2 KB (added by gav@…, 17 years ago)

Patch that provides post_reset signal against r5788.

  • django/core/management.py

    diff -x .svn -x '*.pyc' -rup django_orig/django/core/management.py django_live/django/core/management.py
    old new def _emit_post_sync_signal(created_model  
    499499            app=app, created_models=created_models,
    500500            verbosity=verbosity, interactive=interactive)
    501501
     502def _emit_post_reset_signal(app, interactive):
     503    from django.db import models
     504    from django.dispatch import dispatcher
     505    # Emit the post_reset signal for the given application.
     506    app_name = app.__name__.split('.')[-2]
     507    dispatcher.send(signal=models.signals.post_reset, sender=app,
     508        app=app, interactive=interactive)
     509
    502510def syncdb(verbosity=1, interactive=True):
    503511    "Creates the database tables for all apps in INSTALLED_APPS whose tables haven't already been created."
    504512    from django.db import backend, connection, transaction, models
    def reset(app, interactive=True):  
    679687
    680688    # First, try validating the models.
    681689    _check_for_validation_errors(app)
     690
     691    # Import the 'management' module within each installed app, to register
     692    # dispatcher events.
     693    for app_name in settings.INSTALLED_APPS:
     694        try:
     695            __import__(app_name + '.management', {}, {}, [''])
     696        except ImportError:
     697            pass
     698   
    682699    sql_list = get_sql_reset(app)
    683700
    684701    if interactive:
    The full error: """ % (app_name, app_nam  
    707724            transaction.rollback_unless_managed()
    708725            sys.exit(1)
    709726        transaction.commit_unless_managed()
     727
     728        _emit_post_reset_signal(app, interactive)
    710729    else:
    711730        print "Reset cancelled."
    712731reset.help_doc = "Executes ``sqlreset`` for the given app(s) in the current database."
  • django/db/models/signals.py

    diff -x .svn -x '*.pyc' -rup django_orig/django/db/models/signals.py django_live/django/db/models/signals.py
    old new pre_delete = object()  
    1010post_delete = object()
    1111
    1212post_syncdb = object()
     13post_reset = object()
Back to Top