Skip to content

Commit

Permalink
refactor: upgrade code to Django 2.2+ and Python 3.6+
Browse files Browse the repository at this point in the history
  • Loading branch information
henri-hulski committed Feb 17, 2022
1 parent 81b3b26 commit 8eb3b54
Show file tree
Hide file tree
Showing 36 changed files with 125 additions and 240 deletions.
3 changes: 1 addition & 2 deletions cartridge/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@

__version__ = "0.13.0"
__version__ = "1.0.0b1"
12 changes: 1 addition & 11 deletions cartridge/project_template/project_name/settings.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@

from __future__ import absolute_import, unicode_literals
import os

from django import VERSION as DJANGO_VERSION
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _


######################
Expand Down Expand Up @@ -294,9 +291,6 @@
},
]

if DJANGO_VERSION < (1, 9):
del TEMPLATES[0]["OPTIONS"]["builtins"]


################
# APPLICATIONS #
Expand Down Expand Up @@ -350,10 +344,6 @@
"mezzanine.core.middleware.FetchFromCacheMiddleware",
)

if DJANGO_VERSION < (1, 10):
MIDDLEWARE_CLASSES = MIDDLEWARE
del MIDDLEWARE


# Store these package names here as they may change in the future since
# at the moment we are using custom forks of them.
Expand Down
22 changes: 10 additions & 12 deletions cartridge/project_template/project_name/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from __future__ import unicode_literals

from django.conf.urls import include, url
from django.urls import include, path
from django.conf.urls.i18n import i18n_patterns
from django.contrib import admin
from django.views.i18n import set_language
Expand All @@ -19,19 +17,19 @@
urlpatterns = i18n_patterns(
# Change the admin prefix here to use an alternate URL for the
# admin interface, which would be marginally more secure.
url("^admin/", include(admin.site.urls)),
path("admin/", include(admin.site.urls)),
)

if settings.USE_MODELTRANSLATION:
urlpatterns += [
url('^i18n/$', set_language, name='set_language'),
path('i18n/', set_language, name='set_language'),
]

urlpatterns += [

# Cartridge URLs.
url("^shop/", include("cartridge.shop.urls")),
url("^account/orders/$", order_history, name="shop_order_history"),
path("shop/", include("cartridge.shop.urls")),
path("account/orders/", order_history, name="shop_order_history"),

# We don't want to presume how your homepage works, so here are a
# few patterns you can use to set it up.
Expand All @@ -43,7 +41,7 @@
# one homepage pattern, so if you use a different one, comment this
# one out.

url("^$", direct_to_template, {"template": "index.html"}, name="home"),
path("", direct_to_template, {"template": "index.html"}, name="home"),

# HOMEPAGE AS AN EDITABLE PAGE IN THE PAGE TREE
# ---------------------------------------------
Expand All @@ -59,7 +57,7 @@
# should be used if you want to customize the homepage's template.
# NOTE: Don't forget to import the view function too!

# url("^$", mezzanine.pages.views.page, {"slug": "/"}, name="home"),
# path("", mezzanine.pages.views.page, {"slug": "/"}, name="home"),

# HOMEPAGE FOR A BLOG-ONLY SITE
# -----------------------------
Expand All @@ -70,7 +68,7 @@
# page tree in the admin if it was installed.
# NOTE: Don't forget to import the view function too!

# url("^$", mezzanine.blog.views.blog_post_list, name="home"),
# path("", mezzanine.blog.views.blog_post_list, name="home"),

# MEZZANINE'S URLS
# ----------------
Expand All @@ -83,7 +81,7 @@
# ``mezzanine.urls``, go right ahead and take the parts you want
# from it, and use them directly below instead of using
# ``mezzanine.urls``.
url("^", include("mezzanine.urls")),
path("", include("mezzanine.urls")),

# MOUNTING MEZZANINE UNDER A PREFIX
# ---------------------------------
Expand All @@ -99,7 +97,7 @@
# Note that for any of the various homepage patterns above, you'll
# need to use the ``SITE_PREFIX`` setting as well.

# url("^%s/" % settings.SITE_PREFIX, include("mezzanine.urls"))
# path("%s/" % settings.SITE_PREFIX, include("mezzanine.urls"))

]

Expand Down
2 changes: 0 additions & 2 deletions cartridge/shop/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
from __future__ import unicode_literals

from cartridge import __version__
17 changes: 7 additions & 10 deletions cartridge/shop/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
from __future__ import unicode_literals
from future.builtins import super, zip

"""
Admin classes for all the shop models.
Expand Down Expand Up @@ -34,7 +31,7 @@
from django.contrib import admin
from django.db.models import ImageField
from django.utils.html import format_html
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

from mezzanine.conf import settings
from mezzanine.core.admin import (
Expand Down Expand Up @@ -176,7 +173,7 @@ def save_model(self, request, obj, form, change):
"""
Store the product ID for creating variations in save_formset.
"""
super(ProductAdmin, self).save_model(request, obj, form, change)
super().save_model(request, obj, form, change)
# We store the product ID so we can retrieve a clean copy of
# the product in save_formset, see: GH #301.
self._product_id = obj.id
Expand Down Expand Up @@ -213,16 +210,16 @@ def save_formset(self, request, form, formset, change):
if formset.model == ProductImage:
self._images_formset = formset
else:
super(ProductAdmin, self).save_formset(request, form, formset,
super().save_formset(request, form, formset,
change)

# Run each of the variation manager methods if we're saving
# the variations formset.
if formset.model == ProductVariation:

# Build up selected options for new variations.
options = dict([(f, request.POST.getlist(f)) for f in option_fields
if request.POST.getlist(f)])
options = {f: request.POST.getlist(f) for f in option_fields
if request.POST.getlist(f)}
# Create a list of image IDs that have been marked to delete.
deleted_images = [request.POST.get(f.replace("-DELETE", "-id"))
for f in request.POST
Expand All @@ -238,7 +235,7 @@ def save_formset(self, request, form, formset, change):
product.variations.set_default_images(deleted_images)

# Save the images formset stored previously.
super(ProductAdmin, self).save_formset(request, form,
super().save_formset(request, form,
self._images_formset, change)

# Run again to allow for no images existing previously, with
Expand Down Expand Up @@ -335,7 +332,7 @@ def change_view(self, *args, **kwargs):
if kwargs.get("extra_context", None) is None:
kwargs["extra_context"] = {}
kwargs["extra_context"]["has_pdf"] = HAS_PDF
return super(OrderAdmin, self).change_view(*args, **kwargs)
return super().change_view(*args, **kwargs)


class SaleAdmin(admin.ModelAdmin):
Expand Down
4 changes: 1 addition & 3 deletions cartridge/shop/checkout.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
"""
Checkout process utilities.
"""
from __future__ import unicode_literals

from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from django.template.loader import get_template, TemplateDoesNotExist
from mezzanine.accounts import get_profile_for_user, ProfileNotConfigured

Expand Down
2 changes: 0 additions & 2 deletions cartridge/shop/context_processors.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

from mezzanine.conf import settings


Expand Down
4 changes: 1 addition & 3 deletions cartridge/shop/defaults.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from __future__ import unicode_literals

from socket import gethostname

from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

from mezzanine.conf import register_setting

Expand Down
15 changes: 6 additions & 9 deletions cartridge/shop/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@
these are consistant when used across multiple models.
"""

from __future__ import absolute_import, unicode_literals
from future.builtins import super

from locale import localeconv

from django.db.models import CharField, DecimalField
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

from cartridge.shop.utils import set_locale

Expand All @@ -23,7 +20,7 @@ def __init__(self, *args, **kwargs):
kwargs["null"] = True
defaults = {"max_length": 50}
defaults.update(kwargs)
super(OptionField, self).__init__(*args, **defaults)
super().__init__(*args, **defaults)


class PercentageField(DecimalField):
Expand All @@ -34,7 +31,7 @@ class PercentageField(DecimalField):
def formfield(self, *args, **kwargs):
defaults = {'min_value': 0, 'max_value': 100}
kwargs.update(**defaults)
return super(PercentageField, self).formfield(*args, **kwargs)
return super().formfield(*args, **kwargs)


class MoneyField(DecimalField):
Expand All @@ -47,7 +44,7 @@ def __init__(self, *args, **kwargs):
defaults = {"null": True, "blank": True, "max_digits": 10,
"decimal_places": localeconv()["frac_digits"]}
defaults.update(kwargs)
super(MoneyField, self).__init__(*args, **defaults)
super().__init__(*args, **defaults)


class SKUField(CharField):
Expand All @@ -59,7 +56,7 @@ def __init__(self, *args, **kwargs):
args = (_("SKU"),)
defaults = {"max_length": 20}
defaults.update(kwargs)
super(SKUField, self).__init__(*args, **defaults)
super().__init__(*args, **defaults)


class DiscountCodeField(CharField):
Expand All @@ -69,4 +66,4 @@ class DiscountCodeField(CharField):
def __init__(self, *args, **kwargs):
defaults = {"max_length": 20}
defaults.update(kwargs)
super(DiscountCodeField, self).__init__(*args, **defaults)
super().__init__(*args, **defaults)
Loading

0 comments on commit 8eb3b54

Please sign in to comment.