Skip to content

Commit

Permalink
Patch for Django 4.1 support. (#44)
Browse files Browse the repository at this point in the history
Fixes: AttributeError: 'UserAgentMiddleware' object has no attribute '_is_coroutine'
  • Loading branch information
sarahboyce authored Sep 27, 2022
1 parent cda396c commit f13a3a4
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion django_seo_js/backends/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .base import SelectedBackend, SEOBackendBase
from .base import SelectedBackend, SelectedBackendMixin, SEOBackendBase
from .prerender import PrerenderHosted, PrerenderIO
from .test import TestBackend, TestServiceDownBackend
11 changes: 7 additions & 4 deletions django_seo_js/backends/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,18 @@
))


class SelectedBackend(MiddlewareMixin):

def __init__(self, get_response=None, *args, **kwargs):
self.get_response = get_response
class SelectedBackendMixin:
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
module_path = settings.BACKEND
backend_module = importlib.import_module(".".join(module_path.split(".")[:-1]))
self.backend = getattr(backend_module, module_path.split(".")[-1])()


class SelectedBackend(MiddlewareMixin, SelectedBackendMixin):
pass


class SEOBackendBase:
"""The base class to inherit for SEO_JS backends"""

Expand Down
4 changes: 2 additions & 2 deletions django_seo_js/helpers.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from django_seo_js import settings
from django_seo_js.backends import SelectedBackend
from django_seo_js.backends import SelectedBackendMixin


def update_cache_for_url(url):
if settings.ENABLED:
selector = SelectedBackend()
selector = SelectedBackendMixin()
return selector.backend.update_url(url)
return False

Expand Down
12 changes: 8 additions & 4 deletions django_seo_js/tests/backends/test_base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.test import TestCase

from django_seo_js.tests.utils import override_settings
from django_seo_js.backends import PrerenderIO, SelectedBackend, SEOBackendBase, TestBackend
from django_seo_js.tests.utils import override_settings, get_response_empty
from django_seo_js.backends import PrerenderIO, SelectedBackend, SelectedBackendMixin, SEOBackendBase, TestBackend


class SEOBackendBaseTest(TestCase):
Expand All @@ -18,10 +18,14 @@ def test_update_url(self):
class SelectedBackendTest(TestCase):

def test_default_backend(self):
s = SelectedBackend()
s_mixin = SelectedBackendMixin()
s = SelectedBackend(get_response_empty)
self.assertTrue(isinstance(s_mixin.backend, PrerenderIO))
self.assertTrue(isinstance(s.backend, PrerenderIO))

@override_settings(BACKEND='django_seo_js.backends.TestBackend')
def test_override_backend(self):
s = SelectedBackend()
s_mixin = SelectedBackendMixin()
s = SelectedBackend(get_response_empty)
self.assertTrue(isinstance(s_mixin.backend, TestBackend))
self.assertTrue(isinstance(s.backend, TestBackend))

0 comments on commit f13a3a4

Please sign in to comment.