What's the type of something marshalled to a "record"?
Hi all Short version of my question: how do I know when a form variable has been marshalled to a record? _.same_type(var, ????) Long version: If I do this: <p> <input name="properties_to_show.ContactPerson:record:list" type="checkbox" value="id"> id <br> <input name="properties_to_show.ContactPerson:record:list" type="checkbox" value="Category"> Category [...] I can successfully do this: <dtml-let p2s="REQUEST.form['properties_to_show']"> <dtml-in "p2s.keys()"> <dtml-var sequence-item> </dtml-in> </dtml-let> But if I do this: <dtml-let p2s="REQUEST.form['properties_to_show']"> <dtml-if "_.same_type(p2s, {})"> it's a dict! <dtml-elif "_.same_type(p2s, p2s)"> it's it! </dtml-if> </dtml-let> then I get "it's it!" instead of "it's a dict!". The question again: how do I know when a form variable has been marshalled to a record? _.same_type(var, ????) Lots of TIA .. Jean Jordaan
Jean Jordaan writes:
Short version of my question: how do I know when a form variable has been marshalled to a record? _.same_type(var, ????) The form variables and their type are usually part of the actions interface.
Usually, you do not check whether the form designer used ":record" or not, but you require him to do that. Maybe because of this, there is no easy way to check for "recordness". If you really want to check it, you can create a record in an External Method and use "same_type": (in an ExternalMethod): from ZPublisher.HTTPRequest import record def getRecordInstance(): '''return an empty 'record' instance.''' return record() Dieter
Hi Dieter
Usually, you do not check whether the form designer used ":record" or not, but you require him to do that.
Yes. I wanted to iterate over REQUEST.form.keys(), though, and the form may or may not contain record instance(s). I didn't want to check for them by name.
Maybe because of this, there is no easy way to check for "recordness". If you really want to check it,
Thank you for the answer! I agree that it's probably not such a clever thing to do, though, and I've gone another way. Regards, Jean
participants (2)
-
Dieter Maurer -
Jean Jordaan