Skip to content

Commit

Permalink
Changes the way we resolve the page object using the path due to reso…
Browse files Browse the repository at this point in the history
…lve() inconsistency (django-cms#2)
  • Loading branch information
corentin-cres authored and Ianaré Sévi committed Mar 7, 2019
1 parent 2d0fc75 commit 3b73bb6
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions cms/admin/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,19 @@ def save(self, *args, **kwargs):
for lang in source.get_languages():
source._copy_contents(new_page, lang)
elif canonical_url:
# Retrieve the targeted page
from django.urls import resolve
page_metadata = resolve(canonical_url)
# Remove language from the URL
from django.conf import settings
for lang in settings.LANGUAGES:
if canonical_url.startswith('/{}/'.format(lang[0])):
length = len(lang[0]) + 2 # + '/'*2
canonical_url = canonical_url[length:]
break
# Remove the trailing '/'
canonical_url = canonical_url.rstrip('/')

# Retrieve the targeted page object
canonical_page = Page.objects.get(
title_set__path=page_metadata.kwargs['slug'],
title_set__path=canonical_url,
publisher_is_draft=False,
title_set__language=self._language
)
Expand Down

0 comments on commit 3b73bb6

Please sign in to comment.