[Zope] dtml-in over the output from my method

Tim Hicks tim.hicks@iname.com
Mon, 6 Nov 2000 20:45:57 -0000


This is a multi-part message in MIME format.

------=_NextPart_000_0048_01C04832.905AAC40
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

I am trying to create a zope product in python but have got stuck with =
using the dtml-in tag to iterate over a method (or is it a function? I =
get a little mixed up) of my class. Here is the method,

        def list_messages(self):
                lr =3D open(self.user_dir+'/msg_list', 'r')
                spl =3D re.compile('\s\|\s')
                for msg_line in lr.readline():
                        num_from_sub =3D []
                        num_from_sub =3D spl.split(msg_line, 2)
                        print num_from_sub
                        self.msgnum =3D num_from_sub[0]
                        self.msgfrom =3D 'This is from UNKNOWN'
                        self.msgsub =3D 'My special subject'
                        return self.msgnum, self.msgfrom, self.msgsub

And here is an extract from the dtml file that is supposed to display =
the output,

<dtml-in list_messages>
        <tr>
                <td><a =
href=3D"/spool/&dtml-user;/get_message?&dtml-msgnum;">&dtml-msgfrom;</a><=
/td>
                <td><a =
href=3D"/spool/&dtml-user;/get_message?&dtml-msgnum;">&dtml-msgsub;</a></=
td>
        </tr>
</dtml-in>

However, this does not produce the desired effect. I don't know if it is =
obvious from what I've written, but basically, the three variables =
(self.msgnum, self.msgfrom and self.msgsub) are supposed to be inserted =
into the appropriate place in the table, and then the 'for' statement =
re-executed (producing different values for the variables) with the =
subsequent values being inserted into the next line of the table etc... =
until there are no more lines to be read from lr. I'm not sure if that =
is clear or not, sorry. Obviously, this does not work as the dtml-in =
simply iterates over each of the returned variables (instead of over the =
for statement). I can't seem to make it do what I want. Does anyone have =
any ideas? Much obliged if you do.

Cheers

tim


------=_NextPart_000_0048_01C04832.905AAC40
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2614.3500" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>I am trying to create a zope product in =
python but=20
have got stuck with using the dtml-in tag to iterate over a method (or =
is it a=20
function? I get a little mixed up) of my class. Here is the =
method,</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial =
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; def=20
list_messages(self):<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
lr =3D open(self.user_dir+'/msg_list',=20
'r')<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;=20
spl =3D=20
re.compile('\s\|\s')<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
for msg_line in=20
lr.readline():<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;=20
num_from_sub =3D=20
[]<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
num_from_sub =3D spl.split(msg_line,=20
2)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
print=20
num_from_sub<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;=20
self.msgnum =3D=20
num_from_sub[0]<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;=20
self.msgfrom =3D 'This is from=20
UNKNOWN'<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;=20
self.msgsub =3D 'My special subject'</FONT></DIV>
<DIV><FONT face=3DArial=20
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;=20
return self.msgnum, self.msgfrom, self.msgsub</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>And here is&nbsp;an extract from the =
dtml file that=20
is supposed to display the output,</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&lt;dtml-in=20
list_messages&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
&lt;tr&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
&lt;td&gt;&lt;a=20
href=3D"/spool/&amp;dtml-user;/get_message?&amp;dtml-msgnum;"&gt;&amp;dtm=
l-msgfrom;&lt;/a&gt;&lt;/td&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
&lt;td&gt;&lt;a=20
href=3D"/spool/&amp;dtml-user;/get_message?&amp;dtml-msgnum;"&gt;&amp;dtm=
l-msgsub;&lt;/a&gt;&lt;/td&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;=20
&lt;/tr&gt;<BR>&lt;/dtml-in&gt;<BR></FONT></DIV>
<DIV><FONT face=3DArial size=3D2>However, this does not produce the =
desired effect.=20
I don't know if it is obvious from what I've written, but basically, the =
three=20
variables (self.msgnum, self.msgfrom and self.msgsub) are supposed to be =

inserted into the appropriate place in the table, and then the 'for' =
statement=20
re-executed (producing different values for the variables) with the =
subsequent=20
values being inserted into the next line of the table etc... until there =
are no=20
more lines to be read from lr. I'm not sure if that is clear or not, =
sorry.=20
Obviously, this does not work as the dtml-in simply iterates over each =
of the=20
returned variables (instead of over the for statement). I can't seem to =
make it=20
do what I want. Does anyone have any ideas? Much obliged if you =
do.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Cheers</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>tim</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;</DIV></FONT></BODY></HTML>

------=_NextPart_000_0048_01C04832.905AAC40--