Ticket #16803: 16803.2.diff

File 16803.2.diff, 6.6 KB (added by Ivan Sagalaev, 13 years ago)

Patch fixing unicode breakage

  • django/contrib/contenttypes/models.py

    === modified file 'django/contrib/contenttypes/models.py'
     
    11from django.db import models
    22from django.utils.translation import ugettext_lazy as _
    3 from django.utils.encoding import smart_unicode
     3from django.utils.encoding import smart_unicode, force_unicode
    44
    55class ContentTypeManager(models.Manager):
    66
     
    8585        unique_together = (('app_label', 'model'),)
    8686
    8787    def __unicode__(self):
    88         return self.name
     88        # self.name is deprecated in favor of using model's verbose_name. Formal
     89        # deprecation is delayed until we have DB migration to be able to
     90        # remove the field from the database along with the attribute.
     91        #
     92        # We return self.name only when users have changed its value from the
     93        # initial verbose_name_raw and might rely on it.
     94        meta = self.model_class()._meta
     95        if self.name != meta.verbose_name_raw:
     96            return self.name
     97        else:
     98            return force_unicode(meta.verbose_name)
    8999
    90100    def model_class(self):
    91101        "Returns the Python model class for this type of content."
  • tests/regressiontests/i18n/contenttypes/locale/en/LC_MESSAGES/django.po

    === added directory 'tests/regressiontests/i18n/contenttypes'
    === added file 'tests/regressiontests/i18n/contenttypes/__init__.py'
    === added directory 'tests/regressiontests/i18n/contenttypes/locale'
    === added directory 'tests/regressiontests/i18n/contenttypes/locale/en'
    === added directory 'tests/regressiontests/i18n/contenttypes/locale/en/LC_MESSAGES'
    === added file 'tests/regressiontests/i18n/contenttypes/locale/en/LC_MESSAGES/django.mo'
    Binary 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
    === added file 'tests/regressiontests/i18n/contenttypes/locale/en/LC_MESSAGES/django.po'
     
     1# SOME DESCRIPTIVE TITLE.
     2# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
     3# This file is distributed under the same license as the PACKAGE package.
     4# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
     5#
     6#, fuzzy
     7msgid ""
     8msgstr ""
     9"Project-Id-Version: PACKAGE VERSION\n"
     10"Report-Msgid-Bugs-To: \n"
     11"POT-Creation-Date: 2011-09-15 15:41-0700\n"
     12"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
     13"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
     14"Language-Team: LANGUAGE <LL@li.org>\n"
     15"Language: \n"
     16"MIME-Version: 1.0\n"
     17"Content-Type: text/plain; charset=UTF-8\n"
     18"Content-Transfer-Encoding: 8bit\n"
     19
     20#: models.py:6
     21msgid "Anything"
     22msgstr ""
     23
     24#: models.py:15
     25msgid "Company"
     26msgstr "Company"
     27 No newline at end of file
  • tests/regressiontests/i18n/contenttypes/locale/fr/LC_MESSAGES/django.po

    === added directory 'tests/regressiontests/i18n/contenttypes/locale/fr'
    === added directory 'tests/regressiontests/i18n/contenttypes/locale/fr/LC_MESSAGES'
    === added file 'tests/regressiontests/i18n/contenttypes/locale/fr/LC_MESSAGES/django.mo'
    Binary 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
    === added file 'tests/regressiontests/i18n/contenttypes/locale/fr/LC_MESSAGES/django.po'
     
     1# SOME DESCRIPTIVE TITLE.
     2# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
     3# This file is distributed under the same license as the PACKAGE package.
     4# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
     5#
     6#, fuzzy
     7msgid ""
     8msgstr ""
     9"Project-Id-Version: PACKAGE VERSION\n"
     10"Report-Msgid-Bugs-To: \n"
     11"POT-Creation-Date: 2011-09-15 15:41-0700\n"
     12"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
     13"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
     14"Language-Team: LANGUAGE <LL@li.org>\n"
     15"Language: \n"
     16"MIME-Version: 1.0\n"
     17"Content-Type: text/plain; charset=UTF-8\n"
     18"Content-Transfer-Encoding: 8bit\n"
     19"Plural-Forms: nplurals=2; plural=(n > 1)\n"
     20
     21#: models.py:6
     22msgid "Anything"
     23msgstr ""
     24
     25#: models.py:15
     26msgid "Company"
     27msgstr "Société"
     28 No newline at end of file
  • tests/regressiontests/i18n/contenttypes/tests.py

    === added file 'tests/regressiontests/i18n/contenttypes/tests.py'
     
     1# coding: utf-8
     2import os
     3
     4from django.test import TestCase
     5from django.test.utils import override_settings
     6from django.utils import translation
     7from django.contrib.contenttypes.models import ContentType
     8
     9
     10class ContentTypeTests(TestCase):
     11    def test_verbose_name(self):
     12        company_type = ContentType.objects.get(app_label='i18n', model='company')
     13        with translation.override('en'):
     14            self.assertEqual(unicode(company_type), u'Company')
     15        with translation.override('fr'):
     16            self.assertEqual(unicode(company_type), u'Société')
     17   
     18    def test_field_override(self):
     19        company_type = ContentType.objects.get(app_label='i18n', model='company')
     20        company_type.name = 'Other'
     21        self.assertEqual(unicode(company_type), 'Other')
     22
     23ContentTypeTests = override_settings(
     24    USE_I18N=True,
     25    LOCALE_PATHS=(
     26        os.path.join(os.path.dirname(__file__), 'locale'),
     27    ),
     28    LANGUAGE_CODE='en',
     29    LANGUAGES=(
     30        ('en', 'English'),
     31        ('fr', 'French'),
     32    ),
     33)(ContentTypeTests)
     34 No newline at end of file
  • tests/regressiontests/i18n/models.py

    === modified file 'tests/regressiontests/i18n/models.py'
     
    1010    date_added = models.DateTimeField(default=datetime(1799,1,31,23,59,59,0))
    1111    cents_payed = models.DecimalField(max_digits=4, decimal_places=2)
    1212    products_delivered = models.IntegerField()
     13
     14    class Meta:
     15        verbose_name = _('Company')
     16 No newline at end of file
  • tests/regressiontests/i18n/tests.py

    === modified file 'tests/regressiontests/i18n/tests.py'
     
    2626
    2727from commands.tests import *
    2828from patterns.tests import *
     29from contenttypes.tests import *
    2930from test_warnings import DeprecationWarningTests
    3031
    3132here = os.path.dirname(os.path.abspath(__file__))
Back to Top