Ñò
+z2Wc @ sÀ d Z d d k Z d d k l Z l Z d „ Z e d „ ƒ Z e d „ ƒ Z d e f d „ ƒ YZ d
e f d „ ƒ YZ d e f d
„ ƒ YZ
d e e f d „ ƒ YZ e Z
e Z e Z d S( s" Basic classes with predefined properties
Example usage:
class Article(Gdtstruct):
"A basic Article class"
# fields and types are dynamically set by the initializer
gdtstruct_properties([('title', Gdtstr, "The Title of the Article"),
('page', Gdtlist, "List of pages in the Article")
])
def __init__(self, *args):
super(Article, self).__init__(*args)
self.title = Gdtstr("")
self.page = Gdtlist()
class Page(Gdtstruct):
# fields and types are dynamically set by the initializer
gdtstruct_properties([('text', Gdtstr, "The text of the page"),
])
def __init__(self, *args):
super(Page, self).__init__(*args)
self.text = Gdtstr(args[0] if len(args) else "")
a = Article()
print Article.title.__doc__
print
a.title = "My title"
a.page.append(Page("page 1"))
a.page.append(Page("page 2"))
a.commit()
print a
print
a.title = "My bad title"
a.page[1].text = "bad page 2"
a.page.append(Page("bad page 3"))
print a
print
a.page.rollback()
print a
print
a.rollback()
print a
Output of the example:
The Title of the Article
Article.title=My title
Article.page.1.Page.text=page 1
Article.page.2.Page.text=page 2
Article.title=My bad title
Article.page.1.Page.text=page 1
Article.page.2.Page.text=bad page 2
Article.page.3.Page.text=bad page 3
Article.title=My bad title
Article.page.1.Page.text=page 1
Article.page.2.Page.text=page 2
Article.title=My title
Article.page.1.Page.text=page 1
Article.page.2.Page.text=page 2
iÿÿÿÿNi ( t Transactiont Transactionlistc sC ‡ f d † } ˆ i | _ ˆ i | _ ˆ i | _ ˆ i | _ | S( s6 basic idea stolen from zope.interface.advice, P.J. Ebyc s‰ t i d ƒ } d | i j oY d | i i j oF d | i j o t d ƒ ‚ n ‡ ‡ ‡ f d † } | | i d