0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-11-29 17:36:49 +01:00

Fixed crashes when Page.locked_at is None

This commit is contained in:
Karl Hobley 2019-11-26 16:20:05 +00:00
parent 5f68627950
commit c2318b48e6

View File

@ -344,12 +344,21 @@ def edit(request, page_id):
form_class = edit_handler.get_form_class()
if page_perms.user_has_lock():
messages.warning(request, format_html(_("<b>Page '{}' was locked</b> by <b>you</b> on <b>{}</b>."), page.get_admin_display_title(), page.locked_at.strftime("%d %b %Y %H:%M")), extra_tags='lock')
if page_perms.page_locked():
locked_by_message = ""
if page.locked_by:
locked_by_message = format_html(" by <b>{}</b>", str(page.locked_by))
messages.error(request, format_html(_("<b>Page '{}' was locked</b>{} on <b>{}</b>."), page.get_admin_display_title(), locked_by_message, page.locked_at.strftime("%d %b %Y %H:%M")), extra_tags='lock')
if page.locked_at:
lock_message = format_html(_("<b>Page '{}' was locked</b> by <b>you</b> on <b>{}</b>."), page.get_admin_display_title(), page.locked_at.strftime("%d %b %Y %H:%M"))
else:
lock_message = format_html(_("<b>Page '{}' is locked</b> by <b>you</b>."), page.get_admin_display_title())
messages.warning(request, lock_message, extra_tags='lock')
elif page_perms.page_locked():
if page.locked_by and page.locked_at:
lock_message = format_html(_("<b>Page '{}' was locked</b> by <b>{}</b> on <b>{}</b>."), page.get_admin_display_title(), str(page.locked_by), page.locked_at.strftime("%d %b %Y %H:%M"))
else:
# Page was probably locked with an old version of Wagtail, or a script
lock_message = format_html(_("<b>Page '{}' is locked</b>."), page.get_admin_display_title())
messages.error(request, lock_message, extra_tags='lock')
next_url = get_valid_next_url_from_request(request)