Skip to content

Saleor Core: the high performance, composable, headless commerce API.

__unicode__ methods renamed to __str__ - Python 3 compatibility

Artur Smęte5e647653114
diff --git a/saleor/cart/__init__.py b/saleor/cart/__init__.py
index 825e39558e..f31cec863c 100755
--- a/saleor/cart/__init__.py
+++ b/saleor/cart/__init__.py
@@ -1,6 +1,7 @@
from __future__ import unicode_literals
from django.utils.translation import pgettext
+from django.utils.encoding import python_2_unicode_compatible
from satchless import cart
from satchless.item import ItemList, partition
@@ -12,6 +13,7 @@ class DigitalGroup(ItemList):
pass
+@python_2_unicode_compatible
class Cart(cart.Cart):
'''
Contains cart items. Serialized instance of cart is saved into django
@@ -20,7 +22,7 @@ class Cart(cart.Cart):
timestamp = None
billing_address = None
- def __unicode__(self):
+ def __str__(self):
return pgettext(
'Shopping cart',
'Your cart (%(cart_count)s)') % {'cart_count': self.count()}
diff --git a/saleor/delivery/__init__.py b/saleor/delivery/__init__.py
index 0487d79cc1..d592588423 100644
--- a/saleor/delivery/__init__.py
+++ b/saleor/delivery/__init__.py
@@ -1,6 +1,7 @@
from __future__ import unicode_literals
from django.conf import settings
+from django.utils.encoding import python_2_unicode_compatible
from prices import Price
from satchless.item import ItemSet
@@ -22,13 +23,14 @@ class BaseDelivery(ItemSet):
return self.group.get_total() + self.get_delivery_total()
+@python_2_unicode_compatible
class DummyShipping(BaseDelivery):
def __init__(self, delivery_group, address):
self.address = address
super(DummyShipping, self).__init__(delivery_group)
- def __unicode__(self):
+ def __str__(self):
return 'Dummy shipping'
def get_delivery_total(self, **kwargs):
@@ -38,13 +40,14 @@ class DummyShipping(BaseDelivery):
currency=settings.DEFAULT_CURRENCY)
+@python_2_unicode_compatible
class DigitalDelivery(BaseDelivery):
def __init__(self, delivery_group, email):
self.email = email
super(DigitalDelivery, self).__init__(delivery_group)
- def __unicode__(self):
+ def __str__(self):
return 'Digital delivery'
diff --git a/saleor/order/admin.py b/saleor/order/admin.py
index 83ac9ec7d1..ad42cb6676 100644
--- a/saleor/order/admin.py
+++ b/saleor/order/admin.py
@@ -87,7 +87,7 @@ class OrderAdmin(OrderModelAdmin):
inlines = [PaymentInlineAdmin]
exclude = ['token']
readonly_fields = ['customer', 'total']
- list_display = ['__unicode__', 'status', 'created', 'user']
+ list_display = ['__str__', 'status', 'created', 'user']
def customer(self, obj):
return format_address(obj.billing_address)
diff --git a/saleor/order/models.py b/saleor/order/models.py
index 8387a6cce3..53fba635c3 100644
--- a/saleor/order/models.py
+++ b/saleor/order/models.py
@@ -6,6 +6,7 @@ from django.core.urlresolvers import reverse
from django.db import models
from django.utils.encoding import smart_text
from django.utils.timezone import now
+from django.utils.encoding import python_2_unicode_compatible
from django.utils.translation import pgettext_lazy
from django_prices.models import PriceField
from payments import PurchasedItem
@@ -21,6 +22,7 @@ from ..product.models import Product
from ..userprofile.models import Address
+@python_2_unicode_compatible
class Order(models.Model, ItemSet):
STATUS_CHOICES = (
@@ -91,7 +93,7 @@ class Order(models.Model, ItemSet):
def __repr__(self):
return '<Order #%r>' % (self.id,)
- def __unicode__(self):
+ def __str__(self):
return '#%d' % (self.id, )
@property
@@ -148,7 +150,7 @@ class DeliveryGroup(Subtyped, ItemSet):
self.save()
def get_total(self, **kwargs):
- return (super(DeliveryGroup, self).get_total(**kwargs) + self.price)
+ return super(DeliveryGroup, self).get_total(**kwargs) + self.price
def add_items_from_partition(self, partition):
for item_line in partition:
@@ -163,22 +165,25 @@ class DeliveryGroup(Subtyped, ItemSet):
unit_price_gross=price.gross)
+@python_2_unicode_compatible
class ShippedDeliveryGroup(DeliveryGroup):
address = models.ForeignKey(Address, related_name='+')
- def __unicode__(self):
+ def __str__(self):
return 'Shipped delivery'
+@python_2_unicode_compatible
class DigitalDeliveryGroup(DeliveryGroup):
email = models.EmailField()
- def __unicode__(self):
+ def __str__(self):
return 'Digital delivery'
+@python_2_unicode_compatible
class OrderedItem(models.Model, ItemLine):
delivery_group = models.ForeignKey(
@@ -205,7 +210,7 @@ class OrderedItem(models.Model, ItemLine):
return Price(net=self.unit_price_net, gross=self.unit_price_gross,
currency=settings.DEFAULT_CURRENCY)
- def __unicode__(self):
+ def __str__(self):
return self.product_name
def get_quantity(self):
diff --git a/saleor/userprofile/models.py b/saleor/userprofile/models.py
index fda0c3fd0f..760a706803 100644
--- a/saleor/userprofile/models.py
+++ b/saleor/userprofile/models.py
@@ -7,6 +7,7 @@ from django.contrib.auth.models import BaseUserManager
from django.db import models
from django.forms.models import model_to_dict
from django.utils import timezone
+from django.utils.encoding import python_2_unicode_compatible
from django.utils.safestring import mark_safe
from django.utils.translation import pgettext_lazy
from unidecode import unidecode
@@ -31,6 +32,7 @@ class AddressBookManager(models.Manager):
return entry
+@python_2_unicode_compatible
class AddressBook(models.Model):
user = models.ForeignKey('User', related_name='address_book')
@@ -48,7 +50,7 @@ class AddressBook(models.Model):
class Meta:
unique_together = ('user', 'alias')
- def __unicode__(self):
+ def __str__(self):
return self.alias
@models.permalink
@@ -75,6 +77,7 @@ class AddressManager(models.Manager):
return data1 == data2
+@python_2_unicode_compatible
class Address(models.Model):
first_name = models.CharField(
@@ -110,7 +113,7 @@ class Address(models.Model):
objects = AddressManager()
- def __unicode__(self):
+ def __str__(self):
return '%s %s' % (self.first_name, self.last_name)
def __repr__(self):
@@ -162,6 +165,7 @@ class UserManager(BaseUserManager):
user.save()
+@python_2_unicode_compatible
class User(models.Model):
email = models.EmailField(unique=True)
@@ -197,7 +201,7 @@ class User(models.Model):
objects = UserManager()
- def __unicode__(self):
+ def __str__(self):
return self.get_username()
def natural_key(self):