[Zope] newbie question

Tony McDonald tony.mcdonald@ncl.ac.uk
Sun, 04 Jul 1999 09:11:34 +0100


> Thanks for your help Tony/Bill
> 
> I'm making progress with this but have a few more questions:
>
> 1.      I've just worked out I need to pass two parameters to the second query
> (branch and customer no). If I hardcode the branch no into the SQL method and
> pass only the customer number  it works, but how do I pass both variables?
I've
> tried using a + and & between the two variables as below but no joy.
>
>         <tr>
>           <td><a href="linktest02?Branch=<!--#var
> cu_branch-->&linktest02?Customer=<!--#var cu_customer-->"</a>
>             <!--#var cu_branch null=""--> / <!--#var cu_customer
null=""--></td>
>
>           <td><!--#var cu_name null=""--></td>
>           <td><!--#var cu_street_add3 null=""--></td>
>         </tr>
>

Alexander has given you the good stuff about URL encoding etc...

>
> 2.     Tony - in your edit_me object :
>
>        <!--#if staff_number-->
>         <!--#in expr="find_staff_number(staff_number=staff_number)"-->
>
>     I can't work out where the expr=find_staff_number ties into all the other
> code, is it another separate query like find_staff?
>
>

Apologies for that, it is a separate query, the single argument is
staff_number

select
staff_number,
title,
forename,
surname,
department,
job_title,
tel_no,
fax_no,
email
from staff where staff_number = '<!--#var staff_number-->'
order by surname asc

> 3.    In the find_staff query:
>
>     <!--#in expr="find_staff(search_field=search_type,
search_item=search_term)"
>
>     size=8 orphan=1 start=query_start-->
>
>     Is "search_field=search_type, search_item=search_term" using named fields
> from your database or is it just a general piece of code I can use as is?
>

Again, more apologies here. The find_staff object is a ZSQL method too:
arguments are 'search_field search_item' (no , between them)

select
staff_number,
title,
forename,
surname,
department,
job_title,
tel_no,
fax_no,
email
from staff where <!--#var search_field--> like <!--#sqlvar search_item
type=string-->
order by surname asc

If you look closely, you'll see that we're using Zope to tell the SQL query
what field to search on (ie, is search_field = 'tel_no' and search_item =
'%0191%' the query is actually:

select
staff_number,
title,
forename,
surname,
department,
job_title,
tel_no,
fax_no,
email
from staff where tel_no like '%0191%'
order by surname asc

(this can be really useful!)

The ZSQL query uses the arguments search_field and search_item, but is
passed the Zope variables search_type and search_term. Within the HTML
<FORM> we have [1]:

<a href="display_all_staff?search_term=a%">A</a>
<a href="display_all_staff?search_term=b%">B</a>
etc.
This part of the code allows all staff whose surname begins with 'a', 'b'
etc. to be displayed easily.

we also have a popup menu, allowing the user to select what field to search
on:
   <select name=search_type>
    <option value="surname" selected>Lastname
    <option value="forename">Firstname
    <option value="department">Department
    <option value="title">Title
    <option value="job_title">Job Title
    <option value="tel_no">Telephone
    <option value="fax_no">Fax
    <option value="email" >Email
   </select>

This is where the Zope variables search_field and search_term are defined.

We also have another input type
<input type=text name=searchit>

Which is used for free-form text entry (ie a query that is more complex than
the ones in [1])

If the person has put something in the searchit input (ie they want a more
complex lookup), we need to do some Zope Voodoo..

<!--#if searchit-->
 <!--#call "REQUEST.set('search_term','%'+searchit+'%')"-->
<!--#/if-->

All this does is to create a new variable 'search_term' to '%' + value of
search_it +'%' ready for the ZSQL method. Zope2 has a *much* nicer way of
doing this, but let's not muddy the water too much.

Some more Voodoo is needed to make sure that the two arguments we send to
the ZSQL method are defined;

<!--#unless search_term-->
 <!--#call "REQUEST.set('search_term','%')"-->
<!--#/unless-->
<!--#unless search_type-->
 <!--#call "REQUEST.set('search_type','surname')"-->
<!--#/unless-->

Then we call the ZSQL method;

<!--#in expr="find_staff(search_field=search_type, search_item=search_term)"
size=8 orphan=1 start=query_start-->
...
<!--#/in-->

> Really appreciate your help as I've been given two weeks to put together a
> demonstration intranet and I've never seen Zope (or anything else before) and
> only have the User Guides for help. Major learning curve!! Thanks
>
> Jenny

Stick with it! - Zope has some weird ways of doing things it's true, but
some things it does are quite beautiful (what a word to use when describing
software! :) - and just wait until you get the hang of
Acquisition...awesome.

Grab hold of the How-To docs and scour them, get hold of the archives of the
mailing list, ask questions here and don't forget that if you have a budget
for setting up this demo, then you can call on the DC people who will help
you set up a killer intranet demo!

HTH
Tone,