- How do I publish this object?
I believe this was asked yesterday, but I don't recall seeing an answer posted yet, so I'll ask again, in case it wasn't noticed by those with enough Zope Zen. While I was in the shower last night (what is it about the shower with this group?) it dawned on me that what I don't get about Zope is how to publish an object in much the same way I would have done using Bobo. As an example, appended is a small module, cal.py, which uses the Unix cal command to generate an ASCII calendar. How would I make that available through Zope? Seeing how that is done would be a big step forward for me. Thx, Skip Montanaro | Mojam: "Uniting the World of Music" http://www.mojam.com/ skip@calendar.com | Musi-Cal: http://concerts.calendar.com/ 518-372-5583 """ dumb Calendar module """ import os class Calendar: """calendar class""" def show(self, year, month=0): """return plain ASCII calendar month == 0 ==> display calendar for entire year """ if year < 1 or year > 9999: raise ValueError, ("year out of range: %d" % year) if month < 0 or month > 12: raise ValueError, ("month out of range: %d" % month) if month: cal = os.popen("cal %s %s" % (month, year)).read() else: cal = os.popen("cal %s" % year).read() return cal
I believe this was asked yesterday, but I don't recall seeing an answer posted yet, so I'll ask again, in case it wasn't noticed by those with enough Zope Zen.
While I was in the shower last night (what is it about the shower with this group?) it dawned on me that what I don't get about Zope is how to publish an object in much the same way I would have done using Bobo.
As an example, appended is a small module, cal.py, which uses the Unix cal command to generate an ASCII calendar. How would I make that available through Zope? Seeing how that is done would be a big step forward for me.
Thx,
Skip Montanaro | Mojam: "Uniting the World of Music" http://www.mojam.com/ skip@calendar.com | Musi-Cal: http://concerts.calendar.com/ 518-372-5583
It's quite easy. There are some things missing from my example here that you will need to create, alot of dtml and an __init__.py file which sets up some stuff and contains the ImageFile references to any icons you plan to use. Notice I just droped this stuff like iceing onto your Calendar cake. It looks daunting now but after you see it a few times lots of the fluf because invisible to you. Michel
""" dumb Calendar module """
from Globals import HTMLFile import OFS.SimpleItem, Persistence, Acquisition, AccessControl.Role
import os
class Calendar( OFS.SimpleItem.Item, Persistence.Persistent, Acquisition.Implicit, AccessControl.Role.RoleManager, ): """calendar class"""
meta_type='MyCalendar' icon='misc_/MyCalendar/folder # These are added to your manage screens by lib/python/App/manage_tabs.dtml manage_options=( {'label':'Contents', 'action':'manage_main'}, {'label':'Properties', 'action':'manage_propertiesForm'}, {'label':'View', 'action':''}, {'label':'Security', 'action':'manage_access'}, ) # These define the atomic operations that can be done with this module # These end up in your security screen 'manage_access' __ac_permissions__=( ('View management screens', ('manage_tabs','manage_main')), ('Change permissions', ('manage_access',)), ('Change Calendar Settings', ('manage_edit',)), ('View Calendar', ('',)), ) def __init__(self, id, title='', REQUEST): self.id = id self.title=title # need an index view index_html=HTMLFile('index_html', globals()) # this is your management screen manage_main=HTMLFile('main', globals()) # returned when the manage clicks on 'Properties' (see permissions above) manage_propertiesForm=HTMLFile('editprops', globabls()) def manage_edit(self, id, name, REQUEST: """ this is the action for the form in manage_propertiesForm """ self.title=title if REQUEST is not None: return self.manage_main(self, REQUEST)
def show(self, year, month=0): """return plain ASCII calendar
You probably want to convert this to a function that returns a DTML file that lays out the calendar and fills in some <!--#var--> tags.
month == 0 ==> display calendar for entire year """ if year < 1 or year > 9999: raise ValueError, ("year out of range: %d" % year) if month < 0 or month > 12: raise ValueError, ("month out of range: %d" % month)
if month: cal = os.popen("cal %s %s" % (month, year)).read() else: cal = os.popen("cal %s" % year).read() return cal
On Tue, 8 Dec 1998, Michel Pelletier wrote:
It's quite easy. [60 lines of Python expunged]
Thank you for the help, but...this must be some new definition of the word "easy" with which I was previously unfamiliar. :-) Further questions spring to mind: a) where do you stick this file - lib/python/Products/Cal/Cal.py, along with __init__.py etc a la other directories under lib/python/Products ? b) how do you add it to Zope? Under Control Panel I see Products, and from there I can add a product, for whatever that's worth. Now I see a menu which allows you to add "Principia Factory", ... "External Method", "Mail Host". At this point I'm completely lost... (if it's an External Method then where is Zope looking for the Python module file? If it isn't an external method, what is it? What's a Principia Factory?) c) once you've done that, how do you create an object instance? Does your new class just get added to the list of things you can "Add"? d) how do you test the product you're working on? e.g. change its definition and have that reflected in Zope e) are the naming conventions documented anywhere? f) how are products distributed? A tar file of lib/python/Products/yourproductname? Is there any documentation on all of this or are we just supposed to wade through all the source code and guess? Maybe I'm just missing the wonderful "Everything You Ever Wanted To Know About Creating Products" tutorial...if not, is something of this sort in the works? -- James Strickland Perforce Software
James> Thank you for the help, but...this must be some new definition of James> the word "easy" with which I was previously unfamiliar. :-) [ several questions, some of which occurred to me, snipped ] My sentiments exactly. It would appear that Principia and Zope traded off Bobo's simple object publishing model for a very nice way to manage hierarchical web sites. The extra complexity added under the covers looks like it will make it very difficult to convert existing CGI-based sites to Zope. I have a site that uses 30-40 CGI scripts to do its business. At this stage, converting them looks like it will be fairly difficult. If I'm missing something, please fill me in. If not, is there some simpler way to publish objects through Zope other than the current Product API? Thx, Skip
On Tue, 8 Dec 1998 skip@calendar.com wrote:
My sentiments exactly. It would appear that Principia and Zope traded off Bobo's simple object publishing model for a very nice way to manage hierarchical web sites. The extra complexity added under the covers looks like it will make it very difficult to convert existing CGI-based sites to Zope. I have a site that uses 30-40 CGI scripts to do its business. At
Echoing Skip ... After playing around with Zope for a while I got the impression that Zope makes it a bit difficult to publish new objects on the Web (compared with Bobo) but provides a very powerful platform to create editable web document hierarchies. I am trying to build a very lightweight distributed object system based on Bobo, where object contents do not change often (apart from configuration files) but whole objects are added or deleted relatively frequently. In such a scenario I need a simple Web front end that displays object functionality and webfolder contents in a consistent manner without the need to provide the option to edit the way this front end looks or the permissions set at development time. Such a zoppini though must be very flexible and user friendly when it comes to adding objects. I would like to transfer everything to Zope and trow away my Zoppini but I think I will need to wait a bit longer. Pavlos
At 02:49 PM 12/8/98 -0500, Skip wrote:
James> Thank you for the help, but...this must be some new definition of James> the word "easy" with which I was previously unfamiliar. :-)
[ several questions, some of which occurred to me, snipped ]
My sentiments exactly. It would appear that Principia and Zope traded off Bobo's simple object publishing model for a very nice way to manage hierarchical web sites.
It's true, for programmers, Zope is much more complex than Bobo. That's because Zope is a large framework built on Bobo that tries to provide lots of extra services. If you still want Bobo's simplicity, it's still there. You can always just use ZPublisher and forget all the other stuff. Zope is not right for all problem domains. That said, I belive that Zope offers a lot of cool things and that depending on what you are trying to do, doing it within Zope's framework can be a lot less total work than going at it with plain Bobo.
The extra complexity added under the covers looks like it will make it very difficult to convert existing CGI-based sites to Zope. I have a site that uses 30-40 CGI scripts to do its business. At this stage, converting them looks like it will be fairly difficult. If I'm missing something, please fill me in. If not, is there some simpler way to publish objects through Zope other than the current Product API?
The Product API is for creating a very specific type of web object--one that can be managed through the web by Zope. You don't need this kind of object for many all purposes. Suppose you have 40 different web objects that you've developed in Bobo over the last year. You want to plug them into Zope. It probably doesn't make sense to productize too many of them. Rather, you probably just want to add them to the object hierarchy somewhere and publish them like normal. The easiest way to do this is with External Methods. Here's an example of how you might do this: "External method to plug a Bobo object into the Zope object hierarchy" # first import your Bobo object or class from myBoboModule import Spam def add_spam(self,id): """This method is called by a folder to add a spam object to the folder. The spam object is not a Zope product, it is simply a normal Bobo object." spam=Spam(id) # or whatever to create your Bobo object if not hasattr(self,id): setattr(self,id,spam) return "Spam added to folder" Now your spam object is an attribute of the folder you called the External Method on. You can publish it the same way you publish any Bobo object. Make sense? -Amos P.S. If you want to plug a whole bunch of Bobo stuff into Zope you might build a more flexible External Method or even a <gasp> Product to manage it. P.P.S. If you're really sick you can use an External Method to attach a textarea to exec and then start hacking away just like at the Python prompt!
On Tue, 8 Dec 1998, Amos Latteier wrote:
P.S. If you want to plug a whole bunch of Bobo stuff into Zope you might build a more flexible External Method or even a <gasp> Product to manage it.
P.P.S. If you're really sick you can use an External Method to attach a textarea to exec and then start hacking away just like at the Python prompt!
I'm craving an imbeded java dtml editor right about now. Something that does tab indention and color coding. I also want $1,000,000 and a Playmate to spend it on...... -Scott Robertson CodeIt Computing
On Tue, 8 Dec 1998, Michel Pelletier wrote:
It's quite easy. [60 lines of Python expunged]
Thank you for the help, but...this must be some new definition of the word "easy" with which I was previously unfamiliar. :-)
Ever try to write a Windows program in ANSI C? :) I think the two dozen or so lines of overhead is trivialized by the abilities it gives you. Like I said in my previous post, these things become clearer the more you look at them.
Further questions spring to mind: a) where do you stick this file - lib/python/Products/Cal/Cal.py, along with __init__.py etc a la other directories under lib/python/Products ?
Make a new subdirectory under Products with the name of your product. For exmaple, I keep Trove in lib/python/Products/Trove/ where is where you'll find all the relevent files.
b) how do you add it to Zope? Under Control Panel I see Products, and from there I can add a product, for whatever that's worth. Now I see a menu which allows you to add "Principia Factory", ... "External Method", "Mail Host". At this point I'm completely lost... (if it's an External Method then where is Zope looking for the Python module file? If it isn't an external method, what is it? What's a Principia Factory?)
After you add the files in the directory of your choice, simple restarting the process loads the product *if you have a well formed package* see below.
c) once you've done that, how do you create an object instance? Does your new class just get added to the list of things you can "Add"?
The __init__.py file in your package is loaded by Zope when the process starts. __init__.py does a few things: imports your product. This is where you catch syntax errors, the Zope process will spit up a traceback and exit. Zope cannot run if a product has a syntax error (digifolk, perhaps this should be wrapped in a try: except block?) hooks into the Zope 'Add' menu a function that displays the 'add' screen where you can type in at least an id, the title might be required too I've never ommited it to try. This function is usualy just a DTML method that spits a a form, whose 'action' is to... ...call another function that __init__ hooks into Zope that does the actual adding of your Product object To where ever you add it. This is all detailed in the Sample Product __init__.py file which I highly suggest anyone writing a Product should d/l and study. It's only about a page long and took me just a few minutes to grok.
d) how do you test the product you're working on? e.g. change its definition and have that reflected in Zope
Restart the process. :| Jim mentioned complications in geting this to work in-band, it would be nice if objects could reload themselves or be manualy reloaded from say, the Control Panel; all in good time.
e) are the naming conventions documented anywhere?
Not really, I'm kinda coming up with my own, in most cased I try to follow the conventions of the Zope source. Functions and Documents that deal with the management interface are usualy prefixed with 'manage_', functions and form that deal with your specific user interface are your discretion.
f) how are products distributed? A tar file of lib/python/Products/yourproductname?
Yep.
Is there any documentation on all of this or are we just supposed to wade through all the source code and guess? Maybe I'm just missing the wonderful "Everything You Ever Wanted To Know About Creating Products" tutorial...if not, is something of this sort in the works?
Why yes, I'll have something shortly for you. 'Till then get out the wading boots. :) Michel
-- James Strickland Perforce Software
participants (6)
-
Amos Latteier -
James Strickland -
Michel Pelletier -
Pavlos Christoforou -
Scott Robertson -
skip@calendar.com