Add last-updated row to modeladmin edit page header

pull/7571/head
Matt Westcott 2021-09-30 18:59:30 +01:00
rodzic 57f150522d
commit cc416215b6
5 zmienionych plików z 55 dodań i 0 usunięć
wagtail/contrib/modeladmin

Wyświetl plik

@ -21,6 +21,19 @@
{{ view.media.js }}
{% prepopulated_slugs %}
<script>
$(function() {
$('[data-wagtail-tooltip]').tooltip({
animation: false,
title: function() {
return $(this).attr('data-wagtail-tooltip');
},
trigger: 'hover',
placement: 'bottom',
});
})
</script>
{% endblock %}
{% block content %}

Wyświetl plik

@ -1,6 +1,10 @@
{% extends "modeladmin/create.html" %}
{% load i18n wagtailadmin_tags %}
{% block header %}
{% include "modeladmin/includes/header_with_history.html" with title=view.get_page_title subtitle=view.get_page_subtitle icon=view.header_icon tabbed=1 merged=1 latest_log_entry=latest_log_entry history_url=history_url %}
{% endblock %}
{% block form_action %}{{ view.edit_url }}{% endblock %}
{% block form_actions %}

Wyświetl plik

@ -0,0 +1,19 @@
{% extends "wagtailadmin/shared/header_with_locale_selector.html" %}
{% load wagtailadmin_tags i18n %}
{% block extra_rows %}
<div class="row last-updated">
{% if latest_log_entry %}
<ul>
<li>
<span class="avatar small" data-wagtail-tooltip="{{ latest_log_entry.user_display_name }}"><img src="{% avatar_url latest_log_entry.user size=25 %}" alt="" /></span>
{% trans "Last updated" %}
{% include "wagtailadmin/shared/last_updated.html" with last_updated=latest_log_entry.timestamp time_prefix="at" %}
</li>
{% if history_url %}
<li><a href="{{ history_url }}">{% icon "history" class_name="default" %} {% trans "History" %}</a></li>
{% endif %}
</ul>
{% endif %}
</div>
{% endblock %}

Wyświetl plik

@ -381,6 +381,13 @@ class TestEditView(TestCase, WagtailTestUtils):
def setUp(self):
self.user = self.login()
ModelLogEntry.objects.create(
content_type=ContentType.objects.get_for_model(Book),
label="The Lord of the Rings",
action='wagtail.create',
timestamp=make_aware(datetime.datetime(2021, 9, 30, 10, 1, 0)),
object_id='1',
)
def get(self, book_id):
return self.client.get('/admin/modeladmintest/book/edit/%d/' % book_id)
@ -394,6 +401,11 @@ class TestEditView(TestCase, WagtailTestUtils):
self.assertEqual(response.status_code, 200)
self.assertContains(response, 'The Lord of the Rings')
# "Last updated" timestamp should be present
self.assertContains(response, 'data-wagtail-tooltip="Sept. 30, 2021, 10:01 a.m."')
# History link should be present
self.assertContains(response, 'href="/admin/modeladmintest/book/history/1/"')
url_finder = AdminURLFinder(self.user)
expected_url = '/admin/modeladmintest/book/edit/1/'
self.assertEqual(url_finder.get_edit_url(Book.objects.get(id=1)), expected_url)

Wyświetl plik

@ -720,6 +720,13 @@ class EditView(ModelFormView, InstanceSpecificView):
self.request.user, self.instance)
}
context.update(kwargs)
if self.model_admin.history_view_enabled:
context['latest_log_entry'] = log_registry.get_logs_for_instance(self.instance).first()
context['history_url'] = self.url_helper.get_action_url('history', quote(self.instance.pk))
else:
context['latest_log_entry'] = None
context['history_url'] = None
return super().get_context_data(**context)
def get_error_message(self):