Skip to content
This repository

make non-public langs visble in frontend for staff #1567

Merged
merged 1 commit into from over 1 year ago

2 participants

pascalmouret Patrick Lauber
pascalmouret

Tests run through, but not sure if there are some other places where code has to be changed.

pascalmouret pascalmouret commented on the diff December 20, 2012
cms/tests/menu.py
@@ -272,7 +272,7 @@ def test_language_chooser(self):
272 272
             context = self.get_context(path=self.get_page(3).get_absolute_url())
273 273
             tpl = Template("{% load menu_tags %}{% language_chooser %}")
274 274
             tpl.render(context)
275  
-            self.assertEqual(len(context['languages']), 3)
  275
+            self.assertEqual(len(context['languages']), 2)
1

since I set a language to public: False

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Patrick Lauber digi604 merged commit 654b666 into from December 20, 2012
Patrick Lauber digi604 closed this December 20, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Dec 20, 2012
make non-public langs visble in frontend for staff 37de352
This page is out of date. Refresh to see the latest.
2  cms/test_utils/cli.py
@@ -128,7 +128,7 @@ def configure(**extra):
128 128
                 {
129 129
                     'code':'pt-br',
130 130
                     'name':gettext('Brazilian Portuguese'),
131  
-                    'public':True,
  131
+                    'public':False,
132 132
                 },
133 133
             ],
134 134
             2: [
2  cms/tests/menu.py
@@ -272,7 +272,7 @@ def test_language_chooser(self):
272 272
             context = self.get_context(path=self.get_page(3).get_absolute_url())
273 273
             tpl = Template("{% load menu_tags %}{% language_chooser %}")
274 274
             tpl.render(context)
275  
-            self.assertEqual(len(context['languages']), 3)
  275
+            self.assertEqual(len(context['languages']), 2)
276 276
             # try a different template and some different args
277 277
             tpl = Template("{% load menu_tags %}{% language_chooser 'menu/test_language_chooser.html' %}")
278 278
             tpl.render(context)
9  cms/tests/multilingual.py
@@ -47,9 +47,11 @@ def test_frontend_lang(self):
47 47
             create_title("de", page2.get_title(), page2, slug=page2.get_slug())
48 48
             page3 = create_page("page2", "nav_playground.html", "en")
49 49
             create_title("de", page3.get_title(), page3, slug=page3.get_slug())
  50
+            page4 = create_page("page4", "nav_playground.html", "de")
50 51
             page.publish()
51 52
             page2.publish()
52 53
             page3.publish()
  54
+            page4.publish()
53 55
             response = self.client.get("/en/")
54 56
             self.assertRedirects(response, "/de/")
55 57
             response = self.client.get("/en/page2/")
@@ -58,6 +60,13 @@ def test_frontend_lang(self):
58 60
             self.assertEqual(response.status_code, 200)
59 61
             response = self.client.get("/de/page2/")
60 62
             self.assertEqual(response.status_code, 200)
  63
+            # check if the admin can see non-public langs
  64
+            admin = self.get_superuser()
  65
+            if self.client.login(username=admin.username, password="admin"):
  66
+                response = self.client.get("/en/page2/")
  67
+                self.assertEqual(response.status_code, 200)
  68
+                response = self.client.get("/en/page4/")
  69
+                self.assertEqual(response.status_code, 302)
61 70
 
62 71
     def test_detail_view_404_when_no_language_is_found(self):
63 72
         page = create_page("page1", "nav_playground.html", "en")
9  cms/views.py
@@ -4,7 +4,7 @@
4 4
 from cms.appresolver import get_app_urls
5 5
 from cms.models import Title
6 6
 from cms.utils import get_template_from_request, get_language_from_request
7  
-from cms.utils.i18n import get_fallback_languages, force_language, get_public_languages, get_redirect_on_fallback
  7
+from cms.utils.i18n import get_fallback_languages, force_language, get_public_languages, get_redirect_on_fallback, get_language_list
8 8
 from cms.utils.page_resolver import get_page_from_request
9 9
 from cms.test_utils.util.context_managers import SettingsOverride
10 10
 from django.conf import settings
@@ -38,7 +38,10 @@ def details(request, slug):
38 38
     # Check that the current page is available in the desired (current) language
39 39
     available_languages = []
40 40
     page_languages = page.get_languages()
41  
-    for frontend_lang in get_public_languages():
  41
+    user_languages = get_public_languages()
  42
+    if hasattr(request, 'user') and request.user.is_staff:
  43
+        user_languages = get_language_list()
  44
+    for frontend_lang in user_languages:
42 45
         if frontend_lang in page_languages:
43 46
             available_languages.append(frontend_lang)
44 47
     attrs = ''
@@ -49,7 +52,7 @@ def details(request, slug):
49 52
         if 'draft' in request.GET:
50 53
             attrs += '&draft=1'
51 54
     # Check that the language is in FRONTEND_LANGUAGES:
52  
-    if not current_language in get_public_languages():
  55
+    if not current_language in user_languages:
53 56
         #are we on root?
54 57
         if not slug:
55 58
             #redirect to supported language
3  menus/templatetags/menu_tags.py
@@ -320,9 +320,10 @@ def get_context(self, context, template, i18n_mode):
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.