Reputation: 3605
I want to get a list of all pages I have published in my Django-CMS application but I can't seem to get it to render the language-specific urls.
in my settings I have specified:
LANGUAGES = [
('sv', 'Svenska'),
('en', 'English'),
]
I go in to the admin site, I create a contact-page (That is not site-home) and set different slugs on different languages, 'contact-sv' and 'contact-en' for instance.
Then I have a view that gets a page
from cms.models import Page
page = Page.objects.published()[1]
print 'swe:', page.get_absolute_url(language='sv')
print 'eng:', page.get_absolute_url(language='en')
I then get This output:
swe: /contact-en/
eng: /contact-en/
When I expected the swe-url to be /sv/contact-sv/
I don't need the langage prefix to the path, I can prepend that to the path but I need the language specific path.
Upvotes: 1
Views: 2702
Reputation: 806
Maybe you could use the sitemap strategy. django cms has it's own sitemap class that runs this code:
class CMSSitemap(Sitemap):
changefreq = "monthly"
priority = 0.5
def items(self):
all_titles = Title.objects.public().filter(
Q(redirect='') | Q(redirect__isnull=True),
page__login_required=False,
page__site=Site.objects.get_current(),
).order_by('page__path')
return all_titles
Upvotes: 0
Reputation: 4781
I can offer you no better solution than to wait for the 2.4 release which will use Django's built-in i18n_urlpatterns to handle this, which should fix the issue you have, for now, your answer is the only way to go.
Upvotes: 2
Reputation: 3605
I bet there is a better way to do it but now I loop through titles on the page object.
for title in page.title_set.all():
print title.language, title.slug
It works, but I do not like it...
Upvotes: 0