Code

Ticket #16803: 16803.diff

File 16803.diff, 6.1 KB (added by isagalaev, 3 years ago)

Patch

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