Django

Code

Changeset 5375

Show
Ignore:
Timestamp:
05/28/07 08:02:16 (1 year ago)
Author:
mtredinnick
Message:

Fixed #4403 -- Stopped pushing form error messages (which are unicode strings)
through a str method.

Files:

Legend:

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

    r5332 r5375  
    137137                else: 
    138138                    help_text = u'' 
    139                 output.append(normal_row % {'errors': bf_errors, 'label': force_unicode(label), 'field': unicode(bf), 'help_text': help_text}) 
     139                output.append(normal_row % {'errors': force_unicode(bf_errors), 'label': force_unicode(label), 'field': unicode(bf), 'help_text': help_text}) 
    140140        if top_errors: 
    141141            output.insert(0, error_row % top_errors) 
  • django/branches/unicode/django/newforms/util.py

    r5310 r5375  
    11from django.utils.html import escape 
    2 from django.utils.encoding import smart_unicode 
     2from django.utils.encoding import smart_unicode, StrAndUnicode 
    33 
    44def flatatt(attrs): 
     
    1111    return u''.join([u' %s="%s"' % (k, escape(v)) for k, v in attrs.items()]) 
    1212 
    13 class ErrorDict(dict): 
     13class ErrorDict(dict, StrAndUnicode): 
    1414    """ 
    1515    A collection of errors that knows how to display itself in various formats. 
     
    1717    The dictionary keys are the field names, and the values are the errors. 
    1818    """ 
    19     def __str__(self): 
     19    def __unicode__(self): 
    2020        return self.as_ul() 
    2121 
     
    2727        return u'\n'.join([u'* %s\n%s' % (k, u'\n'.join([u'  * %s' % smart_unicode(i) for i in v])) for k, v in self.items()]) 
    2828 
    29 class ErrorList(list): 
     29class ErrorList(list, StrAndUnicode): 
    3030    """ 
    3131    A collection of errors that knows how to display itself in various formats. 
    3232    """ 
    33     def __str__(self): 
     33    def __unicode__(self): 
    3434        return self.as_ul() 
    3535 
  • django/branches/unicode/tests/regressiontests/forms/regressions.py

    r5314 r5375  
    5454u'\u0448\u0442.' 
    5555 
     56Translated error messages used to be buggy. 
     57>>> activate('ru') 
     58>>> f = SomeForm({}) 
     59>>> f.as_p() 
     60u'<p><ul class="errorlist"><li>\u041e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u043f\u043e\u043b\u0435.</li></ul></p>\n<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>' 
     61>>> deactivate() 
     62 
    5663####################### 
    5764# Miscellaneous Tests #