Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Django 2.2 compatibility #346

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
language: python
env:
- DJANGO="Django>=1.11,<1.12"
- DJANGO="Django>=2.2,<3.0"
python:
- "2.7"
- "3.4"
- "3.5"
- "3.6"
- "3.7"
- "3.8"
install:
- pip install $DJANGO
- pip install -e git://github.com/stephenmcd/mezzanine.git#egg=mezzanine
- pip install -e git://github.com/fermorltd/mezzanine.git@2.2-compat#egg=mezzanine
- pip install pyPdf
script:
- python setup.py test
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added cartridge/project_template/media/product/blue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added cartridge/project_template/media/product/red.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions cartridge/project_template/project_name/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
MEDIA_URL = STATIC_URL + "media/"
MEDIA_URL = "/media/"

# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/media/"
Expand Down Expand Up @@ -306,6 +306,7 @@
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.messages",
"django.contrib.redirects",
"django.contrib.sessions",
"django.contrib.sites",
Expand Down Expand Up @@ -337,7 +338,6 @@
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',

Expand Down
4 changes: 2 additions & 2 deletions cartridge/shop/checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def initial_order_data(request, form_class=None):
# Look for order in previous session.
if not initial:
lookup = {}
if request.user.is_authenticated():
if request.user.is_authenticated:
lookup["user_id"] = request.user.id
remembered = request.COOKIES.get("remember", "").split(":")
if len(remembered) == 2 and remembered[0] == sign(remembered[1]):
Expand All @@ -115,7 +115,7 @@ def initial_order_data(request, form_class=None):
previous = list(Order.objects.filter(**lookup).values())[:1]
if len(previous) > 0:
initial.update(previous[0])
if not initial and request.user.is_authenticated():
if not initial and request.user.is_authenticated:
# No previous order data - try and get field values from the
# logged in user. Check the profile model before the user model
# if it's configured. If the order field name uses one of the
Expand Down
4 changes: 2 additions & 2 deletions cartridge/shop/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ class ImageWidget(forms.FileInput):
"""
Render a visible thumbnail for image fields.
"""
def render(self, name, value, attrs):
def render(self, name, value, attrs, renderer=None):
rendered = super(ImageWidget, self).render(name, value, attrs)
if value:
orig = u"%s%s" % (settings.MEDIA_URL, value)
Expand All @@ -453,7 +453,7 @@ class MoneyWidget(forms.TextInput):
"""
Render missing decimal places for money fields.
"""
def render(self, name, value, attrs):
def render(self, name, value, attrs, renderer=None):
try:
value = float(value)
except (TypeError, ValueError):
Expand Down
2 changes: 1 addition & 1 deletion cartridge/shop/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def get_for_user(self, order_id, request):
the given request object can access it.
"""
lookup = {"id": order_id}
if not request.user.is_authenticated():
if not request.user.is_authenticated:
lookup["key"] = request.session.session_key
elif not request.user.is_staff:
lookup["user_id"] = request.user.id
Expand Down
9 changes: 5 additions & 4 deletions cartridge/shop/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from __future__ import division, unicode_literals

from django.utils.safestring import mark_safe
from future.builtins import str, super
from future.utils import with_metaclass

Expand Down Expand Up @@ -143,9 +145,8 @@ def save(self, *args, **kwargs):
default = self.variations.get(default=True)
self.copy_price_fields_to(default)

@models.permalink
def get_absolute_url(self):
return ("shop_product", (), {"slug": self.slug})
return reverse("shop_product", kwargs={"slug": self.slug})

def copy_default_variation(self):
"""
Expand Down Expand Up @@ -544,9 +545,9 @@ def invoice(self):
Returns the HTML for a link to the PDF invoice for use in the
order listing view of the admin.
"""
url = reverse("shop_invoice", args=(self.id,))
url = reverse("shop:shop_invoice", args=(self.id,))
text = ugettext("Download PDF invoice")
return "<a href='%s?format=pdf'>%s</a>" % (url, text)
return mark_safe("<a href='%s?format=pdf'>%s</a>" % (url, text))
invoice.allow_tags = True
invoice.short_description = ""

Expand Down
38 changes: 19 additions & 19 deletions cartridge/shop/templates/admin/shop/order/change_form.html
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
{% extends "admin/change_form.html" %}
{% load i18n %}
{% block before_content %}
{% if change %}
<form id="resend-email" method="POST" action="{% url "shop_invoice_resend" object_id %}?next={{ request.path }}">
{% csrf_token %}
</form>
{% endif %}
{{ block.super }}
{% endblock %}
{% block object-tools-items %}
{% if change and has_pdf %}
<li><a href="{% url "shop_invoice" object_id %}?format=pdf">{% trans "Download PDF invoice" %}</a></li>
{% endif %}
<li><a href="#" onclick="document.getElementById('resend-email').submit(); return false;">{% trans "Re-send order email" %}</a></li>
{{ block.super }}
{% endblock %}
{% extends "admin/change_form.html" %}
{% load i18n %}

{% block before_content %}
{% if change %}
<form id="resend-email" method="POST" action="{% url "shop_invoice_resend" object_id %}?next={{ request.path }}">
{% csrf_token %}
</form>
{% endif %}
{{ block.super }}
{% endblock %}

{% block object-tools-items %}
{% if change and has_pdf %}
<li><a href="{% url "shop:shop_invoice" object_id %}?format=pdf">{% trans "Download PDF invoice" %}</a></li>
{% endif %}
<li><a href="#" onclick="document.getElementById('resend-email').submit(); return false;">{% trans "Re-send order email" %}</a></li>
{{ block.super }}
{% endblock %}
2 changes: 1 addition & 1 deletion cartridge/shop/templates/shop/complete.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
<form class="order-complete-form" method="post" action="{% url "shop_invoice_resend" order.id %}?next={{ request.path }}">
{% csrf_token %}
{% if has_pdf %}
<a class="btn btn-primary" href="{% url "shop_invoice" order.id %}?format=pdf">{% trans "Download PDF invoice" %}</a>
<a class="btn btn-primary" href="{% url "shop:shop_invoice" order.id %}?format=pdf">{% trans "Download PDF invoice" %}</a>
{% endif %}
<a class="btn btn-default" target="_blank" href="{% url "shop_invoice" order.id %}">{% trans "View invoice in your browser" %}</a>
<input type="submit" class="btn btn-default" value="{% trans "Re-send order email" %}">
Expand Down
2 changes: 1 addition & 1 deletion cartridge/shop/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
from functools import reduce
from unittest import skipUnless

from django.core.urlresolvers import reverse
from django.test import TestCase
from django.test.client import RequestFactory
from django.utils.timezone import now
from django.utils.translation import ugettext_lazy as _
from django.urls import reverse
from mezzanine.conf import settings
from mezzanine.core.models import CONTENT_STATUS_PUBLISHED
from mezzanine.utils.importing import import_dotted_path
Expand Down
22 changes: 9 additions & 13 deletions cartridge/shop/views.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
from __future__ import unicode_literals
from future.builtins import int, str

from json import dumps

from django.contrib.auth.decorators import login_required
from django.contrib.messages import info
from django.core.urlresolvers import reverse
from django.urls import reverse
from django.db.models import Sum
from django.http import Http404, HttpResponse
from django.shortcuts import get_object_or_404, redirect
Expand Down Expand Up @@ -68,14 +65,14 @@ def product(request, slug, template="shop/product.html",
request.cart.add_item(add_product_form.variation, quantity)
recalculate_cart(request)
info(request, _("Item added to cart"))
return redirect("shop_cart")
return redirect("shop:shop_cart")
else:
skus = request.wishlist
sku = add_product_form.variation.sku
if sku not in skus:
skus.append(sku)
info(request, _("Item added to wishlist"))
response = redirect("shop_wishlist")
response = redirect("shop:shop_wishlist")
set_cookie(response, "wishlist", ",".join(skus))
return response
related = []
Expand Down Expand Up @@ -123,12 +120,12 @@ def wishlist(request, template="shop/wishlist.html",
request.cart.add_item(add_product_form.variation, 1)
recalculate_cart(request)
message = _("Item added to cart")
url = "shop_cart"
url = "shop:shop_cart"
else:
error = list(add_product_form.errors.values())[0]
else:
message = _("Item removed from wishlist")
url = "shop_wishlist"
url = "shop:shop_wishlist"
sku = request.POST.get("sku")
if sku in skus:
skus.remove(sku)
Expand Down Expand Up @@ -199,7 +196,7 @@ def cart(request, template="shop/cart.html",
# shipping details step where shipping is normally set.
recalculate_cart(request)
if valid:
return redirect("shop_cart")
return redirect("shop:shop_cart")
context = {"cart_formset": cart_formset}
context.update(extra_context or {})
settings.clear_cache()
Expand All @@ -218,8 +215,7 @@ def checkout_steps(request, form_class=OrderForm, extra_context=None):
# Do the authentication check here rather than using standard
# login_required decorator. This means we can check for a custom
# LOGIN_URL and fall back to our own login view.
authenticated = request.user.is_authenticated()
if settings.SHOP_CHECKOUT_ACCOUNT_REQUIRED and not authenticated:
if settings.SHOP_CHECKOUT_ACCOUNT_REQUIRED and not request.user.is_authenticated:
url = "%s?next=%s" % (settings.LOGIN_URL, reverse("shop_checkout"))
return redirect(url)

Expand Down Expand Up @@ -308,7 +304,7 @@ def checkout_steps(request, form_class=OrderForm, extra_context=None):
checkout.send_order_email(request, order)
# Set the cookie for remembering address details
# if the "remember" checkbox was checked.
response = redirect("shop_complete")
response = redirect("shop:shop_complete")
if form.cleaned_data.get("remember"):
remembered = "%s:%s" % (sign(order.key), order.key)
set_cookie(response, "remember", remembered,
Expand Down Expand Up @@ -435,5 +431,5 @@ def invoice_resend_email(request, order_id):
if request.user.is_staff:
redirect_to = reverse("admin:shop_order_change", args=[order_id])
else:
redirect_to = reverse("shop_order_history")
redirect_to = reverse("shop:shop_order_history")
return redirect(redirect_to)