Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

force_language rename

  • Loading branch information...
commit 5806d99291bc389b67520ec35fb744767e983069 1 parent bddbad1
Patrick Lauber digi604 authored
4 cms/appresolver.py
View
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import with_statement
from cms.apphook_pool import apphook_pool
-from cms.utils.i18n import ForceLang
+from cms.utils.i18n import force_language
from cms.utils.moderator import get_page_queryset
from django.conf import settings
@@ -204,7 +204,7 @@ def get_app_patterns():
app_ns = app.app_name, inst_ns
else:
app_ns = None, None
- with ForceLang(title.language):
+ with force_language(title.language):
hooked_applications[title.page_id][title.language] = (app_ns, get_patterns_for_title(path, title))
included.append(mix_id)
# Build the app patterns to be included in the cms urlconfs
24 cms/tests/apphooks.py
View
@@ -7,7 +7,7 @@
from cms.test_utils.testcases import CMSTestCase
from cms.test_utils.util.context_managers import SettingsOverride
from cms.tests.menu_utils import DumbPageLanguageUrl
-from cms.utils.i18n import ForceLang
+from cms.utils.i18n import force_language
from django.contrib.auth.models import User
from django.core.urlresolvers import clear_url_caches, reverse
import sys
@@ -130,7 +130,7 @@ def test_apphook_on_root(self):
create_title("de", "aphooked-page-de", page, apphook="SampleApp")
self.assertTrue(page.publish())
self.assertTrue(blank_page.publish())
- with ForceLang("en"):
+ with force_language("en"):
response = self.client.get(self.get_pages_root())
self.assertTemplateUsed(response, 'sampleapp/home.html')
@@ -158,7 +158,7 @@ def test_get_page_for_apphook(self):
with SettingsOverride(ROOT_URLCONF='cms.test_utils.project.second_urls_for_apphook_tests'):
en_title, de_title = self.create_base_structure(APP_NAME, ['en', 'de'])
- with ForceLang("en"):
+ with force_language("en"):
path = reverse('sample-settings')
request = self.get_request(path)
request.LANGUAGE_CODE = 'en'
@@ -171,7 +171,7 @@ def test_get_page_for_apphook(self):
self.assertTemplateUsed(response, 'sampleapp/home.html')
self.assertContains(response, en_title.title)
- with ForceLang("de"):
+ with force_language("de"):
path = reverse('sample-settings')
request = self.get_request(path)
@@ -191,7 +191,7 @@ def test_get_root_page_for_apphook_with_instance_namespace(self):
en_title = self.create_base_structure(NS_APP_NAME, 'en', 'instance_ns')
self.reload_urls()
- with ForceLang("en"):
+ with force_language("en"):
path = reverse('namespaced_app_ns:sample-root')
path_instance = reverse('instance_ns:sample-root')
self.assertEquals(path, path_instance)
@@ -207,7 +207,7 @@ def test_get_root_page_for_apphook_with_instance_namespace(self):
def test_get_child_page_for_apphook_with_instance_namespace(self):
with SettingsOverride(ROOT_URLCONF='cms.test_utils.project.second_urls_for_apphook_tests'):
en_title = self.create_base_structure(NS_APP_NAME, 'en', 'instance_ns')
- with ForceLang("en"):
+ with force_language("en"):
path = reverse('namespaced_app_ns:sample-settings')
path_instance1 = reverse('instance_ns:sample-settings')
path_instance2 = reverse('namespaced_app_ns:sample-settings', current_app='instance_ns')
@@ -223,7 +223,7 @@ def test_get_child_page_for_apphook_with_instance_namespace(self):
def test_get_sub_page_for_apphook_with_implicit_current_app(self):
with SettingsOverride(ROOT_URLCONF='cms.test_utils.project.second_urls_for_apphook_tests'):
en_title = self.create_base_structure(NS_APP_NAME, 'en')
- with ForceLang("en"):
+ with force_language("en"):
path = reverse('namespaced_app_ns:current-app')
request = self.get_request(path)
@@ -243,7 +243,7 @@ def test_get_sub_page_for_apphook_with_implicit_current_app(self):
def test_get_sub_page_for_apphook_with_explicit_current_app(self):
with SettingsOverride(ROOT_URLCONF='cms.test_utils.project.second_urls_for_apphook_tests'):
en_title = self.create_base_structure(NS_APP_NAME, 'en', 'instance_ns')
- with ForceLang("en"):
+ with force_language("en"):
path = reverse('namespaced_app_ns:current-app')
request = self.get_request(path)
@@ -275,13 +275,13 @@ def test_include_urlconf(self):
self.assertEquals(response.status_code, 200)
self.assertTemplateUsed(response, 'sampleapp/extra.html')
self.assertContains(response, "test urlconf")
- with ForceLang("de"):
+ with force_language("de"):
path = reverse('extra_first')
response = self.client.get(path)
self.assertEquals(response.status_code, 200)
self.assertTemplateUsed(response, 'sampleapp/extra.html')
self.assertContains(response, "test urlconf")
- with ForceLang("de"):
+ with force_language("de"):
path = reverse('extra_second')
response = self.client.get(path)
self.assertEquals(response.status_code, 200)
@@ -297,7 +297,7 @@ def test_apphook_breaking_under_home_with_new_path_caching(self):
# not-home is what breaks stuff, because it contains the slug of the home page
not_home = create_page("not-home", "nav_playground.html", "en", published=True, parent=child)
create_page("subchild", "nav_playground.html", "en", published=True, parent=not_home, apphook='SampleApp')
- with ForceLang("en"):
+ with force_language("en"):
self.reload_urls()
urlpatterns = get_app_patterns()
resolver = urlpatterns[0]
@@ -341,7 +341,7 @@ def test_page_language_url_for_apphook(self):
child_child_page.publish()
# publisher_public is set to draft on publish, issue with onetoone reverse
child_child_page = self.reload(child_child_page)
- with ForceLang("en"):
+ with force_language("en"):
path = reverse('extra_first')
request = self.get_request(path)
4 cms/tests/menu.py
View
@@ -10,7 +10,7 @@
from cms.test_utils.util.context_managers import (SettingsOverride,
LanguageOverride)
from cms.test_utils.util.mock import AttributeObject
-from cms.utils.i18n import ForceLang
+from cms.utils.i18n import force_language
from django.conf import settings
from django.contrib.auth.models import AnonymousUser, User, Permission, Group
from django.contrib.sites.models import Site
@@ -86,7 +86,7 @@ def test_menu_failfast_on_invalid_usage(self):
def test_basic_cms_menu(self):
self.assertEqual(len(menu_pool.menus), 1)
- with ForceLang("en"):
+ with force_language("en"):
response = self.client.get(self.get_pages_root()) # path = '/'
self.assertEquals(response.status_code, 200)
request = self.get_request()
3  cms/tests/multilingual.py
View
@@ -23,3 +23,6 @@ def test_multilingual_page(self):
self.assertEqual(placeholder.cmsplugin_set.filter(language='de').count(), 1)
self.assertEqual(placeholder.cmsplugin_set.filter(language='en').count(), 1)
+ def test_frontend_lang(self):
+ pass
+
4 cms/tests/nonroot.py
View
@@ -4,7 +4,7 @@
from cms.models import Page
from cms.test_utils.testcases import CMSTestCase
from cms.test_utils.util.context_managers import SettingsOverride
-from cms.utils.i18n import ForceLang
+from cms.utils.i18n import force_language
from django.contrib.auth.models import User
from django.middleware.locale import LocaleMiddleware
from django.template import Template
@@ -82,7 +82,7 @@ def test_form_multilingual_admin(self):
Tests for correct form URL mangling in preview_link templatetag
"""
language = 'en'
- with ForceLang("en"):
+ with force_language("en"):
pages_root = self.get_pages_root()
link = preview_link(self.page2,language=language)
self.assertEqual(link,'%s%s/' % (pages_root,self.page2.get_slug()))
8 cms/tests/permmod.py
View
@@ -10,7 +10,7 @@
from cms.test_utils.testcases import (URL_CMS_PAGE_ADD, URL_CMS_PLUGIN_REMOVE,
SettingsOverrideTestCase, URL_CMS_PLUGIN_ADD, CMSTestCase)
from cms.test_utils.util.context_managers import SettingsOverride
-from cms.utils.i18n import ForceLang
+from cms.utils.i18n import force_language
from cms.utils.page_resolver import get_page_from_path
from cms.utils.permissions import has_generic_permission
@@ -851,19 +851,19 @@ def test_patricks_move(self):
class ModeratorSwitchCommandTest(CMSTestCase):
def test_switch_moderator_on(self):
- with ForceLang("en"):
+ with force_language("en"):
pages_root = urllib.unquote(reverse("pages-root"))
with SettingsOverride(CMS_MODERATOR=False):
page1 = create_page('page', 'nav_playground.html', 'en', published=True)
with SettingsOverride(CMS_MODERATOR=True):
call_command('cms', 'moderator', 'on')
- with ForceLang("en"):
+ with force_language("en"):
path = page1.get_absolute_url()[len(pages_root):].strip('/')
page2 = get_page_from_path(path)
self.assertEqual(page1.get_absolute_url(), page2.get_absolute_url())
def test_switch_moderator_off(self):
- with ForceLang("en"):
+ with force_language("en"):
pages_root = urllib.unquote(reverse("pages-root"))
with SettingsOverride(CMS_MODERATOR=True):
page1 = create_page('page', 'nav_playground.html', 'en', published=True)
2  cms/utils/i18n.py
View
@@ -44,7 +44,7 @@ def get_fallback_languages(language):
-class ForceLang(object):
+class force_language(object):
def __init__(self, new_lang):
self.new_lang = new_lang
self.old_lang = translation.get_language()
4 cms/views.py
View
@@ -3,7 +3,7 @@
from cms.apphook_pool import apphook_pool
from cms.appresolver import get_app_urls
from cms.utils import get_template_from_request, get_language_from_request
-from cms.utils.i18n import get_fallback_languages, ForceLang
+from cms.utils.i18n import get_fallback_languages, force_language
from cms.utils.page_resolver import get_page_from_request
from django.conf import settings
from django.conf.urls.defaults import patterns
@@ -46,7 +46,7 @@ def details(request, slug):
# fallback languages (CMS_LANGUAGE_CONF)
for alt_lang in get_fallback_languages(current_language):
if alt_lang in available_languages:
- with ForceLang(alt_lang):
+ 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
4 menus/templatetags/menu_tags.py
View
@@ -3,7 +3,7 @@
from classytags.arguments import IntegerArgument, Argument, StringArgument
from classytags.core import Options
from classytags.helpers import InclusionTag
-from cms.utils.i18n import ForceLang
+from cms.utils.i18n import force_language
from django import template
from django.conf import settings
from django.contrib.sites.models import Site
@@ -273,7 +273,7 @@ def _raw_language_marker(language, lang_code):
return language
def _native_language_marker(language, lang_code):
- with ForceLang(lang_code):
+ with force_language(lang_code):
return unicode(ugettext(language))
def _current_language_marker(language, lang_code):
4 menus/utils.py
View
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import with_statement
-from cms.utils.i18n import ForceLang
+from cms.utils.i18n import force_language
from django.conf import settings
import warnings
from cms.models.titlemodels import Title
@@ -91,7 +91,7 @@ def __call__(self, lang):
def get_page_path(self, lang):
page = getattr(self.request, 'current_page', None)
if page:
- with ForceLang(lang):
+ with force_language(lang):
try:
return page.get_absolute_url(language=lang, fallback=False)
except Title.DoesNotExist:
Please sign in to comment.
Something went wrong with that request. Please try again.