From b74153fabb785bdfcccf07c2be3f0668d660c25f Mon Sep 17 00:00:00 2001 From: Adrian Fedoreanu Date: Sun, 28 Jun 2015 00:15:41 +0100 Subject: [PATCH] naming parameters - django-oscar 1.1 compatible ERROR Internal Server Error: /en/checkout/paypal/preview/5/ Traceback (most recent call last): File "/virtenvs/test/lib/python2.7/site-packages/django/core/handlers/base.py", line 132, in get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/virtenvs/test/lib/python2.7/site-packages/django/utils/decorators.py", line 145, in inner return func(*args, **kwargs) File "/virtenvs/test/lib/python2.7/site-packages/django/views/generic/base.py", line 71, in view return self.dispatch(request, *args, **kwargs) File "/virtenvs/test/lib/python2.7/site-packages/oscar/apps/checkout/session.py", line 68, in dispatch request, *args, **kwargs) File "/virtenvs/test/lib/python2.7/site-packages/django/views/generic/base.py", line 89, in dispatch return handler(request, *args, **kwargs) File "/virtenvs/test/lib/python2.7/site-packages/paypal/express/views.py", line 200, in get kwargs['basket'] = self.load_frozen_basket(kwargs['basket_id']) File "/virtenvs/test/lib/python2.7/site-packages/paypal/express/views.py", line 231, in load_frozen_basket Applicator().apply(self.request, basket) File "/virtenvs/test/lib/python2.7/site-packages/oscar/apps/offer/applicator.py", line 26, in apply offers = self.get_offers(basket, user, request) File "/virtenvs/test/lib/python2.7/site-packages/oscar/apps/offer/applicator.py", line 58, in get_offers basket_offers = self.get_basket_offers(basket, user) File "/virtenvs/test/lib/python2.7/site-packages/oscar/apps/offer/applicator.py", line 94, in get_basket_offers if not basket.id or not user: AttributeError: 'WSGIRequest' object has no attribute 'id' --- paypal/express/views.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/paypal/express/views.py b/paypal/express/views.py index c1d08e90..d8edad86 100644 --- a/paypal/express/views.py +++ b/paypal/express/views.py @@ -16,6 +16,7 @@ import oscar from oscar.apps.payment.exceptions import UnableToTakePayment +from oscar.core.exceptions import ModuleNotFoundError from oscar.core.loading import get_class, get_model from oscar.apps.shipping.methods import FixedPrice, NoShippingRequired @@ -34,10 +35,14 @@ Country = get_model('address', 'Country') Basket = get_model('basket', 'Basket') Repository = get_class('shipping.repository', 'Repository') -Applicator = get_class('offer.utils', 'Applicator') Selector = get_class('partner.strategy', 'Selector') Source = get_model('payment', 'Source') SourceType = get_model('payment', 'SourceType') +try: + Applicator = get_class('offer.applicator', 'Applicator') +except ModuleNotFoundError: + # fallback for django-oscar<=1.1 + Applicator = get_class('offer.utils', 'Applicator') logger = logging.getLogger('paypal.express') @@ -225,7 +230,7 @@ def load_frozen_basket(self, basket_id): basket.strategy = Selector().strategy(self.request) # Re-apply any offers - Applicator().apply(self.request, basket) + Applicator().apply(request=self.request, basket=basket) return basket