Django

Code

Changeset 5236

Show
Ignore:
Timestamp:
05/14/07 11:06:27 (1 year ago)
Author:
mtredinnick
Message:

unicode: Changed a few more places in newforms where str() was being used with
potential non-ASCII arguments. Refs #3406 (and added a test for the latter).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/unicode/django/newforms/fields.py

    r5126 r5236  
    360360        if value == u'': 
    361361            return value 
    362         valid_values = set([str(k) for k, v in self.choices]) 
     362        valid_values = set([smart_unicode(k) for k, v in self.choices]) 
    363363        if value not in valid_values: 
    364364            raise ValidationError(ugettext(u'Select a valid choice. That choice is not one of the available choices.')) 
  • django/branches/unicode/django/newforms/forms.py

    r5214 r5236  
    55from django.utils.datastructures import SortedDict, MultiValueDict 
    66from django.utils.html import escape 
    7 from django.utils.encoding import StrAndUnicode 
     7from django.utils.encoding import StrAndUnicode, smart_unicode 
    88from fields import Field 
    99from widgets import TextInput, Textarea, HiddenInput, MultipleHiddenInput 
     
    312312        """ 
    313313        auto_id = self.form.auto_id 
    314         if auto_id and '%s' in str(auto_id): 
    315             return str(auto_id) % self.html_name 
     314        if auto_id and '%s' in smart_unicode(auto_id): 
     315            return smart_unicode(auto_id) % self.html_name 
    316316        elif auto_id: 
    317317            return self.html_name 
  • django/branches/unicode/django/newforms/models.py

    r5229 r5236  
    55 
    66from django.utils.translation import ugettext 
     7from django.utils.encoding import smart_unicode 
    78from util import ValidationError 
    89from forms import BaseForm, DeclarativeFieldsMetaclass, SortedDictFromList 
     
    121122            yield (u"", self.empty_label) 
    122123        for obj in self.queryset: 
    123             yield (obj._get_pk_val(), str(obj)) 
     124            yield (obj._get_pk_val(), smart_unicode(obj)) 
    124125        # Clear the QuerySet cache if required. 
    125126        if not self.cache_choices: 
  • django/branches/unicode/tests/regressiontests/forms/regressions.py

    r5229 r5236  
    3737>>> f.as_p() 
    3838u'<p><label for="id_somechoice_0">\xc5\xf8\xdf:</label> <ul>\n<li><label><input type="radio" id="id_somechoice_0" value="\xc5" name="somechoice" /> En tied\xe4</label></li>\n<li><label><input type="radio" id="id_somechoice_1" value="\xf8" name="somechoice" /> Mies</label></li>\n<li><label><input type="radio" id="id_somechoice_2" value="\xdf" name="somechoice" /> Nainen</label></li>\n</ul></p>' 
     39 
     40Testing choice validation with UTF-8 bytestrings as input (these are the 
     41Russian abbreviations "мес." and "шт.". 
     42 
     43>>> UNITS = (('\xd0\xbc\xd0\xb5\xd1\x81.', '\xd0\xbc\xd0\xb5\xd1\x81.'), ('\xd1\x88\xd1\x82.', '\xd1\x88\xd1\x82.')) 
     44>>> f = ChoiceField(choices=UNITS) 
     45>>> f.clean(u'\u0448\u0442.') 
     46u'\u0448\u0442.' 
     47>>> f.clean('\xd1\x88\xd1\x82.') 
     48u'\u0448\u0442.' 
    3949"""