Split EditView into get and create methods

pull/6331/head
Matt Westcott 2020-08-07 09:50:45 +01:00 zatwierdzone przez Matt Westcott
rodzic 8795ec94f6
commit bca74c41e2
1 zmienionych plików z 303 dodań i 294 usunięć

Wyświetl plik

@ -87,7 +87,9 @@ class EditView(TemplateResponseMixin, ContextMixin, View):
self.errors_debug = None self.errors_debug = None
if self.request.method == 'GET': return super().dispatch(request)
def get(self, request):
if self.page_perms.user_has_lock(): if self.page_perms.user_has_lock():
if self.page.locked_at: if self.page.locked_at:
lock_message = format_html(_("<b>Page '{}' was locked</b> by <b>you</b> on <b>{}</b>."), self.page.get_admin_display_title(), self.page.locked_at.strftime("%d %b %Y %H:%M")) lock_message = format_html(_("<b>Page '{}' was locked</b> by <b>you</b> on <b>{}</b>."), self.page.get_admin_display_title(), self.page.locked_at.strftime("%d %b %Y %H:%M"))
@ -134,10 +136,20 @@ class EditView(TemplateResponseMixin, ContextMixin, View):
_("This page is awaiting <b>'{}'</b> in the <b>'{}'</b> workflow."), _("This page is awaiting <b>'{}'</b> in the <b>'{}'</b> workflow."),
task.name, workflow.name task.name, workflow.name
) )
messages.error(self.request, mark_safe(workflow_info + " " + _("Only reviewers for this task can edit the page.")), messages.error(
extra_tags="lock") self.request, mark_safe(workflow_info + " " + _("Only reviewers for this task can edit the page.")),
extra_tags="lock"
)
if self.request.method == 'POST': self.form = self.form_class(instance=self.page, parent_page=self.parent)
self.has_unsaved_changes = False
self.edit_handler = self.edit_handler.bind_to(form=self.form)
self.add_legacy_moderation_warning()
self.page_for_status = self.get_page_for_status()
return self.render_to_response(self.get_context_data())
def post(self, request):
self.form = self.form_class( self.form = self.form_class(
self.request.POST, self.request.FILES, instance=self.page, parent_page=self.parent self.request.POST, self.request.FILES, instance=self.page, parent_page=self.parent
) )
@ -402,9 +414,6 @@ class EditView(TemplateResponseMixin, ContextMixin, View):
]) ])
) )
self.has_unsaved_changes = True self.has_unsaved_changes = True
else:
self.form = self.form_class(instance=self.page, parent_page=self.parent)
self.has_unsaved_changes = False
self.edit_handler = self.edit_handler.bind_to(form=self.form) self.edit_handler = self.edit_handler.bind_to(form=self.form)
self.add_legacy_moderation_warning() self.add_legacy_moderation_warning()