diff --git a/wagtail/admin/views/pages.py b/wagtail/admin/views/pages.py
index d0eb5aeef6..c30ca7fa3d 100644
--- a/wagtail/admin/views/pages.py
+++ b/wagtail/admin/views/pages.py
@@ -343,12 +343,9 @@ def edit(request, page_id):
edit_handler = edit_handler.bind_to(instance=page, request=request)
form_class = edit_handler.get_form_class()
- user_has_lock = page.locked_by_id == request.user.id
- page_locked = page_perms.page_locked()
-
- if user_has_lock:
+ if page_perms.user_has_lock():
messages.warning(request, format_html(_("Page '{}' was locked by you on {}."), page.get_admin_display_title(), page.locked_at.strftime("%d %b %Y %H:%M")), extra_tags='lock')
- if page_locked:
+ if page_perms.page_locked():
locked_by_message = ""
if page.locked_by:
locked_by_message = format_html(" by {}", str(page.locked_by))
@@ -362,7 +359,7 @@ def edit(request, page_id):
form = form_class(request.POST, request.FILES, instance=page,
parent_page=parent)
- if form.is_valid() and not page_locked:
+ if form.is_valid() and not page_perms.page_locked():
page = form.save(commit=False)
is_publishing = bool(request.POST.get('action-publish')) and page_perms.can_publish()
@@ -506,7 +503,7 @@ def edit(request, page_id):
target_url += '?next=%s' % urlquote(next_url)
return redirect(target_url)
else:
- if page_locked:
+ if page_perms.page_locked():
messages.error(request, _("The page could not be saved as it is locked"))
else:
messages.validation_error(
@@ -556,7 +553,6 @@ def edit(request, page_id):
'form': form,
'next': next_url,
'has_unsaved_changes': has_unsaved_changes,
- 'user_has_lock': user_has_lock,
})
diff --git a/wagtail/core/models.py b/wagtail/core/models.py
index c6e7dafbfd..9cbacb794d 100644
--- a/wagtail/core/models.py
+++ b/wagtail/core/models.py
@@ -1845,6 +1845,9 @@ class PagePermissionTester:
if self.page.path.startswith(perm.page.path)
)
+ def user_has_lock(self):
+ return self.page.locked_by_id == self.user.pk
+
def page_locked(self):
if not self.page.locked:
# Page is not locked
@@ -1855,7 +1858,7 @@ class PagePermissionTester:
return True
else:
# Locked only if the current user was not the one who locked the page
- return self.page.locked_by_id is not self.user.pk
+ return not self.user_has_lock()
def can_add_subpage(self):
if not self.user.is_active: