[Zope] publishing objects

Kent Polk kent@goathill.org
20 Apr 1999 17:57:20 GMT


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