Inserting an object automagically on folder creation
Hello everyone, A long time ago I posted some question and finally made it to the creation of my first product, now I'm back I'm still thinking on how I will design my product but here are some caracteristics I'd like my product to have A) I'd like to create two way to represent data. In the first one the data is stored in in ZODB, in the second one the data is stored in a (possibly) remote database server. So I intend to do it this way : - Zpeople `- ZpeopleItemContainer (inheriting from Folder) `- ZpeopleItem (inheriting from SimpleItem) `- ZpeopleSQL (any pointer on how I can do this) I'd like ZpeopleSQL and ZpeopleItemContainer to have the same contract (ie: a search method with different flavour of search). Last but not least, 'a' being a ZpeopleSQL instance and 'b' being a ZpeopleItemContainer instance. Is it possible through some clever use of acquisition to acces the same kind of internal information by the same kind of url ? Example: localhost/folder/a/p1/name -> name of people whose id is p1 (DB version) localhost/folder/b/p1/name -> name of people whose id is p1 (ZODB version) B) I'd like to insert on a Product creation three objects. I use this code : def __init__(self, args) : self.clientsDB = ZpeopleSQL('clientsDB', dbConnection) self._setObject('clientsDB', self.clientsDB) is it gonna work ? Or maybe I should use this less elegant (at least IMHO) version : self.manage_addProduct['ZpeopleSQL'].manage_addPT(id='dkfj', db=dbConnection) Any help, flame, pointer appreciated ... -- (°> Nicolas Évrard / ) Liège - Belgique ^^
* Nicolas Évrard [01:15 28/02/03 CET]:
A) I'd like to create two way to represent data. In the first one the data is stored in in ZODB, in the second one the data is stored in a (possibly) remote database server.
So I intend to do it this way :
- Zpeople `- ZpeopleItemContainer (inheriting from Folder) `- ZpeopleItem (inheriting from SimpleItem) `- ZpeopleSQL (any pointer on how I can do this)
I'd like ZpeopleSQL and ZpeopleItemContainer to have the same contract (ie: a search method with different flavour of search).
Last but not least, 'a' being a ZpeopleSQL instance and 'b' being a ZpeopleItemContainer instance. Is it possible through some clever use of acquisition to acces the same kind of internal information by the same kind of url ?
Example: localhost/folder/a/p1/name -> name of people whose id is p1 (DB version) localhost/folder/b/p1/name -> name of people whose id is p1 (ZODB version)
Well maybe AdaptableStorage will do the trick ... Anyway, I'm printing the code right now and it seems to me a really nice piece of code ... Thanks to creator (even if I don't find what I'm looking for in this). -- (°> Nicolas Évrard / ) Liège - Belgique ^^
A) I'd like to create two way to represent data. In the first one the data is stored in in ZODB, in the second one the data is stored in a (possibly) remote database server.
So I intend to do it this way :
- Zpeople `- ZpeopleItemContainer (inheriting from Folder) `- ZpeopleItem (inheriting from SimpleItem) `- ZpeopleSQL (any pointer on how I can do this)
I'd like ZpeopleSQL and ZpeopleItemContainer to have the same contract (ie: a search method with different flavour of search).
Last but not least, 'a' being a ZpeopleSQL instance and 'b' being a ZpeopleItemContainer instance. Is it possible through some clever use of acquisition to acces the same kind of internal information by the same kind of url ?
Example: localhost/folder/a/p1/name -> name of people whose id is p1 (DB version) localhost/folder/b/p1/name -> name of people whose id is p1 (ZODB version)
You should probably take a look at Pluggable Brains and the Result Objects. It allows you to do something quite similar to this. I was able to muck up a quick example in a few minutes where I could do: localhost/folder/b/name/p1/nameview where there is some table 'data' in my database with a 'name' column among some others, having in its records one where 'p1' is the value of the 'name' field, where 'b' is an ZSQLMethod in 'folder' that has a 'name' parameter and looks like select * from data <dtml-sqlgroup where> <dtml-sqltest name type="nb" optional> </dtml-sqlgroup> where 'nameview' is a DTML Method in 'folder' (or above) looking like <dtml-var name> Works fine. I'm sure if you get into it, you can make it look like your example above, though I expect it to be easier to change your 'a'-type product. Start in the Zope book chapter on Relational Database Connectivity: http://www.zope.org/Documentation/Books/ZopeBook/current/RelationalDatabases... pay special attention to the "Traversing to Result Objects" and "Binding Classes to Result Objects" sections. Also take a look at http://www.zope.org/Members/spinwing/ZSQL_Results http://www.zope.org/Members/mcdonc/HowTos/direct_traversal and of course the Zope source, looking for 'Brains' among others. --jcc
participants (2)
-
J Cameron Cooper -
Nicolas Évrard