forked from skoczen/django-seo-js
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switches to EscapedFragmentMiddleware, fixes tests.
- Loading branch information
Showing
8 changed files
with
82 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,3 +36,5 @@ README.html | |
shelf.db | ||
.idea/* | ||
venv | ||
|
||
django_seo_js/.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
from .escaped_fragment import EscapedFragmentMiddleware | ||
from .hashbang import HashBangMiddleware | ||
from .useragent import UserAgentMiddleware |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from django_seo_js import settings | ||
from django_seo_js.backends import SelectedBackend | ||
from django_seo_js.helpers import request_should_be_ignored | ||
|
||
import logging | ||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class EscapedFragmentMiddleware(SelectedBackend): | ||
def process_request(self, request): | ||
if not settings.ENABLED: | ||
return | ||
|
||
if request_should_be_ignored(request): | ||
return | ||
|
||
if "_escaped_fragment_" not in request.GET: | ||
return | ||
|
||
url = self.backend.build_absolute_uri(request) | ||
try: | ||
return self.backend.get_response_for_url(url) | ||
except Exception as e: | ||
logger.exception(e) | ||
|
||
|
||
class HashBangMiddleware(EscapedFragmentMiddleware): | ||
|
||
def __init__(self, *args, **kwargs): | ||
logging.info( | ||
"Deprecation note: HashBangMiddleware has been renamed EscapedFragmentMiddleware," | ||
" for more clarity. Upgrade your MIDDLEWARE_CLASSES to \n" | ||
" 'django_seo_js.middleware.EscapedFragmentMiddleware'" | ||
" when you get a chance. HashBangMiddleware will be removed in v0.5" | ||
) | ||
super(HashBangMiddleware, self).__init__(*args, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,4 @@ | ||
from django_seo_js import settings | ||
from django_seo_js.backends import SelectedBackend | ||
from django_seo_js.helpers import request_should_be_ignored | ||
from .escaped_fragment import HashBangMiddleware | ||
|
||
import logging | ||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class HashBangMiddleware(SelectedBackend): | ||
def process_request(self, request): | ||
if not settings.ENABLED: | ||
return | ||
|
||
if request_should_be_ignored(request): | ||
return | ||
|
||
if "_escaped_fragment_" not in request.GET: | ||
return | ||
|
||
url = self.backend.build_absolute_uri(request) | ||
try: | ||
return self.backend.get_response_for_url(url) | ||
except Exception as e: | ||
logger.exception(e) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
from django.test import TestCase | ||
|
||
from django_seo_js.tests.utils import override_settings | ||
from django_seo_js.middleware import HashBangMiddleware | ||
from django_seo_js.middleware import EscapedFragmentMiddleware | ||
|
||
|
||
class HelpersTest(TestCase): | ||
|
||
@override_settings(BACKEND='django_seo_js.backends.TestBackend') | ||
def test_update_the_render_cache(self): | ||
from django_seo_js.helpers import update_cache_for_url | ||
self.middleware = HashBangMiddleware() | ||
self.middleware = EscapedFragmentMiddleware() | ||
self.assertEqual(update_cache_for_url("http://example.com"), True) | ||
|
||
@override_settings(BACKEND='django_seo_js.backends.TestBackend', ENABLED=False) | ||
def test_update_skips_if_disabled(self): | ||
from django_seo_js.helpers import update_cache_for_url | ||
self.middleware = HashBangMiddleware() | ||
self.middleware = EscapedFragmentMiddleware() | ||
self.assertEqual(update_cache_for_url("http://example.com"), False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters