[Product-Developers] z3c.form - unicode problem

Umberto Calligaro u.calligaro at tecnoteca.com
Fri Mar 30 09:42:31 UTC 2012


I've solved the problem setting "ignoreContext = True", then I populate the
form in "updateWidgets" method with this code:

for key in self.widgets.keys():
    value = getattr(self.context, key)
    if isinstance(value, str):
        value = unicode(value, "utf-8", errors="ignore")
    if IDatetimeWidget.providedBy(self.widgets[key]):
        value = DateTimeParser().parse(value.strftime('%Y/%m/%d %H:%M'))
    self.widgets[key].value = value


Thanks again
Umberto Calligaro
*
*


2012/3/28 Jean-Michel FRANCOIS <toutpt at gmail.com>

> z3c.form manage only unicode where archetype use only encoded strings. You
> have to encode data before do the save.
>
> Regards / Cordialement,
> JeanMichel FRANCOIS
> Find me on Twitter <http://twitter.com/toutpt> / Retrouvez moi sur Twitter<http://twitter.com/toutpt_nantes>
>
>
>
>
> Le 28 mars 2012 17:10, Umberto Calligaro <u.calligaro at tecnoteca.com> a
> écrit :
>
>>  Hi,
>>
>> I've a problem with unicode and z3c.form.
>> This is my scenario: I've a custom contet type (CT) based on Archetypes.
>> I've made a z3c.form Form to let anonymous users edit data and the form
>> fields are generated from the interface of the CT.
>> When I call the form with "ignoreContext=False" if there's a special
>> character (something like "è","à", etc. ) in the description field, I get
>> this error:
>>
>> 2012-03-28T16:00:31 ERROR Zope.SiteErrorLog 1332943231.380.770318914895
>> http://localhost:8080/.../my-contentype/@@add-update-event
>> Traceback (innermost last):
>>   Module ZPublisher.Publish, line 126, in publish
>>   Module ZPublisher.mapply, line 77, in mapply
>>   Module ZPublisher.Publish, line 46, in call_object
>>   Module plone.z3cform.layout, line 70, in __call__
>>   Module plone.z3cform.layout, line 54, in update
>>   Module tecnoteca.associations.forms.add_update_event, line 36, in update
>>   Module z3c.form.form, line 208, in update
>>   Module plone.z3cform.patch, line 21, in BaseForm_update
>>   Module z3c.form.form, line 149, in update
>>   Module tecnoteca.associations.forms.add_update_event, line 43, in
>> updateWidgets
>>   Module z3c.form.form, line 134, in updateWidgets
>>   Module z3c.form.field, line 275, in update
>>   Module z3c.form.browser.textarea, line 36, in update
>>   Module z3c.form.browser.widget, line 70, in update
>>   Module z3c.form.widget, line 123, in update
>>   Module z3c.form.converter, line 43, in toWidgetValue
>> UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 21:
>> ordinal not in range(128)
>>
>>
>> How can I fix this problem?
>>
>> Thanks
>> Umberto Calligaro
>>
>> _______________________________________________
>> Product-Developers mailing list
>> Product-Developers at lists.plone.org
>> https://lists.plone.org/mailman/listinfo/plone-product-developers
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.plone.org/pipermail/plone-product-developers/attachments/20120330/c4c4d87c/attachment-0001.html>


More information about the Product-Developers mailing list