Skip to content

Commit

Permalink
add language check workaround to menus as well
Browse files Browse the repository at this point in the history
  • Loading branch information
Radosław Stępień committed May 6, 2020
1 parent 390d361 commit 0ed1f77
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
6 changes: 3 additions & 3 deletions cms/tests/test_cache.py
Expand Up @@ -91,12 +91,12 @@ def test_cache_placeholder(self):
with self.settings(**overrides):
with self.assertNumQueries(FuzzyInt(13, 25)):
self.client.get(page1_url)
with self.assertNumQueries(FuzzyInt(5, 12)):
with self.assertNumQueries(FuzzyInt(5, 11)):
self.client.get(page1_url)

overrides['CMS_PLACEHOLDER_CACHE'] = False
with self.settings(**overrides):
with self.assertNumQueries(FuzzyInt(7, 16)):
with self.assertNumQueries(FuzzyInt(7, 15)):
self.client.get(page1_url)

def test_no_cache_plugin(self):
Expand Down Expand Up @@ -172,7 +172,7 @@ def test_no_cache_plugin(self):
with self.assertNumQueries(5):
output2 = self.render_template_obj(template, {}, request)
with self.settings(CMS_PAGE_CACHE=False):
with self.assertNumQueries(FuzzyInt(8, 15)):
with self.assertNumQueries(FuzzyInt(8, 14)):
response = self.client.get(page1_url)
resp2 = response.content.decode('utf8').split("$$$")[1]
self.assertNotEqual(output, output2)
Expand Down
2 changes: 1 addition & 1 deletion cms/utils/i18n.py
Expand Up @@ -202,7 +202,7 @@ def is_language_prefix_patterns_used():
for url_pattern in get_resolver(None).url_patterns:
pattern = getattr(url_pattern, 'pattern', url_pattern)
if isinstance(pattern, LocalePrefixPattern):
if pattern.prefix_default_language:
if pattern.language_prefix != '':
return True
return False

Expand Down
9 changes: 7 additions & 2 deletions menus/menu_pool.py
Expand Up @@ -10,7 +10,9 @@
from django.utils.functional import cached_property
from django.utils.module_loading import autodiscover_modules
from django.utils.translation import get_language_from_request, ugettext_lazy as _

from cms.utils import get_current_site
from cms.utils.i18n import (get_default_language_for_site,
is_language_prefix_patterns_used)
from cms.utils.conf import get_cms_setting
from cms.utils.moderator import use_draft

Expand Down Expand Up @@ -102,7 +104,10 @@ def __init__(self, pool, request):
# instance lives.
self.menus = pool.get_registered_menus(for_rendering=True)
self.request = request
self.request_language = get_language_from_request(request, check_path=True)
if is_language_prefix_patterns_used():
self.request_language = get_language_from_request(request, check_path=True)
else:
self.request_language = get_default_language_for_site(get_current_site().pk)
self.site = Site.objects.get_current(request)

@property
Expand Down

0 comments on commit 0ed1f77

Please sign in to comment.