[Zope] Advice Needed.

Dylan Reinhardt zope at dylanreinhardt.com
Wed Nov 26 10:56:51 EST 2003


On Tue, 2003-11-25 at 22:45, Goldthwaite, Joe wrote:
> I'd basically like to be able to have Zope accept a URL
> something like this; http:\\MyZopeServer\IncomeStatement?rgn=80 and have it
> generate an Income Statement routine for region 80.

What you want is an IncomeStatment *method* that takes parameters such
as rgn, grp, etc.

Methods can be stand-alone objects (Python Scripts, ZPT, DTML) or they
can be attributes of more complex objects, such as you might define in a
product.


> That sounds pretty simple doesn't it?  I can't seem to put the pieces
> together.  I was able to write a python module that takes the organization
> type and number and writes an Income Statement to a file in HTML.

That's how it works externally to Zope, you mean?

If you were to use a Python Script here, you'd want to *return* HTML or
an object capable of rendering it, such as ZPT or DTML.  Both templating
languages are, themselves, able to take parameters.


>   I got the
> project from The Book of Zope working but all the forms seem to be linked to
> DTML files.

The client doesn't care what is used to process your form, it just cares
where to send it.  What resides at that URL is entirely up to you.


>   It didn't give me any examples on where to get the URL
> parameters from

Querystring parameters are simply attributes of the REQUEST object.  The
easiest way to learn about the REQUEST object is simply to view it...
create a DTML Method called "me" and give it the contents:

<dtml-var REQUEST>

Now hit server/me.  After that, try, server/me?arg1=foo&arg2=bar.



> Having been a programmer for 20 years, I'm most comfortable with programming
> languages like Python than with TAL or DTML.

That's a good thing.  Use templating primarily for presentation and
Python for pretty much everything else.  If it helps, you can think of
templates as a syntactically enhanced use of the %s operator.  They're
just text with named holes where other data gets squeezed in.


>   Ideally, I'd like the above
> URL to execute my Income Statement function and pass the org type and
> number.  My module could then return the HTML page.  The main problem I see
> with this approach (other than the fact that I can't figure out how to do
> it) is that I need to connect to the database every time.

How would you prefer data be accessed?


>   Also, the Income
> Statement module returns data appropriate to the SQL user name so I need to
> have some way to associate a Zope user with an SQL database user.

You could make that a property of the Zope user object or create a
Python Script that consists of a user:user mapping.


> 
> I work at a Microsoft shop

Boo!  Hiss!  :-)


>  and am getting a log of pressure to go with IIS
> and .Net.

>From what I hear, Zope works fine being fronted by IIS.



> So, what's the best approach to take?  Should I try to do it with Page
> Templates and python scripts?

Yes.

>  Is that efficient? Is the product approach
> better?

Products are Zope's sweet spot, so you'll definitely want to learn about
them eventually.  But you'll do better at this stage to prototype your
system in the ZMI.  You'll get visible results much faster.

Once it works there, if you want to make it portable or easily
replicated, you can port it to a product.  That's not difficult.


> I guess what I'd really like is a product that would translate the above URL
> into a call to a Python function passing in the user info, the database
> connection, the organization type and number.

If this were being done in a product, you'd have several template
objects defined (similar to first line) and a method that takes the
REQUEST object as a parameter and returns a template object when it's
done doing whatever it does:

----

some_template = PageTemplateFile('path/from/product/folder', globals())

...

def IncomeStatement(self, request):
    ''' You need a docstring here '''
    rgn = int(request.form.get('rgn', 0))
    if rgn:
        # do stuff here
        request['foo'] = bar  # <-- pass bar to template
    return self.some_template

----


>  It doesn't seem like that
> would be too hard for someone who knows what they're doing.  So far, I
> haven't had much success.

Like anything, it gets easier as you become familiar with the idioms.  

HTH,

Dylan




More information about the Zope mailing list