Ticket #6064: 6064-using-signals.diff

File 6064-using-signals.diff, 7.8 KB (added by floguy, 8 years ago)

Changed the implementation method to emit a signal instead of execute a tuple from the settings.

  • django/db/backends/ado_mssql/base.py

     
    55"""
    66
    77from django.db.backends import BaseDatabaseWrapper, BaseDatabaseFeatures, BaseDatabaseOperations, util
     8from django.dispatch import dispatcher
     9from django.db.backends import signals
    810try:
    911    import adodbapi as Database
    1012except ImportError, e:
     
    109111            # TODO: Handle DATABASE_PORT.
    110112            conn_string = "PROVIDER=SQLOLEDB;DATA SOURCE=%s;UID=%s;PWD=%s;DATABASE=%s" % (settings.DATABASE_HOST, settings.DATABASE_USER, settings.DATABASE_PASSWORD, settings.DATABASE_NAME)
    111113            self.connection = Database.connect(conn_string)
     114        dispatcher.send(signal=signals.connection_created, sender=self.__class__)
    112115        return self.connection.cursor()
  • django/db/backends/mysql_old/base.py

     
    55"""
    66
    77from django.db.backends import BaseDatabaseWrapper, BaseDatabaseFeatures, BaseDatabaseOperations, util
     8from django.dispatch import dispatcher
     9from django.db.backends import signals
    810from django.utils.encoding import force_unicode
    911try:
    1012    import MySQLdb as Database
     
    194196                    self.connection.set_character_set('utf8')
    195197        else:
    196198            cursor = self.connection.cursor()
     199        dispatcher.send(signal=signals.connection_created, sender=self.__class__)
    197200        return cursor
    198201
    199202    def make_debug_cursor(self, cursor):
  • django/db/backends/postgresql/base.py

     
    66
    77from django.utils.encoding import smart_str, smart_unicode
    88from django.db.backends import BaseDatabaseWrapper, BaseDatabaseFeatures, util
     9from django.dispatch import dispatcher
     10from django.db.backends import signals
    911from django.db.backends.postgresql.operations import DatabaseOperations
    1012try:
    1113    import psycopg as Database
     
    102104            cursor.execute("SET TIME ZONE %s", [settings.TIME_ZONE])
    103105        cursor.execute("SET client_encoding to 'UNICODE'")
    104106        cursor = UnicodeCursorWrapper(cursor, 'utf-8')
     107        dispatcher.send(signal=signals.connection_created, sender=self.__class__)
    105108        return cursor
    106109
    107110def typecast_string(s):
  • django/db/backends/sqlite3/base.py

     
    77"""
    88
    99from django.db.backends import BaseDatabaseWrapper, BaseDatabaseFeatures, BaseDatabaseOperations, util
     10from django.dispatch import dispatcher
     11from django.db.backends import signals
    1012try:
    1113    try:
    1214        from sqlite3 import dbapi2 as Database
     
    112114            self.connection.create_function("django_extract", 2, _sqlite_extract)
    113115            self.connection.create_function("django_date_trunc", 2, _sqlite_date_trunc)
    114116            self.connection.create_function("regexp", 2, _sqlite_regexp)
     117        dispatcher.send(signal=signals.connection_created, sender=self.__class__)
    115118        return self.connection.cursor(factory=SQLiteCursorWrapper)
    116119
    117120    def close(self):
  • django/db/backends/mysql/base.py

     
    55"""
    66
    77from django.db.backends import BaseDatabaseWrapper, BaseDatabaseFeatures, BaseDatabaseOperations, util
     8from django.dispatch import dispatcher
     9from django.db.backends import signals
    810try:
    911    import MySQLdb as Database
    1012except ImportError, e:
     
    180182                kwargs['port'] = int(settings.DATABASE_PORT)
    181183            kwargs.update(self.options)
    182184            self.connection = Database.connect(**kwargs)
     185        dispatcher.send(signal=signals.connection_created, sender=self.__class__)
    183186        cursor = self.connection.cursor()
    184187        return cursor
    185188
  • django/db/backends/oracle/base.py

     
    55"""
    66
    77from django.db.backends import BaseDatabaseWrapper, BaseDatabaseFeatures, BaseDatabaseOperations, util
     8from django.dispatch import dispatcher
     9from django.db.backends import signals
    810from django.utils.datastructures import SortedDict
    911from django.utils.encoding import smart_str, force_unicode
    1012import datetime
     
    432434        # Set oracle date to ansi date format.
    433435        cursor.execute("ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD'")
    434436        cursor.execute("ALTER SESSION SET NLS_TIMESTAMP_FORMAT = 'YYYY-MM-DD HH24:MI:SS.FF'")
     437        dispatcher.send(signal=signals.connection_created, sender=self.__class__)
    435438        return cursor
    436439
    437440class FormatStylePlaceholderCursor(Database.Cursor):
  • django/db/backends/signals.py

     
     1connection_created = object()
     2 No newline at end of file
  • django/db/backends/postgresql_psycopg2/base.py

     
    66
    77from django.db.backends import BaseDatabaseWrapper, BaseDatabaseFeatures
    88from django.db.backends.postgresql.operations import DatabaseOperations as PostgresqlDatabaseOperations
     9from django.dispatch import dispatcher
     10from django.db.backends import signals
    911from django.utils.safestring import SafeUnicode
    1012try:
    1113    import psycopg2 as Database
     
    7375        cursor.tzinfo_factory = None
    7476        if set_tz:
    7577            cursor.execute("SET TIME ZONE %s", [settings.TIME_ZONE])
     78        dispatcher.send(signal=signals.connection_created, sender=self.__class__)
    7679        return cursor
  • tests/modeltests/signals/models.py

     
    22Testing signals before/after saving and deleting.
    33"""
    44
     5from django.dispatch import dispatcher
    56from django.db import models
    6 from django.dispatch import dispatcher
     7from django.db import connection
     8from django.db.backends.signals import connection_created
    79
    810class Person(models.Model):
    911    first_name = models.CharField(max_length=20)
     
    3234    print 'post_delete signal,', instance
    3335    print 'instance.id is None: %s' % (instance.id == None) 
    3436
     37def connection_created_test(sender, **kwargs):
     38    print 'connection_created signal'
     39
    3540__test__ = {'API_TESTS':"""
     41>>> dispatcher.connect(connection_created_test, signal=connection_created)
    3642>>> dispatcher.connect(pre_save_test, signal=models.signals.pre_save)
    3743>>> dispatcher.connect(post_save_test, signal=models.signals.post_save)
    3844>>> dispatcher.connect(pre_delete_test, signal=models.signals.pre_delete)
    3945>>> dispatcher.connect(post_delete_test, signal=models.signals.post_delete)
    4046
     47>>> cursor = connection.cursor()
     48connection_created signal
     49
     50>>> dispatcher.disconnect(connection_created_test, signal=connection_created)
     51>>> cursor = connection.cursor()
     52
    4153>>> p1 = Person(first_name='John', last_name='Smith')
    4254>>> p1.save()
    4355pre_save signal, John Smith
Back to Top