[Checkins] SVN: mongopersist/trunk/ - Bug: ``MongoContainer`` did not emit any Zope container or lifecycle
Stephan Richter
srichter at gmail.com
Mon Jan 16 16:29:37 UTC 2012
Log message for revision 124055:
- Bug: ``MongoContainer`` did not emit any Zope container or lifecycle
events. This has been fixed by using the ``zope.container.contained``
helper functions.
- Get ready for release.
Changed:
U mongopersist/trunk/CHANGES.txt
U mongopersist/trunk/setup.py
U mongopersist/trunk/src/mongopersist/zope/container.py
U mongopersist/trunk/src/mongopersist/zope/tests/test_container.py
-=-
Modified: mongopersist/trunk/CHANGES.txt
===================================================================
--- mongopersist/trunk/CHANGES.txt 2012-01-15 18:41:49 UTC (rev 124054)
+++ mongopersist/trunk/CHANGES.txt 2012-01-16 16:29:35 UTC (rev 124055)
@@ -2,10 +2,12 @@
CHANGES
=======
-0.5.3 (unreleased)
+0.5.3 (2012/01/16)
------------------
-- ...
+- Bug: ``MongoContainer`` did not emit any Zope container or lifecycle
+ events. This has been fixed by using the ``zope.container.contained``
+ helper functions.
0.5.2 (2012-01-13)
------------------
Modified: mongopersist/trunk/setup.py
===================================================================
--- mongopersist/trunk/setup.py 2012-01-15 18:41:49 UTC (rev 124054)
+++ mongopersist/trunk/setup.py 2012-01-16 16:29:35 UTC (rev 124055)
@@ -9,7 +9,7 @@
setup (
name='mongopersist',
- version='0.5.3dev',
+ version='0.5.3',
author = "Stephan Richter",
author_email = "stephan.richter at gmail.com",
description = "Mongo Persistence Backend",
Modified: mongopersist/trunk/src/mongopersist/zope/container.py
===================================================================
--- mongopersist/trunk/src/mongopersist/zope/container.py 2012-01-15 18:41:49 UTC (rev 124054)
+++ mongopersist/trunk/src/mongopersist/zope/container.py 2012-01-16 16:29:35 UTC (rev 124055)
@@ -167,7 +167,8 @@
obj._v_parent = self
return obj
- def __setitem__(self, key, value):
+
+ def _real_setitem(self, key, value):
# This call by iteself caues the state to change _p_changed to True.
setattr(value, self._m_mapping_key, key)
if self._m_parent_key is not None:
@@ -175,11 +176,12 @@
self._m_jar.register(value)
# Temporarily store the added object, so it is immediately available
# via the API.
- value._v_key = key
- value._v_parent = self
self._added[key] = value
self._deleted.pop(key, None)
+ def __setitem__(self, key, value):
+ contained.setitem(self, self._real_setitem, key, value)
+
def __delitem__(self, key):
# Deleting the object from the database is not our job. We simply
# remove it from the dictionary.
@@ -190,6 +192,7 @@
delattr(value, self._m_parent_key)
self._deleted[key] = value
self._added.pop(key, None)
+ contained.uncontained(value, self, key)
def keys(self):
filter = self._m_get_items_filter()
Modified: mongopersist/trunk/src/mongopersist/zope/tests/test_container.py
===================================================================
--- mongopersist/trunk/src/mongopersist/zope/tests/test_container.py 2012-01-15 18:41:49 UTC (rev 124054)
+++ mongopersist/trunk/src/mongopersist/zope/tests/test_container.py 2012-01-16 16:29:35 UTC (rev 124055)
@@ -22,6 +22,7 @@
import transaction
import zope.component
import zope.interface
+import zope.lifecycleevent
from pprint import pprint
from zope.app.testing import placelesssetup
from zope.container import contained, btree
@@ -33,6 +34,9 @@
class ApplicationRoot(container.SimpleMongoContainer):
_p_mongo_collection = 'root'
+ def __repr__(self):
+ return '<ApplicationRoot>'
+
class SimplePerson(contained.Contained, persistent.Persistent):
_p_mongo_collection = 'person'
@@ -54,6 +58,10 @@
>>> cn = 'mongopersist.zope.container.SimpleMongoContainer'
+ Let's make sure events are fired correctly:
+
+ >>> zope.component.provideHandler(handleObjectModifiedEvent)
+
Let's add a container to the root:
>>> dm.reset()
@@ -66,6 +74,7 @@
As you can see, the serialization is very clean. Next we add a person.
>>> dm.root['c'][u'stephan'] = SimplePerson(u'Stephan')
+ ContainerModifiedEvent: <...SimpleMongoContainer ...>
>>> dm.root['c'].keys()
[u'stephan']
>>> dm.root['c'][u'stephan']
@@ -113,6 +122,7 @@
Now remove the item:
>>> del dm.root['c']['stephan']
+ ContainerModifiedEvent: <...SimpleMongoContainer ...>
The changes are immediately visible.
@@ -134,6 +144,10 @@
def doctest_MongoContainer_basic():
"""MongoContainer: basic
+ Let's make sure events are fired correctly:
+
+ >>> zope.component.provideHandler(handleObjectModifiedEvent)
+
Let's add a container to the root:
>>> transaction.commit()
@@ -148,6 +162,7 @@
avoidable using a sub-class.
>>> dm.root['c'][u'stephan'] = Person(u'Stephan')
+ ContainerModifiedEvent: <...MongoContainer ...>
>>> dm.root['c'].keys()
[u'stephan']
>>> dm.root['c'][u'stephan']
@@ -189,6 +204,7 @@
Now remove the item:
>>> del dm.root['c']['stephan']
+ ContainerModifiedEvent: <...MongoContainer ...>
The changes are immediately visible.
@@ -418,6 +434,10 @@
def doctest_SubDocumentMongoContainer_basic():
r"""SubDocumentMongoContainer: basic
+ Let's make sure events are fired correctly:
+
+ >>> zope.component.provideHandler(handleObjectModifiedEvent)
+
Sub_document Mongo containers are useful, since they avoid the creation of
a commonly trivial collections holding meta-data for the collection
object. But they require a root document:
@@ -429,6 +449,7 @@
>>> dm.root['app_root']['people'] = \
... container.SubDocumentMongoContainer('person')
+ ContainerModifiedEvent: <ApplicationRoot>
>>> transaction.commit()
>>> db = dm._conn[DBNAME]
@@ -447,13 +468,14 @@
>>> dm.root['app_root']['people']
<mongopersist.zope.container.SubDocumentMongoContainer ...>
>>> dm.root['app_root']['people'].__parent__
- <mongopersist.zope.tests.test_container.ApplicationRoot object at 0x7f>
+ <ApplicationRoot>
>>> dm.root['app_root']['people'].__name__
'people'
Let's add an item to the container:
>>> dm.root['app_root']['people'][u'stephan'] = Person(u'Stephan')
+ ContainerModifiedEvent: <...SubDocumentMongoContainer ...>
>>> dm.root['app_root']['people'].keys()
[u'stephan']
>>> dm.root['app_root']['people'][u'stephan']
@@ -538,6 +560,14 @@
"zodb-01af3b00c5"),
])
+ at zope.component.adapter(
+ zope.interface.Interface,
+ zope.lifecycleevent.interfaces.IObjectModifiedEvent
+ )
+def handleObjectModifiedEvent(object, event):
+ print event.__class__.__name__+':', repr(object)
+
+
def setUp(test):
placelesssetup.setUp(test)
module.setUp(test)
More information about the checkins
mailing list