publishing objects
hi folks, i've got some beginner questions about zope. i spent a fair amount of time with various documentation, but couldn't find the answers. first, the specific question. the docs talk about publishing objects, with zope translating URLs to method calls. i get the impression that i can call arbitrary Python objects through zope, but i can't get it to work. i've tried it with IIS and the included HTTP server. let's say i want to call somemethod() in test.py. the docs say that http://localhost:9673/test/somemethod will do it. but where should test.py live? what's the home document directory of the builtin HTTP server? and if i use IIS, how do i get it to use zope. by calling http://localhost:9673/manage, i can access the zope ODB, but not python modules outside the database. is this possible? using IIS, i could access ODB objects via http://localhost/zope/cgi/zope.exe/manage, but again, how do i get to the python objects? do the modules have to exist in the zope ODB? if so, how do i import them? i know about external methods, but it seems cumbersome to create them, method by method, object by object. what i want to do is create a web application for reading and writing information from a database (a registry of trainers and trainings). i have begun developing this using ASP, IIS, and SQL Server. i'm always looking for non-microsoft alternatives. it looks like i can develop business objects in python that model the business rules, then use zope to access the objects and control the presentation. in another language, those business objects would encapsulate the database access. i know zope has database adapters, but if i don't already have data in a relational database, do i even need to use one. could the application be implemented solely with the object database? i'm used to relational databases, so when i start with new projects i start with the database. but maybe the zope ODB provides what i need... any ideas? thanks in advance for your time. -scott ----- Scott Lewis Baltic Avenue Productions csl@balticave.com
At 09:18 AM 4/20/99 -0600, Scott Lewis wrote:
the docs talk about publishing objects, with zope translating URLs to method calls. i get the impression that i can call arbitrary Python objects through zope, but i can't get it to work. i've tried it with IIS and the included HTTP server.
Yes it's true. Zope can publish arbitrary Python objects. Actually, it's more accurate to say that Zope ORB (ZPublisher) can publish arbitrary Python objects. For more info see: http://www.zope.org/Documentation/Reference/ORB Or check out the ZPublisher package in the sources. Now that you've read up on object publishing, question becomes, how to get ZPublisher to publish your objects. The easiest way to publish your Python module with ZPublisher is to run ZopeHTTPServer like so: ZopeHTTPServer.py myModule.py Now go to the web and try calling your module which should be published on port 9673. After you get this working, your next questions may be, "How can I use a different web server, say Apache." Followed quickly by, "How can I get my arbitrary Python objects into the Zope framework that I know and love?" The answer to the first question is PCGI. PCGI, like ZopeHTTPServer lets you publish any Python module with ZPublisher. http://starship.python.net/crew/jbauer/persistcgi/ Now suppose you want to use your objects within the Zope framework. You have a couple options: * External Methods * Write a Product Both these methods are laborious when seen in comparison with just writing a Python module and publishing it. Why is it so hard? Because the Zope framework (by which I mean the management conventions and built-in objects like Folders and DTML Methods) is complex. To make your objects play by its rules takes an effort. Not only that, but our developer documentation is still rather crummy. Some people decide that the Zope framework doesn't offer them compelling value. They stick with homegrown Python modules and ZPublisher. Other people find the Zope framework quite useful and so focus on developing Python code that works within the framework. It's your choice. If you're interested in developing for Zope you should check out the External Method documentation and the Product API tutorial. Also the Zope Manager's Guide explains the process of creating a Product through the Control Panel which will become much more interesting with the release of ZClasses (which are now in CVS). Good luck. -Amos
On 20 Apr 1999 10:50:00 -0500, Scott Lewis wrote:
i've got some beginner questions about zope. i spent a fair amount of time with various documentation, but couldn't find the answers.
first, the specific question. the docs talk about publishing objects, with zope translating URLs to method calls. i get the impression that i can call arbitrary Python objects through zope, but i can't get it to work. i've tried it with IIS and the included HTTP server.
let's say i want to call somemethod() in test.py. the docs say that http://localhost:9673/test/somemethod will do it. but where should test.py live? what's the home document directory of the builtin
http://localhost:9673 indicates that you are reading documentation on how to publish Python objects using ZPublisher/ZopeHTTPServer. Say you have a Python module (I'll use mine as an example) named 'pedsys.py' which contains code to create instances of Python Class objects. Now you want to create one instance and publish it using ZPublisher/ZopeHTTPServer. You can create a python module shich simply does that: psys.py: --- import pedsys psys = pedsys.Connection('pedsys/') --- You can test your module using python: $ python -i psys.py
print psys() ['example'] print psys.index_html() <TABLE BORDER=1> <TR><TH>ID</TH></TR> <TR><TD><A HREF="example">example</A></TD></TR>
(Yes, I know it's not correct HTML yet)
Now, you simply start ZPublisher/ZopeHTTPServer, and point it at the instantiation module : $ python /usr/pkg/zope/ZopeHTTPServer/ZopeHTTPServer.py psys.py and point your browser at http://localhost:9673/psys/index_html
HTTP server? and if i use IIS, how do i get it to use zope. by calling http://localhost:9673/manage, i can access the zope ODB, but not
Your example indicates that you are attempting to use ZPublisher/ZopeHTTPServer, (formerly called 'Bobo'), which is at the core of Zope, but does not include the management interface or the Zope object database, etc.
do the modules have to exist in the zope ODB? if so, how do i import them? i know about external methods, but it seems cumbersome to create them, method by method, object by object.
Zope lets you create methods using DTML, Zope Products, and External Methods. ZPublisher/ZopeHTTPServer lets you publish Python objects directly, as in my example above. IMO, the Zope approach is to build applications in a truly modular fashion, where you have small, flexible methods which adapt their behavior to their environment. Once you have one application built the Zope Way, alternates become an exercise in overriding behavior by simply changing attributes and in some cases, overriding methods.
what i want to do is create a web application for reading and writing information from a database (a registry of trainers and trainings). i have begun developing this using ASP, IIS, and SQL Server. i'm always looking for non-microsoft alternatives.
Chances are that you do't need to write Python for this sort of task. It might very well be done entirely using Zope Products and DTML. Possibly a few external methods to handle unusual circumstances that DTML or the Products you are using don't address.
it looks like i can develop business objects in python that model the business rules, then use zope to access the objects and control the presentation. in another language, those business objects would encapsulate the database access. i know zope has database adapters, but if i don't already have data in a relational database, do i even need to use one. could the application be
Good question. If your task doesn't require relational constructs but is more complex than simple attributes will provide for, I'd consider writing a Zope Product becasue Zope's built-in data types are probably not sufficient for what you need. Maybe take a look at the source for TinyTables, which is essentially a very limited, read-only tabular data type that retains data in the Zope object database. OTOH, a Zope database adaptor and some simple SQL tables would probably suffice and be a lot easier to build and maintain, especially with your database experience. Kent
participants (3)
-
Amos Latteier -
kent@tiamat.goathill.org -
Scott Lewis