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

Tino Wildenhain tino@wildenhain.de
Tue, 08 May 2001 22:39:53 +0200

Hi sean,

I would use the following code:

def deDupe(self):
   for kw in self.keywords:
       if kw and not kw in keywords:

Assuming your empty line is really empty.

Tino Wildenhain

--On Dienstag, 8. Mai 2001 11:55 -0700 sean.upton@uniontrib.com wrote:

> 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>
> </dtml-in></textarea>
> [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.deDupe()
>         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
> =========================
> Sean Upton
> Senior Programmer/Analyst
> SignOnSanDiego.com
> The San Diego Union-Tribune
> 619.718.5241
> sean.upton@uniontrib.com
> =========================
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists -
>  http://lists.zope.org/mailman/listinfo/zope-announce
>  http://lists.zope.org/mailman/listinfo/zope-dev )