Ticket #2554: r3598_unicode_formfields.patch

File r3598_unicode_formfields.patch, 2.0 KB (added by Victor Ng <victor.ng@…>, 18 years ago)

Patch to fix FormFieldWrapper rendering when data includes unicode

  • django/db/models/fields/__init__.py

     
    290290            return first_choice + list(self.choices)
    291291        rel_model = self.rel.to
    292292        if hasattr(self.rel, 'get_related_field'):
    293             lst = [(getattr(x, self.rel.get_related_field().attname), str(x)) for x in rel_model._default_manager.complex_filter(self.rel.limit_choices_to)]
     293            lst = [(getattr(x, self.rel.get_related_field().attname), unicode(x)) for x in rel_model._default_manager.complex_filter(self.rel.limit_choices_to)]
    294294        else:
    295             lst = [(x._get_pk_val(), str(x)) for x in rel_model._default_manager.complex_filter(self.rel.limit_choices_to)]
     295            lst = [(x._get_pk_val(), unicode(x)) for x in rel_model._default_manager.complex_filter(self.rel.limit_choices_to)]
    296296        return first_choice + lst
    297297
    298298    def get_choices_default(self):
  • django/forms/__init__.py

     
    158158
    159159    def __str__(self):
    160160        "Renders the field"
    161         return str(self.formfield.render(self.data))
     161        return unicode(self.formfield.render(self.data))
    162162
    163163    def __repr__(self):
    164164        return '<FormFieldWrapper for "%s">' % self.formfield.field_name
  • django/template/__init__.py

     
    736736    def encode_output(self, output):
    737737        # Check type so that we don't run str() on a Unicode object
    738738        if not isinstance(output, basestring):
    739             return str(output)
     739            return unicode(output)
    740740        elif isinstance(output, unicode):
    741741            return output.encode(settings.DEFAULT_CHARSET)
    742742        else:
Back to Top