#4291: Unicode bug with gettext variables in newforms/widgets.py
-----------------------------------------+----------------------------------
Reporter:  Fidel Ramos <[EMAIL PROTECTED]>  |       Owner:  adrian              
  
  Status:  new                           |   Component:  django.newforms       
 Version:  SVN                           |    Keywords:  unicode gettext widget
   Stage:  Unreviewed                    |   Has_patch:  1                     
-----------------------------------------+----------------------------------
 {{{newforms/widgets.py}}} has a bug related to {{{gettext}}}. I have a
 select widget in a form template with several options, translated with
 {{{gettext_lazy}}}. The rendering of the template fails with an
 {{{UnicodeDecodeError}}} exception with a message like
 {{{
 'ascii' codec can't decode byte 0xc3 in position 8: ordinal not in
 range(128)
 }}}
 
 Following the callback, trouble arises from calls like this in
 {{{newforms/widgets.py}}}:
 {{{
 
escape(smart_unicode(string_variable_with_non_english_chars_translated_by_gettext))
 }}}
 
 The fix is simple: exchange the order of the calls to {{{escape()}}} and
 {{{smart_unicode()}}}:
 {{{
 
smart_unicode(escape(string_variable_with_non_english_chars_translated_by_gettext))
 }}}
 
 These are some code snippets that mimic the application in which I
 detected the problem:
 
 model.py:
 {{{
 FOO_LIST = (('A', _('A msgid'),)
 
 class FooModel(models.Model):
    a_list = models.StringField(choices=FOO_LIST)
 }}}
 
 django.po:
 {{{
 msgid "A msgid"
 msgstr "Nön-ÁSCII chäráctèrs"
 }}}
 
 view.py:
 {{{
 FooForm = forms.form_for_model(FooModel)
 f = FooForm()
 return render_to_response('footemplate.html', {'f': f})
 }}}
 
 footemplate.html:
 {{{
 ...
 {{ f }}
 ...
 }}}

-- 
Ticket URL: <http://code.djangoproject.com/ticket/4291>
Django Code <http://code.djangoproject.com/>
The web framework for perfectionists with deadlines
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to