On Thu, 2007-05-10 at 01:45 +0200, Thomas Rabaix wrote: > Hello, > > I have a newform object which I prepopulate some fields : > > form = MenuForm() > > tu = () > for m in Menu.objects.all(): > tu += ((m.id,m),) > form.fields['parent_id'].choices = tu > > In the case of Menu.__str__ return a utf-8 string, the SelectWidget > raise an UnicodeError. To make it work I have to make this changes : > > --- widgets.py (revision 5173) > +++ widgets.py (working copy) > @@ -168,7 +168,7 @@ > for option_value, option_label in chain(self.choices, choices): > option_value = smart_unicode(option_value) > selected_html = (option_value == str_value) and u' > selected="selected"' or '' > - output.append(u'<option value="%s"%s>%s</option>' % > (escape(option_value), selected_html, escape(smart_unicode(option_label)))) > + output.append(u'<option value="%s"%s>%s</option>' % > (escape(option_value), selected_html, > escape(smart_unicode(option_label.__str__())))) > output.append(u'</select>') > return u'\n'.join(output) > > is it a bug or am i doing something in the wrong way ?
Sounds like you option_label is wrapped in a gettext_lazy() call, which is known not to work (otherwise, adding the extra __str__ wouldn't do anything as far as I can see). Of course, there are a lot of known problems with unicode handling in trunk, which is why we have the unicode branch in development, as mentioned here a few times. Regards, Malcolm --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---