[Zope] Need Help in Using :record Type in Form Variable

Evan Simpson evan@4-am.com
Tue, 21 Mar 2000 09:44:56 -0500


----- Original Message -----
From: Michel Pelletier <michel@digicool.com>

> Tanming Fong wrote:
>
> > Now processForm need to tell which and how many choice.x:record are
entered.
> > This works:
> >         <dtml-var "REQUEST['choice']">
> > that's as far as I can go. I want to do:
> >         <dtml-in "REQUEST['choice'].keys()">
> >                 <dtml-var sequence-item>:<dtml-var sequence-value>
> >         </dtml>
> > but it doesn't know what "keys()" is.
>
> > Question: how do I get the keys and values for this "choice" record in
> > processForm?
>
> Record objects do not implement a mapping interface.

In the current CVS they do.  Tanming, if you're using a source code
distribution of Zope you can change the definition of class 'record' in
ZPublisher/HTTPRequest.py to the following:

class record:
    def __getattr__(self, key, default=None):
        if key in ('get', 'keys', 'items', 'values', 'copy', 'has_key'):
            return getattr(self.__dict__, key)
        raise AttributeError, key

    def __getitem__(self, key):
        return self.__dict__[key]

    def __str__(self):
        L1 = self.__dict__.items()
        L1.sort()
        return join(map(lambda item: "%s: %s" %item, L1), ", ")

    __repr__ = __str__

Cheers,

Evan @ digicool & 4-am