Skip to content

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

Fix Django 1.7 incapabilities

Michał Ociepka2497aec158ac
diff --git a/saleor/cart/forms.py b/saleor/cart/forms.py
index 8825fd4875..09f9883e55 100644
--- a/saleor/cart/forms.py
+++ b/saleor/cart/forms.py
@@ -1,10 +1,9 @@
from __future__ import unicode_literals
-from decimal import Decimal
from django import forms
from django.core.exceptions import ObjectDoesNotExist, NON_FIELD_ERRORS
from django.forms.formsets import BaseFormSet, DEFAULT_MAX_NUM
-from django.utils.translation import pgettext, ugettext
+from django.utils.translation import pgettext_lazy, ugettext_lazy
from satchless.item import InsufficientStock
@@ -19,15 +18,15 @@ class AddToCartForm(forms.Form):
"""
Class use product and cart instance.
"""
- quantity = QuantityField(label=pgettext('Form field', 'Quantity'))
+ quantity = QuantityField(label=pgettext_lazy('Form field', 'Quantity'))
error_messages = {
- 'empty-stock': ugettext(
+ 'empty-stock': ugettext_lazy(
'Sorry. This product is currently out of stock.'
),
- 'variant-does-not-exists': ugettext(
+ 'variant-does-not-exists': ugettext_lazy(
'Oops. We could not find that product.'
),
- 'insufficient-stock': ugettext(
+ 'insufficient-stock': ugettext_lazy(
'Only %(remaining)d remaining in stock.'
)
}
@@ -121,6 +120,8 @@ class ReplaceCartLineFormSet(BaseFormSet):
form = ReplaceCartLineForm
max_num = DEFAULT_MAX_NUM
validate_max = False
+ min_num = None
+ validate_min = False
def __init__(self, *args, **kwargs):
self.cart = kwargs.pop('cart')
diff --git a/saleor/registration/forms.py b/saleor/registration/forms.py
index e10b943509..ff27bf3ccc 100644
--- a/saleor/registration/forms.py
+++ b/saleor/registration/forms.py
@@ -5,6 +5,8 @@ from django.contrib.auth import authenticate, get_user_model
from django.contrib.auth.forms import AuthenticationForm, SetPasswordForm
from django.utils.translation import pgettext_lazy, ugettext
+from ..userprofile.models import User
+
from .models import (
EmailConfirmationRequest,
EmailChangeRequest,
@@ -12,8 +14,6 @@ from .models import (
from .utils import get_client_class_for_service
from ..communication.mail import send_email
-User = get_user_model()
-
class LoginForm(AuthenticationForm):
@@ -77,7 +77,8 @@ class RequestEmailChangeForm(RequestEmailConfirmationForm):
super(RequestEmailChangeForm, self).__init__(*args, **kwargs)
def clean_email(self):
- if User.objects.filter(email=self.cleaned_data['email']).exists():
+ email = self.cleaned_data['email']
+ if User.objects.filter(email=email).exists():
raise forms.ValidationError(
ugettext('Account with this email already exists'))
return self.cleaned_data['email']
@@ -111,7 +112,8 @@ class OAuth2CallbackForm(forms.Form):
user_info = client.get_user_info()
user = authenticate(service=self.service, username=user_info['id'])
if not user:
- user, _ = User.objects.get_or_create(email=user_info['email'])
+ user, _ = User.objects.get_or_create(
+ email=user_info['email'])
ExternalUserData.objects.create(
service=self.service, username=user_info['id'], user=user)
user = authenticate(user=user)
diff --git a/saleor/registration/models.py b/saleor/registration/models.py
index ffe109d20d..5df6d130de 100644
--- a/saleor/registration/models.py
+++ b/saleor/registration/models.py
@@ -2,13 +2,13 @@ from __future__ import unicode_literals
from datetime import timedelta
from django.db import models
-from django.contrib.auth import authenticate, get_user_model
+from django.contrib.auth import authenticate
from django.conf import settings
from django.core.urlresolvers import reverse
from django.utils import timezone
from django.utils.crypto import get_random_string
-User = get_user_model()
+from ..userprofile.models import User
now = timezone.now
diff --git a/saleor/registration/tests.py b/saleor/registration/tests.py
index 826f3e5f6e..66a69b5ee4 100644
--- a/saleor/registration/tests.py
+++ b/saleor/registration/tests.py
@@ -1,8 +1,8 @@
from unittest import TestCase
-from django.contrib.auth import get_user_model
from django.core.urlresolvers import resolve
from django.conf import settings
+from django.http import HttpRequest
from mock import call, Mock, MagicMock, patch, sentinel
from purl import URL
@@ -17,7 +17,6 @@ from .utils import (
parse_response)
from .views import oauth_callback, change_email
-User = get_user_model()
JSON_MIME_TYPE = 'application/json; charset=UTF-8'
URLENCODED_MIME_TYPE = 'application/x-www-form-urlencoded; charset=UTF-8'
@@ -288,7 +287,8 @@ class EmailChangeTestCase(TestCase):
get.return_value = token_object
# user is logged in
- request = Mock()
+ request = MagicMock(HttpRequest)
+ request._messages = Mock()
request.user = user
# user clicks link in his email
diff --git a/saleor/registration/utils.py b/saleor/registration/utils.py
index ec6e8bfa38..bc734daed2 100644
--- a/saleor/registration/utils.py
+++ b/saleor/registration/utils.py
@@ -7,14 +7,12 @@ except ImportError:
from django.core.urlresolvers import reverse
from django.conf import settings
-from django.contrib.auth import get_user_model
import requests
GOOGLE, FACEBOOK = 'google', 'facebook'
JSON_MIME_TYPE = 'application/json'
logger = logging.getLogger('saleor.registration')
-User = get_user_model()
def get_local_host(request):
diff --git a/saleor/registration/views.py b/saleor/registration/views.py
index a146762814..77f4f83214 100644
--- a/saleor/registration/views.py
+++ b/saleor/registration/views.py
@@ -5,11 +5,10 @@ except ImportError:
from django.conf import settings
from django.contrib import messages
-from django.contrib.auth import (get_user_model, login as auth_login,
- logout as auth_logout)
+from django.contrib.auth import login as auth_login, logout as auth_logout
from django.contrib.auth.decorators import login_required
-from django.contrib.auth.views import (login as django_login_view,
- password_change)
+from django.contrib.auth.views import (
+ login as django_login_view, password_change)
from django.core.urlresolvers import reverse
from django.shortcuts import redirect
from django.template.response import TemplateResponse
@@ -21,7 +20,6 @@ from . import forms
from .models import EmailConfirmationRequest, EmailChangeRequest
from . import utils
-User = get_user_model()
now = timezone.now
diff --git a/saleor/tests.py b/saleor/tests.py
index 77345a11b2..f67b55d5b8 100644
--- a/saleor/tests.py
+++ b/saleor/tests.py
@@ -1,5 +1,11 @@
from unittest import TestSuite, TestLoader
+import django
+
+if hasattr(django, 'setup'):
+ django.setup()
+
+
TEST_MODULES = [
'saleor.cart.tests',
'saleor.checkout.tests',
diff --git a/saleor/userprofile/forms.py b/saleor/userprofile/forms.py
index fdba313d7b..4ee0f5be7d 100644
--- a/saleor/userprofile/forms.py
+++ b/saleor/userprofile/forms.py
@@ -1,4 +1,5 @@
from django import forms
+from django.utils.translation import ugettext as _
from .models import Address, AddressBook
@@ -21,6 +22,6 @@ class AddressBookForm(forms.ModelForm):
user_id=self.instance.user_id, alias=self.cleaned_data.get('alias')
).exclude(address=self.instance.address_id).exists():
self._errors['alias'] = self.error_class(
- ['You are already using such alias for another address'])
+ [_('You are already using such alias for another address')])
return self.cleaned_data
diff --git a/saleor/userprofile/models.py b/saleor/userprofile/models.py
index 4906f326f8..bd93b96d97 100644
--- a/saleor/userprofile/models.py
+++ b/saleor/userprofile/models.py
@@ -40,7 +40,7 @@ class AddressBook(models.Model):
alias = models.CharField(
pgettext_lazy('Address book entry', 'short alias'),
max_length=30,
- default=pgettext_lazy('Address book entry', 'Home'),
+ default='Home',
help_text=pgettext_lazy(
'Address book entry',
'A short, descriptive name for this address'))