Author: phd
Date: Sat Nov 13 10:26:37 2010
New Revision: 4270
Log:
Major API change: all signals are sent with the instance (or the class)
as the first parameter. The following signals were changed:
RowCreateSignal, RowCreatedSignal, DeleteColumnSignal.
Modified:
SQLObject/trunk/docs/News.txt
SQLObject/trunk/sqlobject/events.py
SQLObject/trunk/sqlobject/main.py
SQLObject/trunk/sqlobject/tests/test_events.py
Modified: SQLObject/trunk/docs/News.txt
==============================================================================
--- SQLObject/trunk/docs/News.txt Fri Oct 15 07:04:19 2010 (r4269)
+++ SQLObject/trunk/docs/News.txt Sat Nov 13 10:26:37 2010 (r4270)
@@ -13,6 +13,10 @@
Features & Interface
--------------------
+* Major API change: all signals are sent with the instance (or the class)
+ as the first parameter. The following signals were changed:
+ RowCreateSignal, RowCreatedSignal, DeleteColumnSignal.
+
SQLObject 0.14.1
================
Modified: SQLObject/trunk/sqlobject/events.py
==============================================================================
--- SQLObject/trunk/sqlobject/events.py Fri Oct 15 07:04:19 2010 (r4269)
+++ SQLObject/trunk/sqlobject/events.py Sat Nov 13 10:26:37 2010 (r4270)
@@ -70,7 +70,7 @@
class RowCreateSignal(Signal):
"""
Called before an instance is created, with the class as the
- sender. Called with the arguments ``(kwargs, post_funcs)``.
+ sender. Called with the arguments ``(instance, kwargs, post_funcs)``.
There may be a ``connection`` argument. ``kwargs``may be usefully
modified. ``post_funcs`` is a list of callbacks, intended to have
functions appended to it, and are called with the arguments
@@ -82,7 +82,7 @@
class RowCreatedSignal(Signal):
"""
Called after an instance is created, with the class as the
- sender. Called with the arguments ``(kwargs, post_funcs)``.
+ sender. Called with the arguments ``(instance, kwargs, post_funcs)``.
There may be a ``connection`` argument. ``kwargs``may be usefully
modified. ``post_funcs`` is a list of callbacks, intended to have
functions appended to it, and are called with the arguments
Modified: SQLObject/trunk/sqlobject/main.py
==============================================================================
--- SQLObject/trunk/sqlobject/main.py Fri Oct 15 07:04:19 2010 (r4269)
+++ SQLObject/trunk/sqlobject/main.py Sat Nov 13 10:26:37 2010 (r4270)
@@ -461,8 +461,8 @@
raise IndexError(
"Column with definition %r not found" % column)
post_funcs = []
- cls.send(events.DeleteColumnSignal, connection, column.name, column,
- post_funcs)
+ cls.send(events.DeleteColumnSignal, cls.soClass, connection,
+ column.name, column, post_funcs)
name = column.name
del sqlmeta.columns[name]
del sqlmeta.columnDefinitions[name]
@@ -1207,7 +1207,7 @@
return
post_funcs = []
- self.sqlmeta.send(events.RowCreateSignal, kw, post_funcs)
+ self.sqlmeta.send(events.RowCreateSignal, self, kw, post_funcs)
# Pass the connection object along if we were given one.
if kw.has_key('connection'):
@@ -1303,7 +1303,7 @@
post_funcs = []
kw = dict([('class', self.__class__), ('id', id)])
def _send_RowCreatedSignal():
- self.sqlmeta.send(events.RowCreatedSignal, kw, post_funcs)
+ self.sqlmeta.send(events.RowCreatedSignal, self, kw, post_funcs)
for func in post_funcs:
func(self)
_postponed_local.postponed_calls.append(_send_RowCreatedSignal)
Modified: SQLObject/trunk/sqlobject/tests/test_events.py
==============================================================================
--- SQLObject/trunk/sqlobject/tests/test_events.py Fri Oct 15 07:04:19 2010 (r4269)
+++ SQLObject/trunk/sqlobject/tests/test_events.py Sat Nov 13 10:26:37 2010 (r4270)
@@ -37,10 +37,12 @@
def test_row_create():
setupClass(EventTester)
watcher = make_listen(events.RowCreateSignal)
- EventTester(name='foo')
- EventTester(name='bar')
+ row1 = EventTester(name='foo')
+ row2 = EventTester(name='bar')
assert len(watcher.log) == 2
- assert watcher.log[0] == ({'name': 'foo'}, [])
+ assert watcher.log == [
+ (row1, {'name': 'foo'}, []),
+ (row2, {'name': 'bar'}, [])]
def test_row_destroy():
setupClass(EventTester)
@@ -102,9 +104,11 @@
c = IntCol()
def _query(instance):
- InheritableEventTestA.get(instance.id)
+ row = InheritableEventTestA.get(instance.id)
+ assert isinstance(row, InheritableEventTestC)
+ assert row.c == 3
-def _signal(kwargs, postfuncs):
+def _signal(instance, kwargs, postfuncs):
postfuncs.append(_query)
def test_inheritance_row_created():
|