Skip to content

Commit

Permalink
Deals with the deprecation of request.site in wagtail 2.9 (#488)
Browse files Browse the repository at this point in the history
  • Loading branch information
nickmoreton authored Aug 13, 2023
1 parent 7d4c22c commit cfd2df1
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion longclaw/checkout/gateways/braintree.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def __init__(self):
self.gateway = braintree.BraintreeGateway(access_token=settings.VZERO_ACCESS_TOKEN)

def create_payment(self, request, amount, description=''):
config = Configuration.for_site(request.site)
config = Configuration.for_request(request)
nonce = request.POST.get('payment_method_nonce')
result = self.gateway.transaction.sale({
"amount": str(amount),
Expand Down
2 changes: 1 addition & 1 deletion longclaw/checkout/gateways/stripe.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def __init__(self):

def create_payment(self, request, amount, description=''):
try:
currency = Configuration.for_site(request.site).currency
currency = Configuration.for_request(request).currency
charge = stripe.Charge.create(
amount=int(math.ceil(amount * 100)), # Amount in pence
currency=currency.lower(),
Expand Down
2 changes: 1 addition & 1 deletion longclaw/checkout/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def create_order(email,

ip_address = get_client_ip(request)
if shipping_country and shipping_option:
site_settings = Configuration.for_site(request.site)
site_settings = Configuration.for_request(request)
shipping_rate = get_shipping_cost(
site_settings,
shipping_address.country.pk,
Expand Down
2 changes: 1 addition & 1 deletion longclaw/configuration/context_processors.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from longclaw.configuration.models import Configuration

def currency(request):
config = Configuration.for_site(request.site)
config = Configuration.for_request(request)
return {
'currency_html_code': config.currency_html_code,
'currency': config.currency
Expand Down
2 changes: 1 addition & 1 deletion longclaw/shipping/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def get_shipping_cost_kwargs(request, country=None):

bid = basket_id(request)
option = request.query_params.get('shipping_rate_name', 'standard')
settings = Configuration.for_site(request.site)
settings = Configuration.for_request(request)

return dict(country_code=country_code, destination=destination, basket_id=bid, settings=settings, name=option)

Expand Down
2 changes: 1 addition & 1 deletion longclaw/shipping/templatetags/longclawshipping_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
def shipping_rate(context, **kwargs):
"""Return the shipping rate for a country & shipping option name.
"""
settings = Configuration.for_site(context["request"].site)
settings = Configuration.for_request(context["request"])
code = kwargs.get('code', None)
name = kwargs.get('name', None)
return get_shipping_cost(settings, code, name)
12 changes: 6 additions & 6 deletions longclaw/shipping/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def test_get_shipping_cost_kwargs_only_country_code(self):
self.assertEqual(result['country_code'], 'US')
self.assertEqual(result['destination'], None)
self.assertEqual(result['basket_id'], basket_id(api_request))
self.assertEqual(result['settings'], Configuration.for_site(api_request.site))
self.assertEqual(result['settings'], Configuration.for_request(api_request))
self.assertEqual(result['name'], 'standard')

def test_get_shipping_cost_kwargs_country_code_and_shipping_rate_name(self):
Expand All @@ -81,7 +81,7 @@ def test_get_shipping_cost_kwargs_country_code_and_shipping_rate_name(self):
self.assertEqual(result['country_code'], 'US')
self.assertEqual(result['destination'], None)
self.assertEqual(result['basket_id'], basket_id(api_request))
self.assertEqual(result['settings'], Configuration.for_site(api_request.site))
self.assertEqual(result['settings'], Configuration.for_request(api_request))
self.assertEqual(result['name'], 'foo')

def test_get_shipping_cost_kwargs_only_country(self):
Expand All @@ -91,7 +91,7 @@ def test_get_shipping_cost_kwargs_only_country(self):
self.assertEqual(result['country_code'], self.country.pk)
self.assertEqual(result['destination'], None)
self.assertEqual(result['basket_id'], basket_id(api_request))
self.assertEqual(result['settings'], Configuration.for_site(api_request.site))
self.assertEqual(result['settings'], Configuration.for_request(api_request))
self.assertEqual(result['name'], 'standard')

def test_get_shipping_cost_kwargs_only_country_known_iso(self):
Expand All @@ -102,7 +102,7 @@ def test_get_shipping_cost_kwargs_only_country_known_iso(self):
self.assertEqual(result['country_code'], 'ZZ')
self.assertEqual(result['destination'], None)
self.assertEqual(result['basket_id'], basket_id(api_request))
self.assertEqual(result['settings'], Configuration.for_site(api_request.site))
self.assertEqual(result['settings'], Configuration.for_request(api_request))
self.assertEqual(result['name'], 'standard')

def test_get_shipping_cost_kwargs_with_destination(self):
Expand All @@ -113,7 +113,7 @@ def test_get_shipping_cost_kwargs_with_destination(self):
self.assertEqual(result['country_code'], destination.country.pk)
self.assertEqual(result['destination'], destination)
self.assertEqual(result['basket_id'], basket_id(api_request))
self.assertEqual(result['settings'], Configuration.for_site(api_request.site))
self.assertEqual(result['settings'], Configuration.for_request(api_request))
self.assertEqual(result['name'], 'standard')

def test_get_shipping_cost_kwargs_with_destination_and_country_code(self):
Expand All @@ -125,7 +125,7 @@ def test_get_shipping_cost_kwargs_with_destination_and_country_code(self):
self.assertEqual(result['country_code'], '11')
self.assertEqual(result['destination'], destination)
self.assertEqual(result['basket_id'], basket_id(api_request))
self.assertEqual(result['settings'], Configuration.for_site(api_request.site))
self.assertEqual(result['settings'], Configuration.for_request(api_request))
self.assertEqual(result['name'], 'standard')

def test_create_address(self):
Expand Down
2 changes: 1 addition & 1 deletion longclaw/stats/wagtail_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def get_context(self):
class MonthlySales(LongclawSummaryItem):
order = 30
def get_context(self):
settings = Configuration.for_site(self.request.site)
settings = Configuration.for_request(self.request)
sales = stats.sales_for_time_period(*stats.current_month())
return {
'total': "{}{}".format(settings.currency_html_code,
Expand Down

0 comments on commit cfd2df1

Please sign in to comment.