Skip to content

Commit

Permalink
force_language rename
Browse files Browse the repository at this point in the history
  • Loading branch information
digi604 committed Sep 26, 2012
1 parent bddbad1 commit 5806d99
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 29 deletions.
4 changes: 2 additions & 2 deletions cms/appresolver.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
24 changes: 12 additions & 12 deletions cms/tests/apphooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')

Expand Down Expand Up @@ -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'
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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')
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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]
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions cms/tests/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
3 changes: 3 additions & 0 deletions cms/tests/multilingual.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 2 additions & 2 deletions cms/tests/nonroot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()))
Expand Down
8 changes: 4 additions & 4 deletions cms/tests/permmod.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion cms/utils/i18n.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions cms/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions menus/templatetags/menu_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions menus/utils.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 5806d99

Please sign in to comment.