Permalink
Browse files

changes from @ojii comments and docs

  • Loading branch information...
1 parent e1f224b commit fb14f0fa8ae58e87c55f62dd92aeff97bc9e883a @digi604 digi604 committed Sep 25, 2012
View
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
from cms.apphook_pool import apphook_pool
-from cms.utils.i18n import force_lang
+from cms.utils.i18n import ForceLang
from cms.utils.moderator import get_page_queryset
from django.conf import settings
@@ -203,7 +203,7 @@ def get_app_patterns():
app_ns = app.app_name, inst_ns
else:
app_ns = None, None
- with force_lang(title.language):
+ with ForceLang(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
View
@@ -64,7 +64,7 @@ def __init__(self, request):
def init(self):
self.is_staff = self.request.user.is_staff
- self.can_change = (self.request.current_page and
+ self.can_change = (hasattr(self.request.current_page, 'has_change_permission') and
self.request.current_page.has_change_permission(self.request))
self.edit_mode_switcher = Switcher(LEFT, 'editmode', 'edit', 'edit-off',
_('Edit mode'))
@@ -1,11 +1,12 @@
# -*- coding: utf-8 -*-
-from django.utils.translation import activate
-
+from distutils.version import LooseVersion
+import django
import os
gettext = lambda s: s
urlpatterns = []
+DJANGO_1_3 = LooseVersion(django.get_version()) < LooseVersion('1.4')
def configure(**extra):
from django.conf import settings
@@ -187,9 +188,7 @@ def configure(**extra):
'django.contrib.auth.hashers.MD5PasswordHasher',
)
)
- import django
- version = django.get_version()
- if version[:3] == "1.3":
+ if DJANGO_1_3:
defaults['INSTALLED_APPS'].append("i18nurls")
defaults['MIDDLEWARE_CLASSES'][4] = 'i18nurls.middleware.LocaleMiddleware'
else:
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 force_lang
+from cms.utils.i18n import ForceLang
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 force_lang("en"):
+ with ForceLang("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 force_lang("en"):
+ with ForceLang("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 force_lang("de"):
+ with ForceLang("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 force_lang("en"):
+ with ForceLang("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 force_lang("en"):
+ with ForceLang("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 force_lang("en"):
+ with ForceLang("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 force_lang("en"):
+ with ForceLang("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 force_lang("de"):
+ with ForceLang("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 force_lang("de"):
+ with ForceLang("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 force_lang("en"):
+ with ForceLang("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 force_lang("en"):
+ with ForceLang("en"):
path = reverse('extra_first')
request = self.get_request(path)
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 force_lang
+from cms.utils.i18n import ForceLang
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 force_lang("en"):
+ with ForceLang("en"):
response = self.client.get(self.get_pages_root()) # path = '/'
self.assertEquals(response.status_code, 200)
request = self.get_request()
@@ -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 force_lang
+from cms.utils.i18n import ForceLang
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 force_lang("en"):
+ with ForceLang("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()))
@@ -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 force_lang
+from cms.utils.i18n import ForceLang
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 force_lang("en"):
+ with ForceLang("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 force_lang("en"):
+ with ForceLang("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 force_lang("en"):
+ with ForceLang("en"):
pages_root = urllib.unquote(reverse("pages-root"))
with SettingsOverride(CMS_MODERATOR=True):
page1 = create_page('page', 'nav_playground.html', 'en', published=True)
View
@@ -44,7 +44,7 @@ def get_fallback_languages(language):
-class force_lang:
+class ForceLang(object):
def __init__(self, new_lang):
self.new_lang = new_lang
self.old_lang = translation.get_language()
View
@@ -2,7 +2,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, force_lang
+from cms.utils.i18n import get_fallback_languages, ForceLang
from cms.utils.page_resolver import get_page_from_request
from django.conf import settings
from django.conf.urls.defaults import patterns
@@ -45,7 +45,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 force_lang(alt_lang):
+ with ForceLang(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
@@ -53,14 +53,13 @@ What you need to do:
Before ::
- {% url "de:myview" %}
+ {% url "de:myview" %}
After::
- {% load i18n %}
- {% language "de" %}
- {% url "myview_name" %}
- {% endlanguage %}
+ {% load i18n %}{% language "de" %}
+ {% url "myview_name" %}
+ {% endlanguage %}
- reverse urls now return the language prefix as well. So maybe there is some code that adds language prefixes. Remove
this code.
@@ -1,3 +1,5 @@
+from classytags.arguments import Argument
+from classytags.core import Tag, Options
from django import template
register = template.Library()
@@ -9,3 +11,4 @@ def language(parser, token):
except ImportError:
from i18nurls.templatetags.i18nurls import language
return language(parser, token)
+
@@ -4,7 +4,7 @@
from classytags.helpers import InclusionTag
from cms.models.pagemodel import Page
from cms.models.titlemodels import Title
-from cms.utils.i18n import force_lang
+from cms.utils.i18n import ForceLang
from django import template
from django.conf import settings
from django.contrib.sites.models import Site
@@ -278,7 +278,7 @@ def _raw_language_marker(language, lang_code):
return language
def _native_language_marker(language, lang_code):
- with force_lang(lang_code):
+ with ForceLang(lang_code):
return unicode(ugettext(language))
def _current_language_marker(language, lang_code):
View
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
-from cms.utils.i18n import force_lang
+from cms.utils.i18n import ForceLang
from django.conf import settings
import warnings
@@ -91,7 +91,7 @@ def __call__(self, lang):
def get_page_path(self, lang):
page = getattr(self.request, 'current_page', None)
if page:
- with force_lang(lang):
+ with ForceLang(lang):
try:
return page.get_absolute_url(language=lang, fallback=False)
except Title.DoesNotExist:

0 comments on commit fb14f0f

Please sign in to comment.