From 79cecbc136cdf75c5f47beaf68fa7002e3c431ce Mon Sep 17 00:00:00 2001 From: Snake-Soft <40820005+snake-soft@users.noreply.github.com> Date: Fri, 21 Jul 2023 10:36:47 +0200 Subject: [PATCH] Fix Django 4 errors (#317) * Ugettext is Removed in Django 4.0 * Signal kwarg providing_args is Disallowed in Django 4.0 * Test against Django 4.2 and remove python 3.7 --------- Co-authored-by: Frank Hennige Co-authored-by: Joey Jurjens --- .github/workflows/ci.yml | 4 ++-- oscarapi/middleware.py | 2 +- oscarapi/serializers/basket.py | 2 +- oscarapi/serializers/fields.py | 2 +- oscarapi/serializers/product.py | 2 +- oscarapi/signals.py | 9 ++++++++- oscarapi/utils/categories.py | 2 +- oscarapi/views/basket.py | 2 +- 8 files changed, 16 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c06479fb..62adcda0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,8 +33,8 @@ jobs: strategy: fail-fast: true matrix: - python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"] - django-version: ["3.2"] + python-version: ["3.8", "3.9", "3.10", "3.11"] + django-version: ["3.2", "4.2"] oscar-version: ["3.2"] steps: - name: Download src dir diff --git a/oscarapi/middleware.py b/oscarapi/middleware.py index 0c3c5bb8..418c617b 100644 --- a/oscarapi/middleware.py +++ b/oscarapi/middleware.py @@ -5,7 +5,7 @@ from django.contrib.sessions.middleware import SessionMiddleware from django.core.exceptions import PermissionDenied from django.http.response import HttpResponse -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from oscar.core.loading import get_class diff --git a/oscarapi/serializers/basket.py b/oscarapi/serializers/basket.py index 5b9fa4e9..1f9ee3ff 100644 --- a/oscarapi/serializers/basket.py +++ b/oscarapi/serializers/basket.py @@ -2,7 +2,7 @@ import logging from decimal import Decimal -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from django.contrib.auth import get_user_model from rest_framework import serializers diff --git a/oscarapi/serializers/fields.py b/oscarapi/serializers/fields.py index 3e56feb3..1e0599f8 100644 --- a/oscarapi/serializers/fields.py +++ b/oscarapi/serializers/fields.py @@ -7,7 +7,7 @@ from urllib.error import HTTPError from django.conf import settings as django_settings from django.db import IntegrityError -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from django.core.exceptions import ObjectDoesNotExist, ValidationError from django.core.files import File from django.utils.functional import cached_property diff --git a/oscarapi/serializers/product.py b/oscarapi/serializers/product.py index 6112f5aa..b480d6f3 100644 --- a/oscarapi/serializers/product.py +++ b/oscarapi/serializers/product.py @@ -2,7 +2,7 @@ import logging from copy import deepcopy -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from rest_framework import serializers from rest_framework.fields import empty diff --git a/oscarapi/signals.py b/oscarapi/signals.py index e3476577..17d20090 100644 --- a/oscarapi/signals.py +++ b/oscarapi/signals.py @@ -1,3 +1,10 @@ +import django from django.dispatch import Signal -oscarapi_post_checkout = Signal(providing_args=["order", "user", "request", "response"]) + +oscarapi_post_checkout_args = ["order", "user", "request", "response"] + +if django.VERSION >= (3, 0): + oscarapi_post_checkout = Signal() +else: + oscarapi_post_checkout = Signal(providing_args=oscarapi_post_checkout_args) diff --git a/oscarapi/utils/categories.py b/oscarapi/utils/categories.py index ac9d35bb..539b7d6c 100644 --- a/oscarapi/utils/categories.py +++ b/oscarapi/utils/categories.py @@ -1,4 +1,4 @@ -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from rest_framework.exceptions import NotFound diff --git a/oscarapi/views/basket.py b/oscarapi/views/basket.py index 905dfedf..07732688 100644 --- a/oscarapi/views/basket.py +++ b/oscarapi/views/basket.py @@ -1,5 +1,5 @@ # pylint: disable=W0632 -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from oscar.apps.basket import signals from oscar.core.loading import get_model, get_class