[Zope] int's as keys for dictionaries
chris at simplistix.co.uk
Mon May 31 05:30:14 EDT 2004
Bryce Harrington wrote:
> Thanks, but yes, I know about this. But that is for the _value_,
> whereas in my situation the conversion is occuring for the _key_.
> Specifically, my input form has widgets like:
> <dtml-in prefix="loop" expr="method.sql_list_test_parameters_for_test(test_uid=d_test_uid)">
> <input type="checkbox" name="d_test_parameter.<dtml-var uid>:record:ignore_empty" value="1" /></td>
Argh! What are you doing?! ;-)
> ints), but in putting them into record form, Zope is converting the keys
> to strings.
Er. No. I think you'll find browsers and http forms have no concept of anything
other than character data and so Zope is doing nothing, as it should.
What you want when using the record type is:
<td>Record <tal:x replace="parameters/uid"></td>
<input type="hidden" name="d_test_parameter.uid:int:record"
<input type="checkbox" name="d_test_parameter.something:record:ignore_empty"
<!-- etc -->
then, in your processing script, "print context.REQUEST.d_test_parameter" will give:
> Now, it happens that the values also need to be ints in some cases (but
> the user can leave them blank), but that's a separate issue. I did try
> appending the ":int" to that, but there were two problems. First, by
> putting ":int" on the end it appears to make the field required - i.e.,
> the user can't leave it blank;
Indeed. DateTime's are even more fun ;-)
> since there's a ":required" one, but have not yet found it. Second, if
> the user enters a non-int value, Zope catches it and displays an error
> page (which is good) but I have not been able to find out how to replace
> that error message with a user friendly one of my own, and from what
> I've read on the Zope site, there is no such capability (which is bad).
standard_error_message. But doing this kindof validation error catching there is
a PITA. I normall just don't use things like :int and :date unless they're
hidden form variables that are already populated, like your uid...
> So it looks like in order to address both these issues, I need to forgo
> the ":int" modifier and create my own error handling system. I took
> this from reading http://www.zope.org/Members/Zen/howto/FormVariableTypes.
You could just use Formulator ;-)
Simplistix - Content Management, Zope & Python Consulting
More information about the Zope