Author: phd
Date: 2008-01-30 06:35:33 -0700 (Wed, 30 Jan 2008)
New Revision: 3233
Modified:
SQLObject/trunk/docs/DeveloperGuide.txt
SQLObject/trunk/docs/News.txt
SQLObject/trunk/sqlobject/events.py
SQLObject/trunk/sqlobject/main.py
SQLObject/trunk/sqlobject/tests/test_events.py
Log:
A patch by Diez B. Roggisch <die...@ar...>:
RowDestroySignal is send on destroying an SQLObject instance; postfunctions
are run after the row has been destroyed.
Modified: SQLObject/trunk/docs/DeveloperGuide.txt
===================================================================
--- SQLObject/trunk/docs/DeveloperGuide.txt 2008-01-30 13:33:02 UTC (rev 3232)
+++ SQLObject/trunk/docs/DeveloperGuide.txt 2008-01-30 13:35:33 UTC (rev 3233)
@@ -149,7 +149,7 @@
its `getting started`_ document for more.
.. __: http://codespeak.net/py/current/doc/test.html
-.. _getting started: http://codespeak.net/py/current/doc/getting-started.html
+.. _getting started: http://codespeak.net/py/dist/test.html#starting-point-py-test-command-line-tool
To actually run the test, you have to give it a database to connect
to. You do this with the ``TESTDB`` environmental variable (right now
@@ -163,7 +163,7 @@
the test module ``tests/test_modulename.py`` -- only modules that
start with ``test_`` will be picked up by py.test.
-The "framework" for testing is in ``tests/dbtest``. There's a couple
+The "framework" for testing is in ``tests/dbtest``. There's a couple of
important functions:
``setupClass(soClass)`` creates the tables for the class. It tries to
Modified: SQLObject/trunk/docs/News.txt
===================================================================
--- SQLObject/trunk/docs/News.txt 2008-01-30 13:33:02 UTC (rev 3232)
+++ SQLObject/trunk/docs/News.txt 2008-01-30 13:35:33 UTC (rev 3233)
@@ -63,6 +63,9 @@
considered equal is they have the same id; other methods return
NotImplemented.
+* RowDestroySignal is send on destroying an SQLObject instance; postfunctions
+ are run after the row has been destroyed.
+
* Changed the implementation type in BoolCol under SQLite from TINYINT to
BOOLEAN and made fromDatabase machinery to recognize it.
Modified: SQLObject/trunk/sqlobject/events.py
===================================================================
--- SQLObject/trunk/sqlobject/events.py 2008-01-30 13:33:02 UTC (rev 3232)
+++ SQLObject/trunk/sqlobject/events.py 2008-01-30 13:35:33 UTC (rev 3233)
@@ -97,7 +97,14 @@
class RowDestroySignal(Signal):
"""
Called before an instance is deleted. Sender is the instance's
- class. Arguments are ``(instance)``. You cannot cancel the delete,
+ class. Arguments are ``(instance, post_funcs)``.
+
+ ``post_funcs`` is a list of callbacks, intended to have
+ functions appended to it, and are called without arguments. If
+ any of the post_funcs raises an exception, the deletion is only
+ affected if this will prevent a commit.
+
+ You cannot cancel the delete,
but you can raise an exception (which will probably cancel the
delete, but also cause an uncaught exception if not expected).
Modified: SQLObject/trunk/sqlobject/main.py
===================================================================
--- SQLObject/trunk/sqlobject/main.py 2008-01-30 13:33:02 UTC (rev 3232)
+++ SQLObject/trunk/sqlobject/main.py 2008-01-30 13:35:33 UTC (rev 3233)
@@ -1464,7 +1464,8 @@
clearTable = classmethod(clearTable)
def destroySelf(self):
- self.sqlmeta.send(events.RowDestroySignal, self)
+ post_funcs = []
+ self.sqlmeta.send(events.RowDestroySignal, self, post_funcs)
# Kills this object. Kills it dead!
klass = self.__class__
@@ -1526,6 +1527,9 @@
self._connection._SO_delete(self)
self._connection.cache.expire(self.id, self.__class__)
+ for func in post_funcs:
+ func()
+
def delete(cls, id, connection=None):
obj = cls.get(id, connection=connection)
obj.destroySelf()
Modified: SQLObject/trunk/sqlobject/tests/test_events.py
===================================================================
--- SQLObject/trunk/sqlobject/tests/test_events.py 2008-01-30 13:33:02 UTC (rev 3232)
+++ SQLObject/trunk/sqlobject/tests/test_events.py 2008-01-30 13:35:33 UTC (rev 3233)
@@ -41,13 +41,13 @@
assert len(watcher.log) == 2
assert watcher.log[0] == ({'name': 'foo'}, [])
-def test_row_destrow():
+def test_row_destroy():
setupClass(EventTester)
watcher = make_listen(events.RowDestroySignal)
f = EventTester(name='foo')
assert not watcher.log
f.destroySelf()
- assert watcher.log == [(f,)]
+ assert watcher.log == [(f, [])]
def test_row_update():
setupClass(EventTester)
|