8000 Fixed #6245 -- Sitemap should only show public languages (#6247) · django-cms/django-cms@4d720a3 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 4d720a3

Browse files
authored
Fixed #6245 -- Sitemap should only show public languages (#6247)
1 parent 52d3194 commit 4d720a3

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

cms/sitemaps/cms_sitemap.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from cms.models import Title
88
from cms.utils import get_current_site
9+
from cms.utils.i18n import get_public_languages
910

1011

1112
def from_iterable(iterables):
@@ -45,10 +46,13 @@ def items(self):
4546
# If, for some reason, you require redirecting pages (Titles) to be
4647
# included, simply create a new class inheriting from this one, and
4748
# supply a new items() method which doesn't filter out the redirects.
49+
site = get_current_site()
50+
languages = get_public_languages(site_id=site.pk)
4851
all_titles = Title.objects.public().filter(
4952
Q(redirect='') | Q(redirect__isnull=True),
53+
language__in=languages,
5054
page__login_required=False,
51-
page__node__site=get_current_site(),
55+
page__node__site=site,
5256
).order_by('page__node__path')
5357
return all_titles
5458

cms/tests/test_sitemap.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
# -*- coding: utf-8 -*-
2+
import copy
3+
4+
from cms.api import create_page, create_title
25
from cms.models import Title, Page
36
from cms.sitemaps import CMSSitemap
47
from cms.test_utils.testcases import CMSTestCase
5-
from cms.api import create_page, create_title
8+
from cms.utils.conf import get_cms_setting
69

710

811
class SitemapTestCase(CMSTestCase):
@@ -144,3 +147,21 @@ def test_sitemap_unpublished_titles(self):
144147
else:
145148
url = 'http://example.com/%s/%s' % (title.language, title.path)
146149
self.assertFalse(url in locations)
150+
151+
def test_sitemap_uses_public_languages_only(self):
152+
"""
153+
Pages on the sitemap should only show public languages.
154+
"""
155+
lang_settings = copy.deepcopy(get_cms_setting('LANGUAGES'))
156+
# sanity check
157+
assert lang_settings[1][1]['code'] == 'de'
158+
# set german as private
159+
lang_settings[1][1]['public'] = False
160+
161+
with self.settings(CMS_LANGUAGES=lang_settings):
162+
for item in CMSSitemap().get_urls():
163+
url = 'http://example.com/en/'
164+
165+
if item['item'].path:
166+
url += item['item'].path + '/'
167+
self.assertEqual(item['location'], url)

0 commit comments

Comments
 (0)
0