[Zope] int's as keys for dictionaries

Chris Withers 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>
>  </dtml-in>

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:

<tr tal:repeat="parameters 
python:here.sql_list_test_parameters_for_test(test_uid=d_test_uid)">
<td>Record <tal:x replace="parameters/uid"></td>
<td>
<input type="hidden" name="d_test_parameter.uid:int:record"
        tal:attributes="value parameters/uid">
<input type="checkbox" name="d_test_parameter.something:record:ignore_empty"
        tal:attributes="value parameters/something"/>
<!-- etc -->
</td>
</tr>

then, in your processing script, "print context.REQUEST.d_test_parameter" will give:

(('uid':1,'something':'xxx'),('uid':2,'something':'yyy'))

> 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 ;-)

cheers,

Chris

-- 
Simplistix - Content Management, Zope & Python Consulting
            - http://www.simplistix.co.uk




More information about the Zope mailing list