Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
__unicode__ methods renamed to __str__ - Python 3 compatibility
Artur Smęte5e647653114
diff --git a/saleor/cart/__init__.py b/saleor/cart/__init__.pyindex 825e39558e..f31cec863c 100755--- a/saleor/cart/__init__.py+++ b/saleor/cart/__init__.py@@ -1,6 +1,7 @@from __future__ import unicode_literalsfrom django.utils.translation import pgettext+from django.utils.encoding import python_2_unicode_compatiblefrom satchless import cartfrom satchless.item import ItemList, partition@@ -12,6 +13,7 @@ class DigitalGroup(ItemList):pass+@python_2_unicode_compatibleclass Cart(cart.Cart):'''Contains cart items. Serialized instance of cart is saved into django@@ -20,7 +22,7 @@ class Cart(cart.Cart):timestamp = Nonebilling_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__.pyindex 0487d79cc1..d592588423 100644--- a/saleor/delivery/__init__.py+++ b/saleor/delivery/__init__.py@@ -1,6 +1,7 @@from __future__ import unicode_literalsfrom django.conf import settings+from django.utils.encoding import python_2_unicode_compatiblefrom prices import Pricefrom satchless.item import ItemSet@@ -22,13 +23,14 @@ class BaseDelivery(ItemSet):return self.group.get_total() + self.get_delivery_total()+@python_2_unicode_compatibleclass DummyShipping(BaseDelivery):def __init__(self, delivery_group, address):self.address = addresssuper(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_compatibleclass DigitalDelivery(BaseDelivery):def __init__(self, delivery_group, email):self.email = emailsuper(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.pyindex 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.pyindex 8387a6cce3..53fba635c3 100644--- a/saleor/order/models.py+++ b/saleor/order/models.py@@ -6,6 +6,7 @@ from django.core.urlresolvers import reversefrom django.db import modelsfrom django.utils.encoding import smart_textfrom django.utils.timezone import now+from django.utils.encoding import python_2_unicode_compatiblefrom django.utils.translation import pgettext_lazyfrom django_prices.models import PriceFieldfrom payments import PurchasedItem@@ -21,6 +22,7 @@ from ..product.models import Productfrom ..userprofile.models import Address+@python_2_unicode_compatibleclass 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.pricedef 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_compatibleclass ShippedDeliveryGroup(DeliveryGroup):address = models.ForeignKey(Address, related_name='+')- def __unicode__(self):+ def __str__(self):return 'Shipped delivery'+@python_2_unicode_compatibleclass DigitalDeliveryGroup(DeliveryGroup):email = models.EmailField()- def __unicode__(self):+ def __str__(self):return 'Digital delivery'+@python_2_unicode_compatibleclass 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_namedef get_quantity(self):diff --git a/saleor/userprofile/models.py b/saleor/userprofile/models.pyindex fda0c3fd0f..760a706803 100644--- a/saleor/userprofile/models.py+++ b/saleor/userprofile/models.py@@ -7,6 +7,7 @@ from django.contrib.auth.models import BaseUserManagerfrom django.db import modelsfrom django.forms.models import model_to_dictfrom django.utils import timezone+from django.utils.encoding import python_2_unicode_compatiblefrom django.utils.safestring import mark_safefrom django.utils.translation import pgettext_lazyfrom unidecode import unidecode@@ -31,6 +32,7 @@ class AddressBookManager(models.Manager):return entry+@python_2_unicode_compatibleclass 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_compatibleclass 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_compatibleclass 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):