Permalink
Browse files

new tests

  • Loading branch information...
1 parent 0fdcf1c commit 7bc1cc295a50d688bb0981a5c6386d9f160f3f35 @digi604 digi604 committed Oct 2, 2012
Showing with 59 additions and 17 deletions.
  1. +1 −1 cms/menu.py
  2. +1 −1 cms/plugins/inherit/cms_plugins.py
  3. +11 −2 cms/plugins/utils.py
  4. +7 −1 cms/tests/multilingual.py
  5. +3 −1 cms/tests/page.py
  6. +17 −1 cms/utils/i18n.py
  7. +19 −10 cms/views.py
View
@@ -272,7 +272,7 @@ def get_nodes(self, request):
nodes.append(page_to_node(page, home, home_cut))
ids.remove(page.pk)
- if ids: # get fallback languages
+ if ids and not hide_untranslated(lang): # get fallback languages if allowed
fallbacks = get_fallback_languages(lang)
for lang in fallbacks:
titles = list(get_title_queryset(request).filter(page__in=ids, language=lang))
@@ -36,7 +36,7 @@ def render(self, context, instance, placeholder):
page = instance.from_page
else:
page = instance.page
- if not instance.page.publisher_is_draft and page.publisher_is_draft:
+ if settings.CMS_MODERATOR and not instance.page.publisher_is_draft and page.publisher_is_draft:
page = page.publisher_public
plugins = get_cmsplugin_queryset(request).filter(
View
@@ -4,6 +4,7 @@
from cms.plugin_pool import plugin_pool
from cms.utils import get_language_from_request
+from cms.utils.i18n import get_redirect_on_fallback, get_fallback_languages
from cms.utils.moderator import get_cmsplugin_queryset
def get_plugins(request, placeholder, lang=None):
@@ -24,9 +25,17 @@ def assign_plugins(request, placeholders, lang=None):
if not placeholders:
return
lang = lang or get_language_from_request(request)
-
+ request_lang = lang
+ if hasattr(request, "current_page") and request.current_page is not None:
+ languages = request.current_page.get_languages()
+ if not lang in languages and not get_redirect_on_fallback(lang):
+ fallbacks = get_fallback_languages(lang)
+ for fallback in fallbacks:
+ if fallback in languages:
+ request_lang = fallback
+ break
# get all plugins for the given placeholders
- qs = get_cmsplugin_queryset(request).filter(placeholder__in=placeholders, language=lang, parent__isnull=True).order_by('placeholder', 'position')
+ qs = get_cmsplugin_queryset(request).filter(placeholder__in=placeholders, language=request_lang, parent__isnull=True).order_by('placeholder', 'position')
plugin_list = downcast_plugins(qs)
# split the plugins up by placeholder
@@ -129,4 +129,10 @@ def test_language_fallback(self):
lang_settings[1][0]['fallbacks'] = []
lang_settings[1][1]['fallbacks'] = []
with SettingsOverride(CMS_LANGUAGES=lang_settings):
- self.assertRaises(Http404, details, request, '')
+ response = self.client.get("/de/")
+ self.assertEquals(response.status_code, 404)
+ lang_settings = copy.deepcopy(settings.CMS_LANGUAGES)
+ lang_settings['default']['redirect_on_fallback'] = False
+ with SettingsOverride(CMS_LANGUAGES=lang_settings):
+ response = self.client.get("/de/")
+ self.assertEquals(response.status_code, 200)
View
@@ -744,8 +744,10 @@ def test_plugin_loading_queries(self):
# trigger the apphook query so that it doesn't get in our way
reverse('pages-root')
+ # trigger the get_languages query so it doesn't get in our way
+ context = self.get_context()
+ context['request'].current_page.get_languages()
with self.assertNumQueries(4):
- context = self.get_context()
for i, placeholder in enumerate(placeholders):
content = get_placeholder_content(context, context['request'], page, placeholder.slot, False)
for j in range(5):
View
@@ -84,10 +84,15 @@ def get_language_object(language_code, site_id=None):
else:
language['fallbacks'] = fallbacks
if not language.has_key('public'):
- if settings.CMS_LANGUAGES.has_key('defaults'):
+ if settings.CMS_LANGUAGES.has_key('default'):
language['public'] = settings.CMS_LANGUAGES['default'].get('public', True)
else:
language['public'] = True
+ if not language.has_key('redirect_on_fallback'):
+ if settings.CMS_LANGUAGES.has_key('default'):
+ language['redirect_on_fallback'] = settings.CMS_LANGUAGES['default'].get('redirect_on_fallback', True)
+ else:
+ language['redirect_on_fallback'] = True
if not language.has_key('hide_untranslated'):
if settings.CMS_LANGUAGES.has_key('default'):
language['hide_untranslated'] = settings.CMS_LANGUAGES['default'].get('hide_untranslated', True)
@@ -142,6 +147,17 @@ def get_fallback_languages(language, site_id=None):
language = get_language_object(language, site_id)
return language['fallbacks']
+def get_redirect_on_fallback(language, site_id=None):
+ """
+ returns if you should redirect on language fallback
+ :param language:
+ :param site_id:
+ :return: Boolean
+ """
+ site_id = get_site(site_id)
+ language = get_language_object(language, site_id)
+ return language['redirect_on_fallback']
+
def hide_untranslated(language, site_id=None):
"""
Should untranslated pages in this language be hidden?
View
@@ -2,8 +2,9 @@
from __future__ import with_statement
from cms.apphook_pool import apphook_pool
from cms.appresolver import get_app_urls
+from cms.models import Title
from cms.utils import get_template_from_request, get_language_from_request
-from cms.utils.i18n import get_fallback_languages, force_language, get_public_languages
+from cms.utils.i18n import get_fallback_languages, force_language, get_public_languages, get_redirect_on_fallback
from cms.utils.page_resolver import get_page_from_request
from cms.test_utils.util.context_managers import SettingsOverride
from django.conf import settings
@@ -63,16 +64,21 @@ def details(request, slug):
if current_language not in available_languages:
# If we didn't find the required page in the requested (current)
# language, let's try to find a fallback
+ found = False
for alt_lang in get_fallback_languages(current_language):
if alt_lang in available_languages:
- with force_language(alt_lang):
- path = page.get_absolute_url(language=alt_lang, fallback=True)
- # In the case where the page is not available in the
- # preferred language, *redirect* to the fallback page. This
- # is a design decision (instead of rendering in place)).
- return HttpResponseRedirect(path)
- # There is a page object we can't find a proper language to render it
- _handle_no_page(request, slug)
+ if get_redirect_on_fallback(current_language):
+ with force_language(alt_lang):
+ path = page.get_absolute_url(language=alt_lang, fallback=True)
+ # In the case where the page is not available in the
+ # preferred language, *redirect* to the fallback page. This
+ # is a design decision (instead of rendering in place)).
+ return HttpResponseRedirect(path)
+ else:
+ found = True
+ if not found:
+ # There is a page object we can't find a proper language to render it
+ _handle_no_page(request, slug)
if apphook_pool.get_apphooks():
# There are apphooks in the pool. Let's see if there is one for the
@@ -81,7 +87,10 @@ def details(request, slug):
# pointless
# page = applications_page_check(request, page, slug)
# Check for apphooks! This time for real!
- app_urls = page.get_application_urls(current_language, False)
+ try:
+ app_urls = page.get_application_urls(current_language, False)
+ except Title.DoesNotExist:
+ app_urls = []
if app_urls:
app = apphook_pool.get_apphook(app_urls)
pattern_list = []

0 comments on commit 7bc1cc2

Please sign in to comment.