[Zope-DB] Get value from selected item

Charlie Clark charlie@begeistert.org
Wed, 29 Jan 2003 13:26:39 +0100


On 2003-01-29 at 12:51:55 [+0100], Kerstin Petersen wrote:
> Hi,
> this is probably a beginners question.
aren't they all? 
 
> My question:
> 
> 1. I created a database connection
> 2. a sql method (GetMitarbeiter) is called by a dtml method 
> (Mitarbeiter) to display a list of empoyees.

I think the idea is to phase DTML out for presentation and use 
PageTemplates instead - they're nicer to use when you start doing these 
kind of things.

> <h1>Mitarbeiter </h1>
> 
>   <h3>
>    <dtml-in GetMitarbeiter>
>     <li>
>       <a href=MitarbeiterEmail>
^^^^^^^^^^^^ won't this generate a name error?
or is this the output HTML you want?

>       <dtml-var Titel> <dtml-var Vorname> <dtml-var Nachname>
>      </a>
>    <dtml-var statusname>
>    </dtml-in>
>   </h3>
> 
> SQL method GetMitarbeiter:
> select MitarbeiterNr,Titel,Vorname,Nachname,StatusName from 
> Mitarbeiter,M_Status
> where Mitarbeiter.status1=M_Status.statusNr order by MitarbeiterNr
> 
> DTML method MitarbeiterEmail:
> <h1>Email</h1>
>   <h1>
>    <dtml-in GetEmail>
>        <li><dtml-var email>
>    </dtml-in>
>   </h1>
> 
> GetEmail:
> argument: Mitarbeiter=1
> select email from Mitarbeiter where
> <dtml-sqltest MitarbeiterNr op=eq type=string>
> 
> 3. in the dtml method object(Mitarbeiter) the names of the employees are 
> referenced to an other dtml method object(MitarbeiterEmail) that calls an 
> other sql method (GetEmail) to get the email from the selected employee.
> 
> My question: How can I get the value of the MitarbeiterId of the selected 
> employee or write it to a variable instead of an input argument. I would 
> like to use the result, that is dependend on the selected employee, in 
> the sql method to get only the email of the selected employee.

I don't understand why you're using two SQL calls here. You can always just 
add it to the first select so you've got it if you need it.

ie.
SQL method GetMitarbeiter:
select MitarbeiterNr,Titel,Vorname,Nachname,StatusName, email from 
Mitarbeiter,M_Status
where Mitarbeiter.status1=M_Status.statusNr order by MitarbeiterNr

DTML:
<html>
<head></head>
<body>
<h1>Mitarbeiter </h1>
  <h3>
   <dtml-in GetMitarbeiter>
<a href="mailto:<dtml-var email>"><dtml-var Titel> <dtml-var Vorname> 
<dtml-var Nachname></a>
   <dtml-var statusname>
   </dtml-in>
  </h3>
</body>
</html>

or ZPT:
<html>
<html>
<head></head>
<body>
<div tal:define="results here/GetMitarbeiter | nothing"
tal:omit-tag="">
<h1>Mitarbeiter </h1>
  <h3 tal:repeat="result results">
<a tal:attributes="href string: mailto:${result/email}"
tal:content="string ${result/title} ${result/vorname} 
${result/nachname}"></a>
   <br tal:replace="result/statusname">
  </h3>
</body>
</html>

Although I'm not too keen on string expressions and often just use <span 
tal:replace="result/item"></span> instead I think the ZPT is more legible 
than the DTML and it will give you an error about incorrect HTML before it 
is rendered which DTML won't.

Hope this helps