0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-11-28 08:48:04 +01:00

Add check for slug when editing page (fixes #119)

This commit is contained in:
Serafeim Papastefanos 2014-04-03 18:15:02 +03:00
parent 420c1a84b7
commit a1c9224b7a

View File

@ -217,6 +217,8 @@ def create(request, content_type_app_name, content_type_model_name, parent_page_
def edit(request, page_id):
latest_revision = get_object_or_404(Page, id=page_id).get_latest_revision()
page = get_object_or_404(Page, id=page_id).get_latest_revision_as_page()
parent = page.get_parent()
page_perms = page.permissions_for_user(request.user)
if not page_perms.can_edit():
raise PermissionDenied
@ -229,6 +231,14 @@ def edit(request, page_id):
if request.POST:
form = form_class(request.POST, request.FILES, instance=page)
# Stick an extra validator into the form to make sure that the slug is not already in use
def clean_slug(slug):
# Make sure the slug isn't already in use
if parent.get_children().filter(slug=slug).count() > 0:
raise ValidationError(_("This slug is already in use"))
return slug
form.fields['slug'].clean = clean_slug
if form.is_valid():
is_publishing = bool(request.POST.get('action-publish')) and page_perms.can_publish()
is_submitting = bool(request.POST.get('action-submit'))