I'm starting to get the "big picture" but I'm still a little fuzzy on the details, particularly about objects and the ZODB. I'm hoping that someone can give me some brief pointers to where the answers the these questions lie. I have read a *bunch* of Zope doc and I'm pretty handy with Python. 1) Where are data object classes defined in Zope? I get the persistent object thing. Very cool. So let's say I want to write a billing system. I have customer objects, invoice objects, and payment objects. [ Customer [ Invoices [Payments] ] ]. a) Where do I put the code that defines each custom class? Scripts seem to be for def-functions. Do I have to put this outside Zope? b) Do I use ZCatalogs to 'index' my objects so I can query them similar to SQL? If so, how/where do I add my custom classes to the ZCatalog? 2) How do I instantiate and persist (through the session) a particular instance of the class from the ZODB (i.e. a certain customer)? I realize these are big questions. Any pointer toward answers, even which documentation I should be reading, would be helpful and greatly appreciated. Thanks! Jeff Childers
Jeff Childers wrote:
1) Where are data object classes defined in Zope?
The ones you can select from the "Add..." menu.
I get the persistent object thing. Very cool. So let's say I want to write a billing system. I have customer objects, invoice objects, and payment objects. [ Customer [ Invoices [Payments] ] ].
a) Where do I put the code that defines each custom class? Scripts seem to be for def-functions. Do I have to put this outside Zope?
You can do it inside Zope with ZClasses, but I'd recommend you to do it outside of Zope in so called "python classes". This are located in lib/python/Products or just /Products. Start with the "BoringProduct" example and go from there. Theres a some about this in the Zope Book too.
b) Do I use ZCatalogs to 'index' my objects so I can query them similar to SQL? If so, how/where do I add my custom classes to the ZCatalog?
You subclass them from a CatalogAware class, and call reindex each time they have changed.
2) How do I instantiate and persist (through the session) a particular instance of the class from the ZODB (i.e. a certain customer)?
Instantiate: customer = CustomerClass() You store it persistently by setting the new object as an attribute on another persistent object. How you do this depends on your other persistent object. You also need to subclass your class from Persistance.Base. The most trivial example is: folder[customer_name] = customer # where customer is the CustomerClass # instance you created above Yes, it is really that simple.
I realize these are big questions.
Well, if you liked Zope before, you'll soon like it more, because with Zope, this is small, simple questions. :)
Lennart Regebro wrote:
Jeff Childers wrote:
1) Where are data object classes defined in Zope?
The ones you can select from the "Add..." menu.
As you no doubt realized, I misread that question as "Where are the data objects that are defined in Zope". Ah well. :)
[Jeff Childers]
I'm starting to get the "big picture" but I'm still a little fuzzy on the details, particularly about objects and the ZODB. I'm hoping that someone can give me some brief pointers to where the answers the these questions lie. I have read a *bunch* of Zope doc and I'm pretty handy with Python.
1) Where are data object classes defined in Zope?
I'm fairly new to Zope, although I've written some Zope Products. My sense is that there are two answers to your question: * ZClasses * Products and that the best bet in the long-run, especially if you feel comfortable with Python, is to skip ZClasses altogether and focus on grokking Products.
I get the persistent object thing. Very cool. So let's say I want to write a billing system. I have customer objects, invoice objects, and payment objects. [ Customer [ Invoices [Payments] ] ].
My guess is that you'd write a Product, BillingSystem. The BillingSystem Product would include a variety of classes: * A top-level container; e.g., Billing * Customer * Invoice * Payment Only the top-level container would be addable to other Zope containers (folderish objects). Once you adding an instance of Billing, it would have a slightly customized manage_main (I'm probably misspelling that). From Billing's manage_main, you could add Customers. From a Customer's management screens, you could add Invoices. And so on.
a) Where do I put the code that defines each custom class? Scripts seem to be for def-functions. Do I have to put this outside Zope?
Yes, that's your best bet. The common wisdom seems to be: Write this as if it's just Python, then add a light wrapper for Zope. Of course, the devil can sometimes be in the details.
b) Do I use ZCatalogs to 'index' my objects so I can query them similar to SQL? If so, how/where do I add my custom classes to the ZCatalog?
Good question.
2) How do I instantiate and persist (through the session) a particular instance of the class from the ZODB (i.e. a certain customer)?
The thing about PersistentObject is that you don't really have to do anything for it to persist aside from instantiating it in Zope. Isn't that cool?
I realize these are big questions. Any pointer toward answers, even which documentation I should be reading, would be helpful and greatly appreciated.
I think the short answer is that you want to investigate Products. I'm hoping someone more knowledgeable about the specifics follows up. Cheers, // m -
Jeff Childers wrote:
I'm starting to get the "big picture" but I'm still a little fuzzy on the details, particularly about objects and the ZODB. I'm hoping that someone can give me some brief pointers to where the answers the these questions lie. I have read a *bunch* of Zope doc and I'm pretty handy with Python.
1) Where are data object classes defined in Zope?
I get the persistent object thing. Very cool. So let's say I want to write a billing system. I have customer objects, invoice objects, and payment objects. [ Customer [ Invoices [Payments] ] ].
a) Where do I put the code that defines each custom class? Scripts seem to be for def-functions. Do I have to put this outside Zope?
You need to write a Zope product i Python to do these things. There is a good overview here: http://www.zope.org/Documentation/comp_tut
b) Do I use ZCatalogs to 'index' my objects so I can query them similar to SQL? If so, how/where do I add my custom classes to the ZCatalog?
Your classes should just subclass "CatalogPathAware" and they are automatically catalog aware. If you use this tool to write your products, they are so automatically: http://www.zope.org/Members/maxm/HowTo/easyProduct
2) How do I instantiate and persist (through the session) a particular instance of the class from the ZODB (i.e. a certain customer)?
When you write your products, you also write a "constructor" function, which does it for you. regards Max M
participants (4)
-
Jeff Childers -
Lennart Regebro -
Mark McEahern -
Max M