Commit 4388c2d4 authored by Kaarle Ritvanen's avatar Kaarle Ritvanen
Browse files

main/py-django-oscar: backport support for Django 1.11

parent 3657983b
From 82c92e467540a5d2e77690d43ca871bc92f05b27 Mon Sep 17 00:00:00 2001
From: Michael van Tellingen <michael@mvantellingen.nl>
Date: Tue, 4 Apr 2017 23:26:22 +0200
Subject: [PATCH 1/8] Use Django 1.11 compatible django-webtest version
---
setup.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/setup.py b/setup.py
index f2ec130..587f10e 100755
--- a/setup.py
+++ b/setup.py
@@ -60,7 +60,7 @@ docs_requires = [
test_requires = [
'WebTest==2.0.24',
'coverage==4.3.4',
- 'django-webtest==1.8.0',
+ 'django-webtest==1.9.1',
'py>=1.4.31',
'pytest==3.0.6',
'pytest-cov==2.4.0',
--
2.9.4
From d2d5b17dcac857503b3040dabc7c93d567c68054 Mon Sep 17 00:00:00 2001
From: Michael van Tellingen <michael@mvantellingen.nl>
Date: Tue, 4 Apr 2017 23:27:38 +0200
Subject: [PATCH 2/8] Don't use django.template.Context for template rendering
Since Django 1.11 dicts should be passed to template rendering functions
---
src/oscar/apps/customer/abstract_models.py | 5 +++--
src/oscar/apps/customer/alerts/utils.py | 10 +++++-----
src/oscar/forms/widgets.py | 5 ++---
src/oscar/templatetags/product_tags.py | 2 ++
4 files changed, 12 insertions(+), 10 deletions(-)
diff --git a/src/oscar/apps/customer/abstract_models.py b/src/oscar/apps/customer/abstract_models.py
index fbebf60..9a6c5ee 100644
--- a/src/oscar/apps/customer/abstract_models.py
+++ b/src/oscar/apps/customer/abstract_models.py
@@ -6,7 +6,7 @@ from django.contrib.auth import models as auth_models
from django.core.urlresolvers import reverse
from django.core.validators import RegexValidator
from django.db import models
-from django.template import Context, Template, TemplateDoesNotExist
+from django.template import Template, TemplateDoesNotExist
from django.template.loader import get_template
from django.utils import six, timezone
from django.utils.encoding import python_2_unicode_compatible
@@ -238,8 +238,9 @@ class AbstractCommunicationEventType(models.Model):
settings, 'OSCAR_STATIC_BASE_URL', None)
messages = {}
+ ctx = {}
for name, template in templates.items():
- messages[name] = template.render(Context(ctx)) if template else ''
+ messages[name] = template.render(ctx) if template else ''
# Ensure the email subject doesn't contain any newlines
messages['subject'] = messages['subject'].replace("\n", "")
diff --git a/src/oscar/apps/customer/alerts/utils.py b/src/oscar/apps/customer/alerts/utils.py
index fc3d8bf..776d811 100644
--- a/src/oscar/apps/customer/alerts/utils.py
+++ b/src/oscar/apps/customer/alerts/utils.py
@@ -4,7 +4,7 @@ from django.conf import settings
from django.contrib.sites.models import Site
from django.core import mail
from django.db.models import Max
-from django.template import Context, loader
+from django.template import loader
from oscar.apps.customer.notifications import services
from oscar.core.loading import get_class, get_model
@@ -32,10 +32,10 @@ def send_alert_confirmation(alert):
"""
Send an alert confirmation email.
"""
- ctx = Context({
+ ctx = {
'alert': alert,
'site': Site.objects.get_current(),
- })
+ }
subject_tpl = loader.get_template('customer/alerts/emails/'
'confirmation_subject.txt')
body_tpl = loader.get_template('customer/alerts/emails/'
@@ -93,11 +93,11 @@ def send_product_alerts(product):
if not data.availability.is_available_to_buy:
continue
- ctx = Context({
+ ctx = {
'alert': alert,
'site': Site.objects.get_current(),
'hurry': hurry_mode,
- })
+ }
if alert.user:
# Send a site notification
num_notifications += 1
diff --git a/src/oscar/forms/widgets.py b/src/oscar/forms/widgets.py
index 85ba1b0..5b374cf 100644
--- a/src/oscar/forms/widgets.py
+++ b/src/oscar/forms/widgets.py
@@ -4,7 +4,6 @@ from django import forms
from django.core.files.uploadedfile import InMemoryUploadedFile
from django.forms.utils import flatatt
from django.forms.widgets import FileInput
-from django.template import Context
from django.template.loader import render_to_string
from django.utils import formats, six
from django.utils.encoding import force_text
@@ -42,11 +41,11 @@ class ImageInput(FileInput):
image_url = final_attrs['value'] = force_text(
self._format_value(value))
- return render_to_string(self.template_name, Context({
+ return render_to_string(self.template_name, {
'input_attrs': flatatt(final_attrs),
'image_url': image_url,
'image_id': "%s-image" % final_attrs['id'],
- }))
+ })
class WYSIWYGTextArea(forms.Textarea):
diff --git a/src/oscar/templatetags/product_tags.py b/src/oscar/templatetags/product_tags.py
index ea5c3f2..8fa6f66 100644
--- a/src/oscar/templatetags/product_tags.py
+++ b/src/oscar/templatetags/product_tags.py
@@ -23,6 +23,8 @@ def render_product(context, product):
% product.get_product_class().slug,
'catalogue/partials/product.html']
template_ = select_template(names)
+ context = context.flatten()
+
# Ensure the passed product is in the context as 'product'
context['product'] = product
return template_.render(context)
--
2.9.4
From bf41f12337554af742148e1d04427974c3ed33fc Mon Sep 17 00:00:00 2001
From: Michael van Tellingen <michael@mvantellingen.nl>
Date: Thu, 6 Apr 2017 17:04:19 +0200
Subject: [PATCH 3/8] Update the custom form widgets for Django 1.11
In Django 1.11 the widgets are rendered with templates instead of
python code. Update the code for this change
---
src/oscar/apps/customer/abstract_models.py | 5 ++---
src/oscar/forms/widgets.py | 28 ++++++++++++++++++++--------
2 files changed, 22 insertions(+), 11 deletions(-)
diff --git a/src/oscar/apps/customer/abstract_models.py b/src/oscar/apps/customer/abstract_models.py
index 9a6c5ee..055fda3 100644
--- a/src/oscar/apps/customer/abstract_models.py
+++ b/src/oscar/apps/customer/abstract_models.py
@@ -6,7 +6,7 @@ from django.contrib.auth import models as auth_models
from django.core.urlresolvers import reverse
from django.core.validators import RegexValidator
from django.db import models
-from django.template import Template, TemplateDoesNotExist
+from django.template import Context, TemplateDoesNotExist, engines
from django.template.loader import get_template
from django.utils import six, timezone
from django.utils.encoding import python_2_unicode_compatible
@@ -222,7 +222,7 @@ class AbstractCommunicationEventType(models.Model):
field = getattr(self, attr_name, None)
if field is not None:
# Template content is in a model field
- templates[name] = Template(field)
+ templates[name] = engines['django'].from_string(field)
else:
# Model field is empty - look for a file template
template_name = getattr(self, "%s_file" % attr_name) % code
@@ -238,7 +238,6 @@ class AbstractCommunicationEventType(models.Model):
settings, 'OSCAR_STATIC_BASE_URL', None)
messages = {}
- ctx = {}
for name, template in templates.items():
messages[name] = template.render(ctx) if template else ''
diff --git a/src/oscar/forms/widgets.py b/src/oscar/forms/widgets.py
index 5b374cf..cdeb6b9 100644
--- a/src/oscar/forms/widgets.py
+++ b/src/oscar/forms/widgets.py
@@ -1,5 +1,6 @@
import re
+import django
from django import forms
from django.core.files.uploadedfile import InMemoryUploadedFile
from django.forms.utils import flatatt
@@ -23,7 +24,7 @@ class ImageInput(FileInput):
template_name = 'partials/image_input_widget.html'
attrs = {'accept': 'image/*'}
- def render(self, name, value, attrs=None):
+ def render(self, name, value, attrs=None, renderer=None):
"""
Render the ``input`` field based on the defined ``template_name``. The
image URL is take from *value* and is provided to the template as
@@ -33,7 +34,15 @@ class ImageInput(FileInput):
If *value* contains no valid image URL an empty string will be provided
in the context.
"""
- final_attrs = self.build_attrs(attrs, type=self.input_type, name=name)
+ extra_attrs = {
+ 'type': self.input_type,
+ 'name': name,
+ }
+ if django.VERSION < (1, 11):
+ final_attrs = self.build_attrs(attrs, **extra_attrs)
+ else:
+ final_attrs = self.build_attrs(attrs, extra_attrs=extra_attrs)
+
if not value or isinstance(value, InMemoryUploadedFile):
# can't display images that aren't stored
image_url = ''
@@ -163,7 +172,7 @@ class TimePickerInput(DateTimeWidgetMixin, forms.TimeInput):
"""
format_key = 'TIME_INPUT_FORMATS'
- def render(self, name, value, attrs=None):
+ def render(self, name, value, attrs=None, renderer=None):
format = self.get_format()
input = super(TimePickerInput, self).render(
name, value, self.gett_attrs(attrs, format))
@@ -192,7 +201,7 @@ class DatePickerInput(DateTimeWidgetMixin, forms.DateInput):
"""
format_key = 'DATE_INPUT_FORMATS'
- def render(self, name, value, attrs=None):
+ def render(self, name, value, attrs=None, renderer=None):
format = self.get_format()
input = super(DatePickerInput, self).render(
name, value, self.gett_attrs(attrs, format))
@@ -235,7 +244,7 @@ class DateTimePickerInput(DateTimeWidgetMixin, forms.DateTimeInput):
if not include_seconds and self.format:
self.format = re.sub(':?%S', '', self.format)
- def render(self, name, value, attrs=None):
+ def render(self, name, value, attrs=None, renderer=None):
format = self.get_format()
input = super(DateTimePickerInput, self).render(
name, value, self.gett_attrs(attrs, format))
@@ -314,15 +323,18 @@ class RemoteSelect(forms.Widget):
else:
return six.text_type(value)
- def render(self, name, value, attrs=None, choices=()):
- attrs = self.build_attrs(attrs, **{
+ def render(self, name, value, attrs=None, renderer=None):
+ attrs = {} if attrs is None else attrs
+
+ extra_attrs = {
'type': 'hidden',
'name': name,
'data-ajax-url': self.lookup_url,
'data-multiple': 'multiple' if self.is_multiple else '',
'value': self.format_value(value),
'data-required': 'required' if self.is_required else '',
- })
+ }
+ attrs = self.build_attrs(attrs, extra_attrs=extra_attrs)
return mark_safe(u'<input %s>' % flatatt(attrs))
--
2.9.4
From 9e7b200b06b07da8c0383d3d506097e5777f6682 Mon Sep 17 00:00:00 2001
From: Michael van Tellingen <michael@mvantellingen.nl>
Date: Sat, 15 Apr 2017 08:42:47 +0200
Subject: [PATCH 4/8] Add template_name attribute to RemoteSelect widget
This fixes an exception in Django 1.11 (template based widgets)
---
src/oscar/forms/widgets.py | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/oscar/forms/widgets.py b/src/oscar/forms/widgets.py
index cdeb6b9..c2a5ce7 100644
--- a/src/oscar/forms/widgets.py
+++ b/src/oscar/forms/widgets.py
@@ -304,6 +304,7 @@ class RemoteSelect(forms.Widget):
"""
is_multiple = False
lookup_url = None
+ template_name = None
def __init__(self, *args, **kwargs):
if 'lookup_url' in kwargs:
--
2.9.4
From 9732e0310b753cec3b8eb0f533c2d9dc9882de6c Mon Sep 17 00:00:00 2001
From: Michael van Tellingen <michael@mvantellingen.nl>
Date: Sat, 15 Apr 2017 10:15:52 +0200
Subject: [PATCH 5/8] Fix RemoteSelect widget for Django 1.10/1.11
We should probably just move to django-select2 in the future
---
src/oscar/forms/widgets.py | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/src/oscar/forms/widgets.py b/src/oscar/forms/widgets.py
index c2a5ce7..6f0f5e7 100644
--- a/src/oscar/forms/widgets.py
+++ b/src/oscar/forms/widgets.py
@@ -1,3 +1,4 @@
+import copy
import re
import django
@@ -325,17 +326,15 @@ class RemoteSelect(forms.Widget):
return six.text_type(value)
def render(self, name, value, attrs=None, renderer=None):
- attrs = {} if attrs is None else attrs
-
- extra_attrs = {
+ attrs = {} if attrs is None else copy.copy(attrs)
+ attrs.update({
'type': 'hidden',
'name': name,
'data-ajax-url': self.lookup_url,
'data-multiple': 'multiple' if self.is_multiple else '',
'value': self.format_value(value),
'data-required': 'required' if self.is_required else '',
- }
- attrs = self.build_attrs(attrs, extra_attrs=extra_attrs)
+ })
return mark_safe(u'<input %s>' % flatatt(attrs))
--
2.9.4
From 5bd3e277df3fe925255302e4aa50a17118ea61b0 Mon Sep 17 00:00:00 2001
From: Samir Shah <samir@regulusweb.com>
Date: Tue, 25 Apr 2017 08:30:17 +0300
Subject: [PATCH 6/8] Fix EmailBackend.authenticate() signature for Django
1.11.
---
src/oscar/apps/customer/auth_backends.py | 22 ++++++++++------------
1 file changed, 10 insertions(+), 12 deletions(-)
diff --git a/src/oscar/apps/customer/auth_backends.py b/src/oscar/apps/customer/auth_backends.py
index 65b8778..6558454 100644
--- a/src/oscar/apps/customer/auth_backends.py
+++ b/src/oscar/apps/customer/auth_backends.py
@@ -1,5 +1,6 @@
import warnings
+import django
from django.contrib.auth.backends import ModelBackend
from django.core.exceptions import ImproperlyConfigured
@@ -22,7 +23,7 @@ class EmailBackend(ModelBackend):
For this to work, the User model must have an 'email' field
"""
- def authenticate(self, email=None, password=None, *args, **kwargs):
+ def _authenticate(self, request, email=None, password=None, *args, **kwargs):
if email is None:
if 'username' not in kwargs or kwargs['username'] is None:
return None
@@ -55,14 +56,11 @@ class EmailBackend(ModelBackend):
"password")
return None
-
-# Deprecated since Oscar 1.0 because of the spelling.
-class Emailbackend(EmailBackend):
-
- def __init__(self):
- warnings.warn(
- "Oscar's auth backend EmailBackend has been renamed in Oscar 1.0 "
- " and you're using the old name of Emailbackend. Please rename "
- " all references; most likely in the AUTH_BACKENDS setting.",
- DeprecationWarning)
- super(Emailbackend, self).__init__()
+ # The signature of the authenticate method changed in Django 1.11 to include
+ # a mandatory `request` argument.
+ if django.VERSION < (1, 11):
+ def authenticate(self, email=None, password=None, *args, **kwargs):
+ return self._authenticate(None, email, password, *args, **kwargs)
+ else:
+ def authenticate(self, *args, **kwargs):
+ return self._authenticate(*args, **kwargs)
--
2.9.4
From b7a50dce837006f8643e59a40a164a75010138e8 Mon Sep 17 00:00:00 2001
From: Michael van Tellingen <michael@mvantellingen.nl>
Date: Sun, 30 Apr 2017 10:15:08 +0200
Subject: [PATCH 7/8] Fix widgets.ImageInput for Django 1.11
The FileInput.format_value returns None instead of the passed value
in Django 1.11. Remove the usage of format_value since it was a noop
before Django 1.11 anyway
Fixes #2334
---
src/oscar/forms/widgets.py | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/src/oscar/forms/widgets.py b/src/oscar/forms/widgets.py
index 6f0f5e7..2a03919 100644
--- a/src/oscar/forms/widgets.py
+++ b/src/oscar/forms/widgets.py
@@ -48,8 +48,7 @@ class ImageInput(FileInput):
# can't display images that aren't stored
image_url = ''
else:
- image_url = final_attrs['value'] = force_text(
- self._format_value(value))
+ image_url = final_attrs['value'] = value
return render_to_string(self.template_name, {
'input_attrs': flatatt(final_attrs),
--
2.9.4
From cdc4476e00d0b9924d0b535c222addb565a1aa8f Mon Sep 17 00:00:00 2001
From: Michael van Tellingen <michael@mvantellingen.nl>
Date: Mon, 26 Jun 2017 10:03:05 +0200
Subject: [PATCH 8/8] Allow latest django-haystack release (for Django 1.11)
---
setup.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/setup.py b/setup.py
index 587f10e..41e106b 100755
--- a/setup.py
+++ b/setup.py
@@ -26,7 +26,7 @@ install_requires = [
# https://github.com/AndrewIngram/django-extra-views/issues/114
'django-extra-views>=0.2,<0.6.5',
# Search support
- 'django-haystack>=2.5.0,<2.6.0',
+ 'django-haystack>=2.5.0,<2.7.0',
# Treebeard is used for categories
'django-treebeard>=4.1.0',
# Sorl is used as the default thumbnailer
--
2.9.4
......@@ -2,7 +2,7 @@
# Maintainer: Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>
pkgname=py-django-oscar
pkgver=1.4
pkgrel=0
pkgrel=1
pkgdesc="Domain-driven e-commerce for Django"
url=http://oscarcommerce.com/
arch=noarch
......@@ -12,7 +12,16 @@ depends="py-babel py-django py-django-extra-views py-django-haystack
py-django-widget-tweaks py-factory-boy py-mock py-phonenumbers
py-pillow py-purl py-unidecode"
makedepends=py-setuptools
source="https://files.pythonhosted.org/packages/source/d/django-oscar/django-oscar-$pkgver.tar.gz"
source="https://files.pythonhosted.org/packages/source/d/django-oscar/django-oscar-$pkgver.tar.gz
0001-Use-Django-1.11-compatible-django-webtest-version.patch
0002-Don-t-use-django.template.Context-for-template-rende.patch
0003-Update-the-custom-form-widgets-for-Django-1.11.patch
0004-Add-template_name-attribute-to-RemoteSelect-widget.patch
0005-Fix-RemoteSelect-widget-for-Django-1.10-1.11.patch
0006-Fix-EmailBackend.authenticate-signature-for-Django-1.patch
0007-Fix-widgets.ImageInput-for-Django-1.11.patch
0008-Allow-latest-django-haystack-release-for-Django-1.11.patch
"
_builddir=$srcdir/django-oscar-$pkgver
prepare() {
......@@ -35,4 +44,12 @@ package() {
./setup.py install --root "$pkgdir"
}
sha512sums="80b86002f515529fbd73aa64a56381daa86d06195cd4cf8dbfaf8f5b4183d3bee1a4cccc970b7093b92b68b15c941a4bedda6bac2238ffd5b7377af3f5b98a4e django-oscar-1.4.tar.gz"
sha512sums="80b86002f515529fbd73aa64a56381daa86d06195cd4cf8dbfaf8f5b4183d3bee1a4cccc970b7093b92b68b15c941a4bedda6bac2238ffd5b7377af3f5b98a4e django-oscar-1.4.tar.gz
e704f9df7522b0e980ca20c3af8808dbc36c9d828de157834b5532525efd0b0ca25f92495f0201dfcbe65b074d99fce5edd41a8660433ff9d3744b1fe08b2b86 0001-Use-Django-1.11-compatible-django-webtest-version.patch
0a442561a76c2073bf63f58dd6b8eb64bff51ae38525e0460aa7d7d12de8a015334727ed066e4e6192f485a95e4cb8ca9eeef31303dc2addfc337309bc908336 0002-Don-t-use-django.template.Context-for-template-rende.patch
482610db4fd415aa5d4aabc07a8e6ffb598563f751fa09a3b2f6d3889cbe858b1e975e2abe725426f53bc945cfa9042495bf9f3da9de094e5868b3849ed5420a 0003-Update-the-custom-form-widgets-for-Django-1.11.patch
bf8a5c004eff8a9494e693a3c7861d8ea68e887c4a3c03bd4083c28b8173cd8013d10cb8d09ffe24dce2023bb267ded6137cf980da2ae5f9796389b0ea0f0b04 0004-Add-template_name-attribute-to-RemoteSelect-widget.patch
92f32a9762faa49c4b3f474cc43ee72cc663c4324b1bd6798707f710ec184374a7a64da4aab9307da49b766386d7dcb641bb26a283323b102392a61da424c655 0005-Fix-RemoteSelect-widget-for-Django-1.10-1.11.patch
95773dda83edfe64b5da0c39935ea7c97483ba0b7088135f6e47c942d3bf3cab8bf1325ad26ea1a85f5c7b539115e6d13b668459ae55a8d5c376f0167cdee128 0006-Fix-EmailBackend.authenticate-signature-for-Django-1.patch
098defd75a2e6175ae6b0fe5ec0a5c6478581bc424a0cd7772f1f1afb80424cb0ec248d75d0ba3e401df5db1465dd6f9e6608f92f54f7b8631219165f04db133 0007-Fix-widgets.ImageInput-for-Django-1.11.patch
0e26d21f8f9e9cb0a60ed06f05d2445798ae90358893b3a061ff1cb7ce7a396c5efd47045a855752fd8505c3e64d9dd4b76464b65df0a26f897dba576e77398f 0008-Allow-latest-django-haystack-release-for-Django-1.11.patch"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment