Fixed #18269 -- Applied unicode_literals for Python 3 compatibility.

Thanks Vinay Sajip for the support of his django3 branch and
Jannis Leidel for the review.
This commit is contained in:
Claude Paroz 2012-06-07 18:08:47 +02:00
parent 706fd9adc0
commit 4a103086d5
401 changed files with 6647 additions and 6157 deletions

View file

@ -1,3 +1,5 @@
from __future__ import unicode_literals
import datetime
from django.db import models
@ -10,20 +12,20 @@ class Place(models.Model):
ordering = ('name',)
def __unicode__(self):
return u"%s the place" % self.name
return "%s the place" % self.name
class Restaurant(Place):
serves_hot_dogs = models.BooleanField()
serves_pizza = models.BooleanField()
def __unicode__(self):
return u"%s the restaurant" % self.name
return "%s the restaurant" % self.name
class ItalianRestaurant(Restaurant):
serves_gnocchi = models.BooleanField()
def __unicode__(self):
return u"%s the italian restaurant" % self.name
return "%s the italian restaurant" % self.name
class ParkingLot(Place):
# An explicit link to the parent (we can control the attribute name).
@ -31,7 +33,7 @@ class ParkingLot(Place):
capacity = models.IntegerField()
def __unicode__(self):
return u"%s the parking lot" % self.name
return "%s the parking lot" % self.name
class ParkingLot2(Place):
# In lieu of any other connector, an existing OneToOneField will be
@ -108,7 +110,7 @@ class AuditBase(models.Model):
class Meta:
abstract = True
verbose_name_plural = u'Audits'
verbose_name_plural = 'Audits'
class CertificationAudit(AuditBase):
class Meta(AuditBase.Meta):

View file

@ -1,8 +1,7 @@
"""
Regression tests for Model inheritance behavior.
"""
from __future__ import absolute_import
from __future__ import absolute_import, unicode_literals
import datetime
from operator import attrgetter
@ -53,14 +52,14 @@ class ModelInheritanceTest(TestCase):
dicts = list(Restaurant.objects.values('name','serves_hot_dogs'))
self.assertEqual(dicts, [{
'name': u"Guido's House of Pasta",
'name': "Guido's House of Pasta",
'serves_hot_dogs': True
}])
dicts = list(ItalianRestaurant.objects.values(
'name','serves_hot_dogs','serves_gnocchi'))
self.assertEqual(dicts, [{
'name': u"Guido's House of Pasta",
'name': "Guido's House of Pasta",
'serves_gnocchi': True,
'serves_hot_dogs': True,
}])
@ -68,7 +67,7 @@ class ModelInheritanceTest(TestCase):
dicts = list(ParkingLot.objects.values('name','capacity'))
self.assertEqual(dicts, [{
'capacity': 100,
'name': u'Main St',
'name': 'Main St',
}])
# You can also update objects when using a raw save.
@ -95,14 +94,14 @@ class ModelInheritanceTest(TestCase):
dicts = list(Restaurant.objects.values('name','serves_hot_dogs'))
self.assertEqual(dicts, [{
'name': u"Guido's All New House of Pasta",
'name': "Guido's All New House of Pasta",
'serves_hot_dogs': False,
}])
dicts = list(ItalianRestaurant.objects.values(
'name', 'serves_hot_dogs', 'serves_gnocchi'))
self.assertEqual(dicts, [{
'name': u"Guido's All New House of Pasta",
'name': "Guido's All New House of Pasta",
'serves_gnocchi': False,
'serves_hot_dogs': False,
}])
@ -110,7 +109,7 @@ class ModelInheritanceTest(TestCase):
dicts = list(ParkingLot.objects.values('name','capacity'))
self.assertEqual(dicts, [{
'capacity': 50,
'name': u'Derelict lot',
'name': 'Derelict lot',
}])
# If you try to raw_save a parent attribute onto a child object,
@ -124,7 +123,7 @@ class ModelInheritanceTest(TestCase):
dicts = list(ItalianRestaurant.objects.values(
'name','serves_hot_dogs','serves_gnocchi'))
self.assertEqual(dicts, [{
'name': u"Guido's All New House of Pasta",
'name': "Guido's All New House of Pasta",
'serves_gnocchi': False,
'serves_hot_dogs': False,
}])
@ -372,7 +371,7 @@ class ModelInheritanceTest(TestCase):
# verbose_name.
self.assertEqual(
InternalCertificationAudit._meta.verbose_name_plural,
u'Audits'
'Audits'
)
def test_inherited_nullable_exclude(self):