Apply full_clean on save_revision and preview

This requires us to set fake (but realistic) values for 'path' and 'depth' during preview_on_create
in order to pass validation.
pull/2280/merge
Matt Westcott 2016-02-25 10:18:54 +02:00
rodzic 8efb7bd231
commit 96f7944c6e
2 zmienionych plików z 13 dodań i 0 usunięć

Wyświetl plik

@ -388,6 +388,7 @@ def preview_on_edit(request, page_id):
if form.is_valid():
form.save(commit=False)
page.full_clean()
preview_mode = request.GET.get('mode', page.default_preview_mode)
response = page.serve_preview(page.dummy_request(), preview_mode)
@ -426,9 +427,19 @@ def preview_on_create(request, content_type_app_name, content_type_model_name, p
if form.is_valid():
form.save(commit=False)
# We need to populate treebeard's path / depth fields in order to pass validation.
# We can't make these 100% consistent with the rest of the tree without making actual
# database changes (such as incrementing the parent's numchild field), but by
# calling treebeard's internal _get_path method, we can set a 'realistic' value that
# will hopefully enable tree traversal operations to at least partially work.
page.depth = parent_page.depth + 1
page.path = page._get_path(parent_page.path, page.depth, parent_page.numchild + 1)
# ensure that our unsaved page instance has a suitable url set
page.set_url_path(parent_page)
page.full_clean()
# Set treebeard attributes
page.depth = parent_page.depth + 1
page.path = Page._get_children_path_interval(parent_page.path)[1]

Wyświetl plik

@ -604,6 +604,8 @@ class Page(six.with_metaclass(PageBase, MP_Node, ClusterableModel, index.Indexed
raise Http404
def save_revision(self, user=None, submitted_for_moderation=False, approved_go_live_at=None, changed=True):
self.full_clean()
# Create revision
revision = self.revisions.create(
content_json=self.to_json(),