formish can not display unicode error message

2 views
Skip to first unread message

Yao

unread,
Oct 25, 2010, 1:30:31 AM10/25/10
to ish.io
Hi

I got some error about display unicode error message.

some source about forms.py

formish.forms.Field

@property
def error(self):
""" Lazily get the error from the form.errors when needed """
error = self.form.errors.get(self.name, None)
if error is not None:
val = str(error)
else:
val = ''
return TemplatedString(self, 'error', val)



def _classes(self):
""" Works out a list of classes that should be applied to the
field """
schema_types = mroattrs(self.attr.__class__,'type')
widget_types = mroattrs(self.widget.widget.__class__,'type')
classes = ['field',re.sub('[0-9\*]+','n',_cssname(self))]
for t in schema_types:
classes.append('type-%s'%t.lower())
for t in widget_types:
classes.append('widget-%s'%t.lower())
if self.required:
classes.append('required')
if self.widget.css_class is not None:
classes.append(self.widget.css_class)
if str(self.error):
classes.append('error')
if getattr(self,'contains_error',None):
classes.append('contains-error')
return ' '.join(classes)

str(error) and str(self.error) will raise UnicodeEncodeError: 'ascii'
codec can't encode characters ...

Regards,
Yao

Matt Goodall

unread,
Oct 26, 2010, 4:39:32 AM10/26/10
to is...@googlegroups.com
On 25 October 2010 06:30, Yao <chunl...@gmail.com> wrote:
> Hi
>
> I got some error about display unicode error message.

Hi Yao,

You're right, trying to convert the error into a str instance is
clearly wrong. I'm not sure why it's converted at all, but I'm
guessing it's because the error may also be an exception instance.

I'll try to take a look soon.

- Matt

> --
> You received this message because you are subscribed to the Google Groups "ish.io" group.
> To post to this group, send an email to is...@googlegroups.com.
> To unsubscribe from this group, send email to ishio+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/ishio?hl=en-GB.
>
>

Wichert Akkerman

unread,
Oct 26, 2010, 4:41:31 AM10/26/10
to is...@googlegroups.com
On 10/26/10 10:39 , Matt Goodall wrote:
> On 25 October 2010 06:30, Yao<chunl...@gmail.com> wrote:
>> Hi
>>
>> I got some error about display unicode error message.
>
> Hi Yao,
>
> You're right, trying to convert the error into a str instance is
> clearly wrong. I'm not sure why it's converted at all, but I'm
> guessing it's because the error may also be an exception instance.

The use of str() and string concatenation in several places in formish
also breaks the use of zope.messageid and translationstring, making it
impossible to use translatable error messages. I carry a fairly nasty
monkeypatch in my projects as a workaround, but it would be nice to see
a better approach.

Wichert.

Reply all
Reply to author
Forward
0 new messages