Are products the right approach?
Since I'm new at Zope, I would value your opinions very much about my choices in this first project. My first Zope project is creating an intranet for a local TV company. They wish to store information about their equipment, spare parts, etc., and maintain logs about the equipment's current state (working, out of order, being maintained, etc.). (note: This is only a small part of their intranet, extracted for discussion purposes). Right now, I've made the following folder structure: ---------------------------------- /root ... intranet Technical Equipment SpareParts ---------------------------------- I have created two product classes called Equipment and SpareParts. As it might be obvious, objects of class Equipment should only be created in the folder Equipment, and likewise with SpareParts. Objects of both classes store information about the specific piece of equipment or spare part. I've also made a superclass called "Loggable", which they inherit to be able to create logs about the use and maintainance of said object. The logs, however, are stored in a relational database. I've done it this way, because I need to create reports later on for the equipment and spare parts based on the logs. So the "class hierarchy" is pretty much like: SimpleItem Loggable |------+-----| | Equipment and the same for SparePart At the moment, I'm not sure this is the right approach. My judgement may be clouded since I come from the relational-DB world. 1) Should Equipment and SparePart be classes or perhaps instead tables in my RDBMS? (ATM they are classes to facilitate the history/undo functionality in Zope) 2) Should I make it all as classes (including the Log)? 3) How do you make relations between objects in Zope? (For use in eg. reporting) 4) I'm going to make a scheduled "event handler" that sends out mail messages based on the latest log entries. This needs to be able to find an object in ZODB based on the log entry - how do I make this connection? I deliberately did not include any source code, since this is more a discussion of techniques and principles. If any of you wish to see some of my code before answering, please say so. I hope you can help me. TIA - Carsten
On Thu, 2003-09-18 at 00:44, Carsten Gehling wrote:
I have created two product classes called Equipment and SpareParts. As it might be obvious, objects of class Equipment should only be created in the folder Equipment, and likewise with SpareParts.
If that's what your users need... it might be easier to treat SpareParts as a special type of Equipment. Treat them exactly the same but give them slightly different properties, interfaces, whatever.
So the "class hierarchy" is pretty much like:
SimpleItem Loggable |------+-----| | Equipment
Good.
and the same for SparePart
Why not: Equipment | SparePart
2) Should I make it all as classes (including the Log)?
It's not 100% clear what you mean by "the log". Information that describes the *current* status or state of your object should *definitely* be stored in an attribute of the class. As for keeping a history of the changes, it's hard to improve on plain old text file logging. There might be some advantage to keeping historical info in your class... but it would depend entirely on your requirements. Zope saves previous versions of objects, so your objects will grow in size quickly if they are changed often. Keeping extensive logs in a product that changes often may cause you to burn through disk space very quickly.
3) How do you make relations between objects in Zope? (For use in eg. reporting)
A couple ways. The obvious way is to store a "foreign key" object id as a string and use restrictedTraverse() when you need to obtain the object the id references. A more involved way is to store a reference to the object. This is quite a bit trickier, but might be worth it if you're doing this a lot. A bigger answer is that there might still be some room for more Zopish thinking. It may be better, for example, to model one-to-many relationships as a container object and its collection of sub-objects. In this design, relations are assumed rather than specified.
4) I'm going to make a scheduled "event handler" that sends out mail messages based on the latest log entries. This needs to be able to find an object in ZODB based on the log entry - how do I make this connection?
You can call restrictedTraverse() from within a product, a Python Script or could use it in a script that manipulates Zope from the outside. HTH, Dylan
participants (2)
-
Carsten Gehling -
Dylan Reinhardt