Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

make non-public langs visble in frontend for staff

  • Loading branch information...
commit 37de352ea7d7720d551a020f9a86599affcefaa6 1 parent 36f7c76
Pascal Mouret authored
View
2  cms/test_utils/cli.py
@@ -128,7 +128,7 @@ def configure(**extra):
{
'code':'pt-br',
'name':gettext('Brazilian Portuguese'),
- 'public':True,
+ 'public':False,
},
],
2: [
View
2  cms/tests/menu.py
@@ -272,7 +272,7 @@ def test_language_chooser(self):
context = self.get_context(path=self.get_page(3).get_absolute_url())
tpl = Template("{% load menu_tags %}{% language_chooser %}")
tpl.render(context)
- self.assertEqual(len(context['languages']), 3)
+ self.assertEqual(len(context['languages']), 2)
# try a different template and some different args
tpl = Template("{% load menu_tags %}{% language_chooser 'menu/test_language_chooser.html' %}")
tpl.render(context)
View
9 cms/tests/multilingual.py
@@ -47,9 +47,11 @@ def test_frontend_lang(self):
create_title("de", page2.get_title(), page2, slug=page2.get_slug())
page3 = create_page("page2", "nav_playground.html", "en")
create_title("de", page3.get_title(), page3, slug=page3.get_slug())
+ page4 = create_page("page4", "nav_playground.html", "de")
page.publish()
page2.publish()
page3.publish()
+ page4.publish()
response = self.client.get("/en/")
self.assertRedirects(response, "/de/")
response = self.client.get("/en/page2/")
@@ -58,6 +60,13 @@ def test_frontend_lang(self):
self.assertEqual(response.status_code, 200)
response = self.client.get("/de/page2/")
self.assertEqual(response.status_code, 200)
+ # check if the admin can see non-public langs
+ admin = self.get_superuser()
+ if self.client.login(username=admin.username, password="admin"):
+ response = self.client.get("/en/page2/")
+ self.assertEqual(response.status_code, 200)
+ response = self.client.get("/en/page4/")
+ self.assertEqual(response.status_code, 302)
def test_detail_view_404_when_no_language_is_found(self):
page = create_page("page1", "nav_playground.html", "en")
View
9 cms/views.py
@@ -4,7 +4,7 @@
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, get_redirect_on_fallback
+from cms.utils.i18n import get_fallback_languages, force_language, get_public_languages, get_redirect_on_fallback, get_language_list
from cms.utils.page_resolver import get_page_from_request
from cms.test_utils.util.context_managers import SettingsOverride
from django.conf import settings
@@ -38,7 +38,10 @@ def details(request, slug):
# Check that the current page is available in the desired (current) language
available_languages = []
page_languages = page.get_languages()
- for frontend_lang in get_public_languages():
+ user_languages = get_public_languages()
+ if hasattr(request, 'user') and request.user.is_staff:
+ user_languages = get_language_list()
+ for frontend_lang in user_languages:
if frontend_lang in page_languages:
available_languages.append(frontend_lang)
attrs = ''
@@ -49,7 +52,7 @@ def details(request, slug):
if 'draft' in request.GET:
attrs += '&draft=1'
# Check that the language is in FRONTEND_LANGUAGES:
- if not current_language in get_public_languages():
+ if not current_language in user_languages:
#are we on root?
if not slug:
#redirect to supported language
View
3  menus/templatetags/menu_tags.py
@@ -320,9 +320,10 @@ def get_context(self, context, template, i18n_mode):
marker = MARKERS[i18n_mode]
current_lang = get_language()
site = Site.objects.get_current()
+ user_is_staff = context['request'].user.is_staff
languages = []
for lang in get_language_objects(site.pk):
- if lang.get('public', True):
+ if user_is_staff or lang.get('public', True):
languages.append((lang['code'], marker(lang['name'], lang['code'])))
context.update({
'languages':languages,
Please sign in to comment.
Something went wrong with that request. Please try again.