From 1e8d1c808bf027be1c26329dc8695daa44cea293 Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Mon, 28 May 2007 11:04:13 +0000 Subject: [PATCH] unicode: Fixed a problem when models had non-ASCII bytestrings for their verbose_name. git-svn-id: http://code.djangoproject.com/svn/django/branches/unicode@5372 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/db/models/options.py | 7 ++++--- tests/modeltests/basic/models.py | 1 + tests/regressiontests/model_regress/__init__.py | 0 tests/regressiontests/model_regress/models.py | 16 ++++++++++++++++ 4 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 tests/regressiontests/model_regress/__init__.py create mode 100644 tests/regressiontests/model_regress/models.py diff --git a/django/db/models/options.py b/django/db/models/options.py index bf604894c4..1228c06852 100644 --- a/django/db/models/options.py +++ b/django/db/models/options.py @@ -6,6 +6,7 @@ from django.db.models.loading import get_models from django.db.models.query import orderlist2sql from django.db.models import Manager from django.utils.translation import activate, deactivate_all, get_language, string_concat +from django.utils.encoding import force_unicode, smart_str from bisect import bisect import re @@ -90,9 +91,9 @@ class Options(object): def __repr__(self): return '' % self.object_name - + def __str__(self): - return "%s.%s" % (self.app_label, self.module_name) + return "%s.%s" % (smart_str(self.app_label), smart_str(self.module_name)) def verbose_name_raw(self): """ @@ -102,7 +103,7 @@ class Options(object): """ lang = get_language() deactivate_all() - raw = unicode(self.verbose_name) + raw = force_unicode(self.verbose_name) activate(lang) return raw verbose_name_raw = property(verbose_name_raw) diff --git a/tests/modeltests/basic/models.py b/tests/modeltests/basic/models.py index bac3f1c2e4..90e5d1755c 100644 --- a/tests/modeltests/basic/models.py +++ b/tests/modeltests/basic/models.py @@ -1,3 +1,4 @@ +# coding: utf-8 """ 1. Bare-bones model diff --git a/tests/regressiontests/model_regress/__init__.py b/tests/regressiontests/model_regress/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/regressiontests/model_regress/models.py b/tests/regressiontests/model_regress/models.py new file mode 100644 index 0000000000..8b43c1c3e1 --- /dev/null +++ b/tests/regressiontests/model_regress/models.py @@ -0,0 +1,16 @@ +# coding: utf-8 +from django.db import models + +class Article(models.Model): + headline = models.CharField(maxlength=100, default='Default headline') + pub_date = models.DateTimeField() + + class Meta: + ordering = ('pub_date','headline') + # A utf-8 verbose name (Ångström's Articles) to test they are valid. + verbose_name = "\xc3\x85ngstr\xc3\xb6m's Articles" + + def __unicode__(self): + return self.headline + +__test__ = {'API_TESTS': "" }