8000 Fixed #6144 -- Always append slug prefix when using existing slug in wizard by czpython · Pull Request #6145 · django-cms/django-cms · GitHub
[go: up one dir, main page]

Skip to content

Fixed #6144 -- Always append slug prefix when using existing slug in wizard #6145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions cms/tests/test_wizards.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,31 @@ def test_create_page_with_existing_slug(self):
self.assertTrue(form.is_valid())
self.assertTrue(form.save().title_set.filter(slug='page-3'))

# Now explicitly request the page-2 slug
data['slug'] = 'page-2'

# slug -> page-2-2
form = CreateCMSPageForm(
data=data,
wizard_page=None,
wizard_user=superuser,
wizard_language='en',
wizard_page_node=None,
)
self.assertTrue(form.is_valid())
self.assertTrue(form.save().title_set.filter(slug='page-2-2'))

# slug -> page-2-3
form = CreateCMSPageForm(
data=data,
wizard_page=None,
wizard_user=superuser,
wizard_language='en',
wizard_page_node=None,
)
self.assertTrue(form.is_valid())
self.assertTrue(form.save().title_set.filter(slug='page-2-3'))


# This entire test class can be removed in 3.5.0
class TestWizardSettings(CMSTestCase):
Expand Down
8 changes: 4 additions & 4 deletions cms/utils/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,24 +190,24 @@ def get_all_pages_from_path(site, path, language):
return pages.filter(title_set__language=language)


def get_available_slug(site, path, language, suffix='copy'):
def get_available_slug(site, path, language, suffix='copy', modified=False):
"""
Generates slug for path.
If path is used, appends the value of APPEND_TO_SLUG to the end.
If path is used, appends the value of suffix to the end.
"""
base, _, slug = path.rpartition('/')
pages = get_all_pages_from_path(site, path, language)

if pages.exists():
match = SUFFIX_REGEX.match(slug)

if match:
if match and modified:
_next = int(match.groups()[-1]) + 1
slug = SUFFIX_REGEX.sub('\g<1>-{}'.format(_next), slug)
elif suffix:
slug += suffix + '-2'
else:
slug += '-2'
path = '%s/%s' % (base, slug) if base else slug
return get_available_slug(site, path, language, suffix=suffix)
return get_available_slug(site, path, language, suffix, modified=True)
return slug
0