Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Make middleware forwards-compatible
Patryk Zawadzkib320803c57f9
diff --git a/saleor/core/middleware.py b/saleor/core/middleware.pyindex dd74e54355..c551f63263 100644--- a/saleor/core/middleware.py+++ b/saleor/core/middleware.py@@ -2,6 +2,7 @@ import loggingfrom django.conf import settingsfrom django.contrib.sites.models import Site+from django.utils.deprecation import MiddlewareMixinfrom django.utils.translation import get_languagefrom django_countries.fields import Country@@ -12,7 +13,7 @@ from .utils import get_client_ip, get_country_by_ip, get_currency_for_countrylogger = logging.getLogger(__name__)-class GoogleAnalytics(object):+class GoogleAnalytics(MiddlewareMixin):def process_request(self, request):client_id = analytics.get_client_id(request)path = request.path@@ -26,15 +27,14 @@ class GoogleAnalytics(object):logger.exception('Unable to update analytics')-class DiscountMiddleware(object):+class DiscountMiddleware(MiddlewareMixin):def process_request(self, request):discounts = Sale.objects.all()discounts = discounts.prefetch_related('products', 'categories')request.discounts = discounts-class CountryMiddleware(object):-+class CountryMiddleware(MiddlewareMixin):def process_request(self, request):client_ip = get_client_ip(request)if client_ip:@@ -43,8 +43,7 @@ class CountryMiddleware(object):request.country = Country(settings.DEFAULT_COUNTRY)-class CurrencyMiddleware(object):-+class CurrencyMiddleware(MiddlewareMixin):def process_request(self, request):if hasattr(request, 'country') and request.country is not None:request.currency = get_currency_for_country(request.country)@@ -52,7 +51,7 @@ class CurrencyMiddleware(object):request.currency = settings.DEFAULT_CURRENCY-class ClearSiteCacheMiddleware(object):+class ClearSiteCacheMiddleware(MiddlewareMixin):"""This middleware clears the Sites cache, refetches the current Siteand sets it as attribute in request object for future uses in this