Need Help in Using :record Type in Form Variable
I've read http://www.zope.org/Members/Zen/howto/FormVariableTypes and a few other HOW-TO's and still haven't figured out how to make use of the :record type in form variables. My form looks like: <form method="post" action="processForm"> <input type=text name=choice.1:record> <input type=text name=choice.3:record> <input type=text name=choice.10:record> <input type=submit> </form> 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? Thanx, -Tanming Fong
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. Form elements are turned into attributes of your 'choice' object, so your objects has instance attributes named 1, 3, and 10. You will need to use _.getattr() to access these attributes since numbers are not very good attribute names. It might be a good idea to look into a new ZPublisher type called :dictionary (or :mapping) that works much like :record, it would be fairly trivial to implement, want to take a stab at it? -Michel
----- 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
participants (3)
-
Evan Simpson -
Michel Pelletier -
Tanming Fong