[Zope-dev] Python Based DataSkins and Propertysheets
Steve Alexander
steve@cat-box.net
Mon, 12 Feb 2001 09:28:47 +0000
Johan Carlsson wrote:
>>> Hi,
>>> I am trying to figure out ZPatterns and because I rather work with Python Products when with Zclasses I am trying to convert the EmployZ product to Python.
>>> So far I got half the way there, the Rack recognizes the DataSkin
>>> And on newItem in the Specialist it a new slot gets created and I can see them and their ID.
>>>
>>> Now the problem is creating a Propertysheet in the DataSkin that gets stored in the Rack.
>>
>> The attributes of a Persistent DataSkin will get stored in the Rack without too much extra work.
>>
>>
>>
>>> class EmployX(
>>> DataSkin,
>>> #VirtualSheets,
>>> ):
>>
>> You need to derive EmployX from DataSkin and some
>> Zope persistent class such as SimpleItem. Otherwise,
>> it won't be persistent.
>
>
> Accualy I donīt have to do that.
> Have a look at Itamar Shtull-Traurings and Heiko Stoermers
> FlatDatabase:
>
> def manage_change(self, REQUEST, RESPONSE):
> """ Change properties """
> for prop in self.database_properties.propertyMap():
> name=prop['id']
> if REQUEST.has_key(name):
> if 'w' in prop.get('mode', 'wd'):
> value=REQUEST.get(name)
> setattr(self, name, value) <<<<
> RESPONSE.redirect(REQUEST.URL1)
>
>
> But as I noticed the "properties" was saved as
> attributes not as properties in a propertysheet.
That's another way of doing it. It is a bit less transparent.
I find it more straightforward to make my classes SimpleItems
and PropertyManagers, as it means I can just call
manage_changeProperties() without writing extra methods.
> I can live with that, but I still would like to know if and
> how to use propertysheets provided by a DataManager
> inside a Pyhton DataSkin?
There are two kinds of PropertySheet in Zope:
DAV propertysheets
Propertysheets that go with ZClasses
There are also Properties for objects that are PropertyManagers,
such as DTML Documents.
There is an important difference in how these different types of
properties work:
DAV Propertysheets are independent Persistent objects
Propertysheets that go with ZClasses and also
PropertyManager propertysheets are stored as attributes
in the objects they belong to.
Therefore, in ZPatterns, you use AttributeProviders to do stuff
with PropertyManager properties and ZClass-style propertysheets.
You use SheetProviders to do stuff with DAV Propertysheets.
If you're using ZClass-style propertysheets, you need to use
DataSkin Attribute Propertysheets, rather than the default
Common Instance Propertysheets.
In your case, I suggest making your class Persistent, and using
PropertyManager properties.
The reason to use ZClass-style propertysheets is if you want to
easily partition your properties into sets of properties with
different permissions.
--
Steve Alexander
Software Engineer
Cat-Box limited
http://www.cat-box.net