Code

Ticket #16803: 16803.2.diff

File 16803.2.diff, 6.6 KB (added by isagalaev, 3 years ago)

Patch fixing unicode breakage

Line 
1=== modified file 'django/contrib/contenttypes/models.py'
2--- django/contrib/contenttypes/models.py       2011-05-22 15:21:03 +0000
3+++ django/contrib/contenttypes/models.py       2011-09-16 05:57:45 +0000
4@@ -1,6 +1,6 @@
5 from django.db import models
6 from django.utils.translation import ugettext_lazy as _
7-from django.utils.encoding import smart_unicode
8+from django.utils.encoding import smart_unicode, force_unicode
9 
10 class ContentTypeManager(models.Manager):
11 
12@@ -85,7 +85,17 @@
13         unique_together = (('app_label', 'model'),)
14 
15     def __unicode__(self):
16-        return self.name
17+        # self.name is deprecated in favor of using model's verbose_name. Formal
18+        # deprecation is delayed until we have DB migration to be able to
19+        # remove the field from the database along with the attribute.
20+        #
21+        # We return self.name only when users have changed its value from the
22+        # initial verbose_name_raw and might rely on it.
23+        meta = self.model_class()._meta
24+        if self.name != meta.verbose_name_raw:
25+            return self.name
26+        else:
27+            return force_unicode(meta.verbose_name)
28 
29     def model_class(self):
30         "Returns the Python model class for this type of content."
31
32=== added directory 'tests/regressiontests/i18n/contenttypes'
33=== added file 'tests/regressiontests/i18n/contenttypes/__init__.py'
34=== added directory 'tests/regressiontests/i18n/contenttypes/locale'
35=== added directory 'tests/regressiontests/i18n/contenttypes/locale/en'
36=== added directory 'tests/regressiontests/i18n/contenttypes/locale/en/LC_MESSAGES'
37=== added file 'tests/regressiontests/i18n/contenttypes/locale/en/LC_MESSAGES/django.mo'
38Binary files tests/regressiontests/i18n/contenttypes/locale/en/LC_MESSAGES/django.mo    1970-01-01 00:00:00 +0000 and tests/regressiontests/i18n/contenttypes/locale/en/LC_MESSAGES/django.mo   2011-09-16 00:09:58 +0000 differ
39=== added file 'tests/regressiontests/i18n/contenttypes/locale/en/LC_MESSAGES/django.po'
40--- tests/regressiontests/i18n/contenttypes/locale/en/LC_MESSAGES/django.po     1970-01-01 00:00:00 +0000
41+++ tests/regressiontests/i18n/contenttypes/locale/en/LC_MESSAGES/django.po     2011-09-16 00:09:53 +0000
42@@ -0,0 +1,26 @@
43+# SOME DESCRIPTIVE TITLE.
44+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
45+# This file is distributed under the same license as the PACKAGE package.
46+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
47+#
48+#, fuzzy
49+msgid ""
50+msgstr ""
51+"Project-Id-Version: PACKAGE VERSION\n"
52+"Report-Msgid-Bugs-To: \n"
53+"POT-Creation-Date: 2011-09-15 15:41-0700\n"
54+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
55+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
56+"Language-Team: LANGUAGE <LL@li.org>\n"
57+"Language: \n"
58+"MIME-Version: 1.0\n"
59+"Content-Type: text/plain; charset=UTF-8\n"
60+"Content-Transfer-Encoding: 8bit\n"
61+
62+#: models.py:6
63+msgid "Anything"
64+msgstr ""
65+
66+#: models.py:15
67+msgid "Company"
68+msgstr "Company"
69\ No newline at end of file
70
71=== added directory 'tests/regressiontests/i18n/contenttypes/locale/fr'
72=== added directory 'tests/regressiontests/i18n/contenttypes/locale/fr/LC_MESSAGES'
73=== added file 'tests/regressiontests/i18n/contenttypes/locale/fr/LC_MESSAGES/django.mo'
74Binary files tests/regressiontests/i18n/contenttypes/locale/fr/LC_MESSAGES/django.mo    1970-01-01 00:00:00 +0000 and tests/regressiontests/i18n/contenttypes/locale/fr/LC_MESSAGES/django.mo   2011-09-16 00:09:58 +0000 differ
75=== added file 'tests/regressiontests/i18n/contenttypes/locale/fr/LC_MESSAGES/django.po'
76--- tests/regressiontests/i18n/contenttypes/locale/fr/LC_MESSAGES/django.po     1970-01-01 00:00:00 +0000
77+++ tests/regressiontests/i18n/contenttypes/locale/fr/LC_MESSAGES/django.po     2011-09-16 00:09:45 +0000
78@@ -0,0 +1,27 @@
79+# SOME DESCRIPTIVE TITLE.
80+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
81+# This file is distributed under the same license as the PACKAGE package.
82+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
83+#
84+#, fuzzy
85+msgid ""
86+msgstr ""
87+"Project-Id-Version: PACKAGE VERSION\n"
88+"Report-Msgid-Bugs-To: \n"
89+"POT-Creation-Date: 2011-09-15 15:41-0700\n"
90+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
91+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
92+"Language-Team: LANGUAGE <LL@li.org>\n"
93+"Language: \n"
94+"MIME-Version: 1.0\n"
95+"Content-Type: text/plain; charset=UTF-8\n"
96+"Content-Transfer-Encoding: 8bit\n"
97+"Plural-Forms: nplurals=2; plural=(n > 1)\n"
98+
99+#: models.py:6
100+msgid "Anything"
101+msgstr ""
102+
103+#: models.py:15
104+msgid "Company"
105+msgstr "Société"
106\ No newline at end of file
107
108=== added file 'tests/regressiontests/i18n/contenttypes/tests.py'
109--- tests/regressiontests/i18n/contenttypes/tests.py    1970-01-01 00:00:00 +0000
110+++ tests/regressiontests/i18n/contenttypes/tests.py    2011-09-16 06:00:28 +0000
111@@ -0,0 +1,33 @@
112+# coding: utf-8
113+import os
114+
115+from django.test import TestCase
116+from django.test.utils import override_settings
117+from django.utils import translation
118+from django.contrib.contenttypes.models import ContentType
119+
120+
121+class ContentTypeTests(TestCase):
122+    def test_verbose_name(self):
123+        company_type = ContentType.objects.get(app_label='i18n', model='company')
124+        with translation.override('en'):
125+            self.assertEqual(unicode(company_type), u'Company')
126+        with translation.override('fr'):
127+            self.assertEqual(unicode(company_type), u'Société')
128+   
129+    def test_field_override(self):
130+        company_type = ContentType.objects.get(app_label='i18n', model='company')
131+        company_type.name = 'Other'
132+        self.assertEqual(unicode(company_type), 'Other')
133+
134+ContentTypeTests = override_settings(
135+    USE_I18N=True,
136+    LOCALE_PATHS=(
137+        os.path.join(os.path.dirname(__file__), 'locale'),
138+    ),
139+    LANGUAGE_CODE='en',
140+    LANGUAGES=(
141+        ('en', 'English'),
142+        ('fr', 'French'),
143+    ),
144+)(ContentTypeTests)
145\ No newline at end of file
146
147=== modified file 'tests/regressiontests/i18n/models.py'
148--- tests/regressiontests/i18n/models.py        2010-09-12 19:03:39 +0000
149+++ tests/regressiontests/i18n/models.py        2011-09-16 06:00:49 +0000
150@@ -10,3 +10,6 @@
151     date_added = models.DateTimeField(default=datetime(1799,1,31,23,59,59,0))
152     cents_payed = models.DecimalField(max_digits=4, decimal_places=2)
153     products_delivered = models.IntegerField()
154+
155+    class Meta:
156+        verbose_name = _('Company')
157\ No newline at end of file
158
159=== modified file 'tests/regressiontests/i18n/tests.py'
160--- tests/regressiontests/i18n/tests.py 2011-09-08 13:25:41 +0000
161+++ tests/regressiontests/i18n/tests.py 2011-09-15 22:33:45 +0000
162@@ -26,6 +26,7 @@
163 
164 from commands.tests import *
165 from patterns.tests import *
166+from contenttypes.tests import *
167 from test_warnings import DeprecationWarningTests
168 
169 here = os.path.dirname(os.path.abspath(__file__))
170