MaxSizeValidator custom max size

"George Lee" <[email protected]>
Newsgroups gmane.comp.web.zope.plone.archetypes.devel
Message-ID <[email protected]>
MaxSizeValidator has the following code to allow a class/instance to
override how the maximum size for a field is evaluated:

elif hasattr(aq_base(instance), 'getMaxSizeFor'):
            maxsize = instance.getMaxSizeFor(field.getName())

The problem is, that if 2+ fields use MaxSizeValidator, but
'getMaxSize' is only defined for one of the fields, then the other
field will cause an error when this line is run. The code should
instead look something like this:

        if kwargs.has_key('maxsize'):
            maxsize = kwargs.get('maxsize')
        else:
            maxsize = None
            if hasattr(aq_base(instance), 'getMaxSizeFor'):
                try:
                    maxsize = instance.getMaxSizeFor(field.getName())
                except:
                    pass
            if maxSize != None:
                if hasattr(field, 'maxsize'):
                    maxsize = field.maxsize
                else:
                    # set to given default value (default defaults to 0)
                    maxsize = self.maxsize

Peace,
George


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid0944&bid$1720&dat1642
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.