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 = open(self.user_dir+'/msg_list', 'r')
                spl = re.compile('\s\|\s')
                for msg_line in lr.readline():
                        num_from_sub = []
                        num_from_sub = spl.split(msg_line, 2)
                        print num_from_sub
                        self.msgnum = num_from_sub[0]
                        self.msgfrom = 'This is from UNKNOWN'
                        self.msgsub = '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>
                <td><a href="/spool/&dtml-user;/get_message?&dtml-msgnum;">&dtml-msgfrom;</a></td>
                <td><a href="/spool/&dtml-user;/get_message?&dtml-msgnum;">&dtml-msgsub;</a></td>
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.

Reply via email to