[Zope] Problem w/ lines-->List in edit form

sean.upton@uniontrib.com sean.upton@uniontrib.com
Tue, 08 May 2001 11:55:38 -0700

Weird problem I am having with "lines" properties, mapping them to a python
list in a product.

In a python product I'm working on, one class property in my primary class
is a python list (well, an enhanced list class instance based upon a python
list for underlying storage).  This keyword class has a method called
asTuple() which returns the list as a tuple; this is used to fill a DTML
edit form textarea that uses "lines" as a type for the request object upon
submission.  This seems to work right, doing this:

<textarea name="keywords:lines" cols="40" rows="6"><dtml-in
expr="keywords.asTuple()"><dtml-var sequence-item>

[Notice the line feed before the </dtml-in>...]

Upon submission, manage_edit does a self.setKeys(REQUEST['keywords']), where
setKeys() accepts a list, then removes duplicate entries, and goes through
the resulting de-duplicated list of words, and uses a list append() method
to add each entry. 

Upon submission of this form, however, it adds an empty string as the 1st
element of the list.  This doesn't happen when unit testing my python code
for my setKeys() method from the python shell.

What I am guessing is happening is that there is a blank line inserted AT
THE END of the textarea.  This is then shifted to the front when my code
runs a sort() on the list as part of the de-duplication process.  My
de-duplication code:

    def deDupe(self):
        """Scans through keyword list and de-dupes multiple entries for the
same keyword"""
        #3 things: 2 loops and a sort, plus recursion via the 2nd loop -
inefficient, but works
        for kw in self.keywords:
            if (self.keywords.count(kw) > 1):       #If duplicate(s) of
current kw, get rid of this one
                self.keywords.remove(kw)            #technically, this
removes 1st instance in list, this works
        #now, check for more duplicates, since above sometimes won't work in
cases of several repreats
        for kw in self.keywords:
            if (self.keywords.count(kw) > 1):
        self.keywords.sort()                        #sort the list

I figure that I could incorporate code to get rid of "empty" list entries.
Is there an easier way to do this?  The extra line feed at the end of the
text area ends up being a nuisance, but I'm not sure if there is a way to
get the DTML to output HTML just right so it works.  I suppose that others
have encountered this weirdness before.  Thoughts?


Sean Upton
Senior Programmer/Analyst
The San Diego Union-Tribune