[Zope] Re: More product writing problems

Tille, Andreas TilleA@rki.de
Wed, 5 Dec 2001 13:12:45 +0100 (CET)


  This message is in MIME format.  The first part should be readable text,
  while the remaining parts are likely unreadable without MIME-aware tools.
  Send mail to mime@docserver.cac.washington.edu for more info.

--8323328-1105350745-1007554365=:26401
Content-Type: TEXT/PLAIN; charset=US-ASCII

On Wed, 5 Dec 2001, Seb Bacon wrote:

> - hack the propertymanager code
How far is this different from the latest one?

> - create custom property editing screens which post to a pythonscript,
> which strips the whitespace before storing it
Hmm, seems me not as good as the other suggestion, but I might be wrong
because of a lack of experience.

> - deal with the whitespace issue inside your product - do a
> getProperty() method which strips before returning
I tried to add the following Method to my product:

def getProperty(self, id, d=None):
    """Get the property 'id', returning the optional second
       argument or None if no such property is found."""
    if self.hasProperty(id):
        if id == 'keywords' :                      # +
            safe_keywords=self.keywords            # +
            self.keywords=[]                       # +
            for keyword in save_keywords:          # +
                keyword=keyword.strip()            # +
                if keyword != '' :                 # +
                    self.keywords.append(keyword)  # +
        return getattr(self, id)
    return d

I took the code crom PropertyManager and added the marked (# +) lines.
I'm not sure if I did this right but it does not work as expected.
Any idea how to debug such kind of code?  (To make sure that there is
no other problem I attached the whole code.)


Another problem I see is that I want to test in a DTML Document, whether
there are keywords defined or not (resp. if I'm in an MyFolder or not).

The following just raises just an AttributeError.

 getattr(object, string)
Return the value of the named attributed of object. name must be a string. If the string is the name of one of the object's attributes, the result is the value of that attribute. For example, getattr(x, "foobar") is equivalent to x.foobar. If the named attribute does not exist, default is returned if provided, otherwise AttributeError is raised.

How can I do this cleanly?

Kind regards and many thanks for your great help

         Andreas.


--8323328-1105350745-1007554365=:26401
Content-Type: TEXT/PLAIN; charset=US-ASCII; name="MyFolder.py"
Content-Transfer-Encoding: BASE64
Content-ID: <Pine.LNX.4.33.0112051312450.26401@wr-linux02.rki.ivbb.bund.de>
Content-Description: 
Content-Disposition: attachment; filename="MyFolder.py"

IyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIy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-1007554365=:26401--