Skip to content

Commit 045920f

Browse files
authored
fix: simple history templates refactoring (#482)
1 parent b1b5d2b commit 045920f

File tree

2 files changed

+52
-16
lines changed

2 files changed

+52
-16
lines changed

src/unfold/contrib/simple_history/templates/simple_history/object_history.html

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
{% extends "admin/object_history.html" %}
22

3-
{% load admin_urls i18n %}
4-
{% load url from simple_history_compat %}
5-
{% load display_list from simple_history_admin_list %}
3+
{% load i18n %}
64

75
{% block content %}
86
{% if not revert_disabled %}
@@ -11,8 +9,8 @@
119
</p>
1210
{% endif %}
1311

14-
{% if action_list %}
15-
{% display_list %}
12+
{% if historical_records %}
13+
{% include object_history_list_template %}
1614
{% else %}
1715
<p class="mb-3 px-3 py-3 rounded-md text-sm last:mb-8 bg-amber-100 text-amber-600 dark:bg-amber-600/20 dark:border-amber-600/10">
1816
{% trans "This object doesn't have a change history." %}

src/unfold/contrib/simple_history/templates/simple_history/_object_history_list.html renamed to src/unfold/contrib/simple_history/templates/simple_history/object_history_list.html

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,48 +31,86 @@
3131
<th class="align-middle font-medium px-3 py-2 text-left text-gray-400 text-sm">
3232
{% trans 'Change reason' %}
3333
</th>
34+
35+
<th class="align-middle font-medium px-3 py-2 text-left text-gray-400 text-sm">
36+
{% trans 'Changes' %}
37+
</th>
3438
</tr>
3539
</thead>
3640

3741
<tbody>
38-
{% for action in action_list %}
42+
{% for record in historical_records %}
3943
<tr class="block border mb-3 rounded-md shadow-sm lg:table-row lg:border-none lg:mb-0 lg:shadow-none dark:border-gray-800">
4044
<td class="align-middle flex border-t border-gray-200 font-normal px-3 py-2 text-left text-sm before:flex before:capitalize before:content-[attr(data-label)] before:items-center before:mr-auto before:text-gray-500 first:border-t-0 dark:before:text-gray-400 lg:before:hidden lg:first:border-t lg:py-3 lg:table-cell dark:border-gray-800" data-label="{% trans 'Object' %}">
41-
<a href="{% url opts|admin_urlname:'simple_history' object.pk action.pk %}">
42-
{{ action.history_object }}
45+
<a href="{% url opts|admin_urlname:'simple_history' object.pk record.pk %}">
46+
{{ record.history_object }}
4347
</a>
4448
</td>
4549

4650
{% for column in history_list_display %}
4751
<td class="align-middle flex border-t border-gray-200 font-normal px-3 py-2 text-left text-sm before:flex before:capitalize before:content-[attr(data-label)] before:items-center before:mr-auto before:text-gray-500 first:border-t-0 dark:before:text-gray-400 lg:before:hidden lg:first:border-t lg:py-3 lg:table-cell dark:border-gray-800" data-label="{% trans column %}">
48-
{{ action|getattribute:column }}
52+
{{ record|getattribute:column }}
4953
</th>
5054
{% endfor %}
5155

5256
<td class="align-middle flex border-t border-gray-200 font-normal px-3 py-2 text-left text-sm before:flex before:capitalize before:content-[attr(data-label)] before:items-center before:mr-auto before:text-gray-500 first:border-t-0 dark:before:text-gray-400 lg:before:hidden lg:first:border-t lg:py-3 lg:table-cell dark:border-gray-800" data-label="{% trans 'Date/time' %}">
53-
{{ action.history_date }}
57+
{{ record.history_date }}
5458
</td>
5559

5660
<td class="align-middle flex border-t border-gray-200 font-normal px-3 py-2 text-left text-sm before:flex before:capitalize before:content-[attr(data-label)] before:items-center before:mr-auto before:text-gray-500 first:border-t-0 dark:before:text-gray-400 lg:before:hidden lg:first:border-t lg:py-3 lg:table-cell dark:border-gray-800" data-label="{% trans 'Comment' %}">
57-
{{ action.get_history_type_display }}
61+
{{ record.get_history_type_display }}
5862
</td>
5963

6064
<td class="align-middle flex border-t border-gray-200 font-normal px-3 py-2 text-left text-sm before:flex before:capitalize before:content-[attr(data-label)] before:items-center before:mr-auto before:text-gray-500 first:border-t-0 dark:before:text-gray-400 lg:before:hidden lg:first:border-t lg:py-3 lg:table-cell dark:border-gray-800" data-label="{% trans 'Changed by' %}">
61-
{% if action.history_user %}
62-
{% url admin_user_view action.history_user_id as admin_user_url %}
65+
{% if record.history_user %}
66+
{% url admin_user_view record.history_user_id as admin_user_url %}
6367

6468
{% if admin_user_url %}
65-
<a href="{{ admin_user_url }}">{{ action.history_user }}</a>
69+
<a href="{{ admin_user_url }}">{{ record.history_user }}</a>
6670
{% else %}
67-
{{ action.history_user }}
71+
{{ record.history_user }}
6872
{% endif %}
6973
{% else %}
7074
{% trans "None" %}
7175
{% endif %}
7276
</td>
7377

7478
<td class="align-middle flex border-t border-gray-200 font-normal px-3 py-2 text-left text-sm before:flex before:capitalize before:content-[attr(data-label)] before:items-center before:mr-auto before:text-gray-500 first:border-t-0 dark:before:text-gray-400 lg:before:hidden lg:first:border-t lg:py-3 lg:table-cell dark:border-gray-800" data-label="{% trans 'Change reason' %}">
75-
{{ action.history_change_reason }}
79+
{{ record.history_change_reason }}
80+
</td>
81+
82+
<td class="align-middle flex border-t border-gray-200 font-normal px-3 py-2 text-left text-sm before:flex before:capitalize before:content-[attr(data-label)] before:items-center before:mr-auto before:text-gray-500 first:border-t-0 dark:before:text-gray-400 lg:before:hidden lg:first:border-t lg:py-3 lg:table-cell dark:border-gray-800" data-label="{% trans 'Changes' %}">
83+
{% block history_delta_changes %}
84+
{% if record.history_delta_changes %}
85+
<ul>
86+
{% for change in record.history_delta_changes %}
87+
<li class="flex flex-row gap-2">
88+
<strong class="font-medium text-gray-700 dark:text-gray-200">
89+
{{ change.field }}:
90+
</strong>
91+
92+
<div class="flex flex-row items-center gap-2">
93+
{% if change.old %}
94+
<span>
95+
{{ change.old }}
96+
</span>
97+
{% endif %}
98+
99+
{% if change.old and change.new %}
100+
<span class="align-text-top material-symbols-outlined md-18 text-gray-300 group-hover:text-gray-400 dark:text-gray-600">arrow_right_alt</span>
101+
{% endif %}
102+
103+
{% if change.new %}
104+
<span>
105+
{{ change.new }}
106+
</span>
107+
{% endif %}
108+
</div>
109+
</li>
110+
{% endfor %}
111+
</ul>
112+
{% endif %}
113+
{% endblock %}
76114
</td>
77115
</tr>
78116
{% endfor %}

0 commit comments

Comments
 (0)