kopia lustrzana https://github.com/wagtail/wagtail
Split EditView.post into form_valid and form_invalid methods
rodzic
badab7b059
commit
74e6c497e1
|
@ -173,12 +173,15 @@ class EditView(TemplateResponseMixin, ContextMixin, View):
|
|||
self.request.POST, self.request.FILES, instance=self.page, parent_page=self.parent
|
||||
)
|
||||
|
||||
is_valid = self.form.is_valid() and not self.page_perms.page_locked()
|
||||
self.is_cancelling_workflow = bool(self.request.POST.get('action-cancel-workflow')) and self.workflow_state and self.workflow_state.user_can_cancel(self.request.user)
|
||||
|
||||
is_cancelling_workflow = bool(self.request.POST.get('action-cancel-workflow')) and self.workflow_state and self.workflow_state.user_can_cancel(self.request.user)
|
||||
if self.form.is_valid() and not self.page_perms.page_locked():
|
||||
return self.form_valid(self.form)
|
||||
else:
|
||||
return self.form_invalid(self.form)
|
||||
|
||||
if is_valid:
|
||||
if is_cancelling_workflow:
|
||||
def form_valid(self, form):
|
||||
if self.is_cancelling_workflow:
|
||||
self.workflow_state.cancel(user=self.request.user)
|
||||
|
||||
self.page = self.form.save(commit=False)
|
||||
|
@ -336,7 +339,7 @@ class EditView(TemplateResponseMixin, ContextMixin, View):
|
|||
)
|
||||
])
|
||||
|
||||
elif is_cancelling_workflow:
|
||||
elif self.is_cancelling_workflow:
|
||||
self.add_cancel_workflow_confirmation_message()
|
||||
|
||||
elif is_restarting_workflow:
|
||||
|
@ -396,9 +399,10 @@ class EditView(TemplateResponseMixin, ContextMixin, View):
|
|||
# Ensure the 'next' url is passed through again if present
|
||||
target_url += '?next=%s' % urlquote(self.next_url)
|
||||
return redirect(target_url)
|
||||
else:
|
||||
|
||||
def form_invalid(self, form):
|
||||
# even if the page is locked due to not having permissions, the original submitter can still cancel the workflow
|
||||
if is_cancelling_workflow:
|
||||
if self.is_cancelling_workflow:
|
||||
self.workflow_state.cancel(user=self.request.user)
|
||||
self.add_cancel_workflow_confirmation_message()
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue