Ticket #6064: 6064-using-signals.diff
File 6064-using-signals.diff, 7.8 KB (added by , 17 years ago) |
---|
-
django/db/backends/ado_mssql/base.py
5 5 """ 6 6 7 7 from django.db.backends import BaseDatabaseWrapper, BaseDatabaseFeatures, BaseDatabaseOperations, util 8 from django.dispatch import dispatcher 9 from django.db.backends import signals 8 10 try: 9 11 import adodbapi as Database 10 12 except ImportError, e: … … 109 111 # TODO: Handle DATABASE_PORT. 110 112 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) 111 113 self.connection = Database.connect(conn_string) 114 dispatcher.send(signal=signals.connection_created, sender=self.__class__) 112 115 return self.connection.cursor() -
django/db/backends/mysql_old/base.py
5 5 """ 6 6 7 7 from django.db.backends import BaseDatabaseWrapper, BaseDatabaseFeatures, BaseDatabaseOperations, util 8 from django.dispatch import dispatcher 9 from django.db.backends import signals 8 10 from django.utils.encoding import force_unicode 9 11 try: 10 12 import MySQLdb as Database … … 194 196 self.connection.set_character_set('utf8') 195 197 else: 196 198 cursor = self.connection.cursor() 199 dispatcher.send(signal=signals.connection_created, sender=self.__class__) 197 200 return cursor 198 201 199 202 def make_debug_cursor(self, cursor): -
django/db/backends/postgresql/base.py
6 6 7 7 from django.utils.encoding import smart_str, smart_unicode 8 8 from django.db.backends import BaseDatabaseWrapper, BaseDatabaseFeatures, util 9 from django.dispatch import dispatcher 10 from django.db.backends import signals 9 11 from django.db.backends.postgresql.operations import DatabaseOperations 10 12 try: 11 13 import psycopg as Database … … 102 104 cursor.execute("SET TIME ZONE %s", [settings.TIME_ZONE]) 103 105 cursor.execute("SET client_encoding to 'UNICODE'") 104 106 cursor = UnicodeCursorWrapper(cursor, 'utf-8') 107 dispatcher.send(signal=signals.connection_created, sender=self.__class__) 105 108 return cursor 106 109 107 110 def typecast_string(s): -
django/db/backends/sqlite3/base.py
7 7 """ 8 8 9 9 from django.db.backends import BaseDatabaseWrapper, BaseDatabaseFeatures, BaseDatabaseOperations, util 10 from django.dispatch import dispatcher 11 from django.db.backends import signals 10 12 try: 11 13 try: 12 14 from sqlite3 import dbapi2 as Database … … 112 114 self.connection.create_function("django_extract", 2, _sqlite_extract) 113 115 self.connection.create_function("django_date_trunc", 2, _sqlite_date_trunc) 114 116 self.connection.create_function("regexp", 2, _sqlite_regexp) 117 dispatcher.send(signal=signals.connection_created, sender=self.__class__) 115 118 return self.connection.cursor(factory=SQLiteCursorWrapper) 116 119 117 120 def close(self): -
django/db/backends/mysql/base.py
5 5 """ 6 6 7 7 from django.db.backends import BaseDatabaseWrapper, BaseDatabaseFeatures, BaseDatabaseOperations, util 8 from django.dispatch import dispatcher 9 from django.db.backends import signals 8 10 try: 9 11 import MySQLdb as Database 10 12 except ImportError, e: … … 180 182 kwargs['port'] = int(settings.DATABASE_PORT) 181 183 kwargs.update(self.options) 182 184 self.connection = Database.connect(**kwargs) 185 dispatcher.send(signal=signals.connection_created, sender=self.__class__) 183 186 cursor = self.connection.cursor() 184 187 return cursor 185 188 -
django/db/backends/oracle/base.py
5 5 """ 6 6 7 7 from django.db.backends import BaseDatabaseWrapper, BaseDatabaseFeatures, BaseDatabaseOperations, util 8 from django.dispatch import dispatcher 9 from django.db.backends import signals 8 10 from django.utils.datastructures import SortedDict 9 11 from django.utils.encoding import smart_str, force_unicode 10 12 import datetime … … 432 434 # Set oracle date to ansi date format. 433 435 cursor.execute("ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD'") 434 436 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__) 435 438 return cursor 436 439 437 440 class FormatStylePlaceholderCursor(Database.Cursor): -
django/db/backends/signals.py
1 connection_created = object() 2 No newline at end of file -
django/db/backends/postgresql_psycopg2/base.py
6 6 7 7 from django.db.backends import BaseDatabaseWrapper, BaseDatabaseFeatures 8 8 from django.db.backends.postgresql.operations import DatabaseOperations as PostgresqlDatabaseOperations 9 from django.dispatch import dispatcher 10 from django.db.backends import signals 9 11 from django.utils.safestring import SafeUnicode 10 12 try: 11 13 import psycopg2 as Database … … 73 75 cursor.tzinfo_factory = None 74 76 if set_tz: 75 77 cursor.execute("SET TIME ZONE %s", [settings.TIME_ZONE]) 78 dispatcher.send(signal=signals.connection_created, sender=self.__class__) 76 79 return cursor -
tests/modeltests/signals/models.py
2 2 Testing signals before/after saving and deleting. 3 3 """ 4 4 5 from django.dispatch import dispatcher 5 6 from django.db import models 6 from django.dispatch import dispatcher 7 from django.db import connection 8 from django.db.backends.signals import connection_created 7 9 8 10 class Person(models.Model): 9 11 first_name = models.CharField(max_length=20) … … 32 34 print 'post_delete signal,', instance 33 35 print 'instance.id is None: %s' % (instance.id == None) 34 36 37 def connection_created_test(sender, **kwargs): 38 print 'connection_created signal' 39 35 40 __test__ = {'API_TESTS':""" 41 >>> dispatcher.connect(connection_created_test, signal=connection_created) 36 42 >>> dispatcher.connect(pre_save_test, signal=models.signals.pre_save) 37 43 >>> dispatcher.connect(post_save_test, signal=models.signals.post_save) 38 44 >>> dispatcher.connect(pre_delete_test, signal=models.signals.pre_delete) 39 45 >>> dispatcher.connect(post_delete_test, signal=models.signals.post_delete) 40 46 47 >>> cursor = connection.cursor() 48 connection_created signal 49 50 >>> dispatcher.disconnect(connection_created_test, signal=connection_created) 51 >>> cursor = connection.cursor() 52 41 53 >>> p1 = Person(first_name='John', last_name='Smith') 42 54 >>> p1.save() 43 55 pre_save signal, John Smith