[Zope] Calculations - more dumb questions.

Tres Seaver tseaver@palladion.com
Wed, 23 Feb 2000 15:43:54 -0600


Richard Moon <richard@dcs.co.uk> writes:
> 
> I was reading earlier postings about 'variables' or the lack of them in
> Zope and I went off and investigated Python Methods and External Methods
> and I've got them working  ... but .. I can't figure out how to use them to
> solve my problem ...
> 
> I have an SQL method and I've generated the form and results report using
> the standard wizard - absolutely wonderful.
> 
> Let's say I have an input variable, called 'customer' on the form which is
> passed to the SQL method. BUT I want to intercept that variable and do
> something with it, let's keep it simple and say that I want to put the
> string "CT" in front of what the user enters (I know that's trivial but for
> the sake of argument).
> 
> I can write an External Method or Python Method which does the necessary
> but it returns the string back to the calling object as text which is
> displayed by the browser.
> 
> Can anyone tell me how to get that new string back into the variable
> 'customer'.
> 
> Please :-)

Ok, say your form is in a DTML Method called "gather_criteria".  Make its ACTION
attribute point to another DTML Method, "prepare_query".  Inside prepare_query,
munge the value of customer and call the SQL method, 'query_db'::

  <dtml-call "REQUEST.set( 'customer', 'CT' + customer )">
  <dtml-in query_db>
    <!-- do stuff with row data here -->
  </dtml-in>

If the munging is more complicated, then write a Python method,
"munge_customer_id", which takes the user-supplied value returns the munged
value::

  return "%08d" % _.int( customer ) # pad with leading zeroes to 8 digits

Then call the munge_customer_id inside prepare_query::

  <dtml-call "REQUEST.set( 'customer', munge_customer_id( customer ) )">

HTH,

Tres.
-- 
=========================================================
Tres Seaver         tseaver@palladion.com    713-523-6582
Palladion Software  http://www.palladion.com