Skip to main content

improved ZODB persistence

Project description

Persistent

This package provides a base class for persistent objects with the advantage that the object is only marked as changed if an attribute has really changed.

>>> import transaction
>>> from ZODB.tests.util import DB
>>> from lovely import persistent
>>> p = LovelyPersistent()
>>> p._p_changed
False
>>> p.a = 1
>>> db = DB()
>>> conn = db.open()
>>> conn.root()['p'] = p
>>> transaction.commit()

After commiting the changes the object is no longer in changed state.

>>> p._p_changed
False

Setting a with its existing value doesn’t put the object in cahnged state.

>>> p.a
1
>>> p.a = 1
>>> p._p_changed
False

But modifying a :

>>> p.a = 2
>>> p._p_changed
True
>>> transaction.commit()
>>> p._p_changed
False

Deleting an attribute also put the object into changed state.

>>> del p.a
>>> p._p_changed
True

Special Properties

Special property implementations do work too. To show this we use the fieldproperties from zope.schema.

>>> from zope.schema.fieldproperty import FieldProperty
>>> from zope import schema, interface
>>> class IMyFace(interface.Interface):
...     eyesOpen = schema.Bool(default=True, required=False)
>>> class MyFace(persistent.Persistent):
...     eyesOpen = FieldProperty(IMyFace['eyesOpen'])
>>> persistent.tests.MyFace = MyFace
>>> MyFace.__module__ = persistent.tests.setUp.__module__
>>> myFace = conn.root()['myFace'] = MyFace()
>>> transaction.commit()

Default values.

>>> myFace.eyesOpen
True

Validation.

>>> myFace.eyesOpen = 'not always'
Traceback (most recent call last):
...
WrongType: ('not always', <type 'bool'>)

Note, setting to default value does not change the object.

>>> transaction.commit()
>>> myFace.eyesOpen = True
>>> myFace._p_changed
False
>>> transaction.commit()
>>> myFace.eyesOpen = False
>>> myFace._p_changed
True

Changes in lovely.persistent

2007/12/10 0.1.1

  • moved to zope.org

2007/06/19 0.1.0a1

  • added zodb to dependencies

  • added support for fieldproperties

Download

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lovely.persistent-0.1.1.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

lovely.persistent-0.1.1-py2.4.egg (9.5 kB view details)

Uploaded Source

File details

Details for the file lovely.persistent-0.1.1.tar.gz.

File metadata

File hashes

Hashes for lovely.persistent-0.1.1.tar.gz
Algorithm Hash digest
SHA256 bb1ad68ed1288ea0a09a80b3919367d949b2854756148d902824511de74efafe
MD5 8c9910f2cf366f51e6e41e6c7fb5fe2d
BLAKE2b-256 c908d216e44797d6aab22042039fef22b3d8d10a7203b33fa4b7f4f1e383c200

See more details on using hashes here.

File details

Details for the file lovely.persistent-0.1.1-py2.4.egg.

File metadata

File hashes

Hashes for lovely.persistent-0.1.1-py2.4.egg
Algorithm Hash digest
SHA256 456f00bcbf7832391bd28d55112e30f11529775fc09b4990e53efa9a6b2a02ec
MD5 04135887f1823fb30bdae96f48425a53
BLAKE2b-256 dccc20e1765405756bef44b1a447424263478ef2cb0916ef549806d515682899

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page