Opened 17 years ago

Closed 17 years ago

#3266 closed defect (duplicate)

RadioSelect broken -- UnicodeDecodeError

Reported by: Honza Král <Honza.Kral@…> Owned by: Adrian Holovaty
Component: Forms Version:
Severity: normal Keywords:
Cc: Honza.Kral@…, jl@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

test application:

templates/test_form.html:

{{ form }}

views.py:

# -*- coding: utf-8 -*-
                
from django import newforms as forms         
from django.shortcuts import *               
                
class TestForm( forms.Form ):
    sel_field = forms.ChoiceField(                                                                                                                                                                            
                    label=Žluťoučký kůň',  
                    choices=[
                        ( u'Žluťoučký', u'úpěl ďábelské ódy' ),
                        ( u'Žluťoučký', u'úpěl ďábelské ódy' ) 
                    ],
                    widget=forms.RadioSelect                                                                                                                              
                )
                
                
def test_view( request ):
    return render_to_response( "test_form.html", { 'form' : TestForm() } )                                                                                        

urls.py:

from django.conf.urls.defaults import *
       
urlpatterns = patterns('',
    (r'^test_form/$', 'myTest.views.test_view' ),                                                                                                                         
)  

If you change the widget to Select, everything works OK, with the RadioSelect it fails on UnicodeDecode error.
Unfortunately I do not understand UNICODE in python (I am fairly new to the language) so I cannot fix it myself without guessing.

Change History (7)

comment:1 by jl@…, 17 years ago

Cc: jl@… added

Same error here!
I came across the UnicodeDecodeError when I tried to fetch data for dynamic choices that contains non-ascii characters.
For now I solved it by encoding the special characters as html entities which is lame. Especially because the same choices work for widget.Select.

Please help
This bug renders widget.RadioSelect pointless for other languages than non-ascii languages and i18n'ed sites.

comment:2 by Adrian Holovaty, 17 years ago

Resolution: fixed
Status: newclosed

(In [4304]) Fixed #3266 -- newforms: Made RadioSelect accept funky characters. Thanks for reporting, Honza Kral

comment:3 by nazar.v.ch@…, 17 years ago

Resolution: fixed
Status: closedreopened

This code still raises UnicodeDecodeError.

Changing

return self.__unicode__().encode(settings.DEFAULT_CHARSET)

to

return self.__unicode__()

in StrAndUnicode fixes this error.

comment:4 by adurdin@…, 17 years ago

Is this a duplicate of #3597?

comment:5 by Gary Wilson <gary.wilson@…>, 17 years ago

Can anyone confirm that this has been fixed as of [4924]?

comment:6 by Gary Wilson <gary.wilson@…>, 17 years ago

Triage Stage: UnreviewedAccepted

comment:7 by Malcolm Tredinnick, 17 years ago

Resolution: duplicate
Status: reopenedclosed

Yes, this is a dupe of #3597. The test included in that patch is basically the same as the example given here. I've improved that test slightly in [5226] (on the unicode branch only, but will eventually be merged back to trunk) to more or less match this example exactly and it still passes.

Note: See TracTickets for help on using tickets.
Back to Top