-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/ucd 36 custom application history page #279
Changes from 1 commit
987552d
0fb068a
991435d
9e6776b
f94ad84
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Generated by Django 4.2.13 on 2024-09-09 14:08 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("request", "0019_historicalregistrypublishedperson_and_more"), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveField( | ||
model_name="historicalregistrantperson", | ||
name="history_user", | ||
), | ||
migrations.RemoveField( | ||
model_name="historicalregistrarperson", | ||
name="history_user", | ||
), | ||
migrations.RemoveField( | ||
model_name="historicalregistrarperson", | ||
name="registrar", | ||
), | ||
migrations.RemoveField( | ||
model_name="historicalregistrypublishedperson", | ||
name="history_user", | ||
), | ||
migrations.DeleteModel( | ||
name="HistoricalRegistrant", | ||
), | ||
migrations.DeleteModel( | ||
name="HistoricalRegistrantPerson", | ||
), | ||
migrations.DeleteModel( | ||
name="HistoricalRegistrarPerson", | ||
), | ||
migrations.DeleteModel( | ||
name="HistoricalRegistryPublishedPerson", | ||
), | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
{% load i18n %} | ||
{% load url from simple_history_compat %} | ||
{% load admin_urls %} | ||
{% load getattribute from getattributes %} | ||
{% load admin_tags %} | ||
<style> | ||
.full_width { | ||
width: 100%; | ||
align-items: center; | ||
} | ||
|
||
h2 { | ||
margin-top: 2%; | ||
} | ||
</style> | ||
<table id="change-history" class="table table-bordered table-striped full_width"> | ||
<thead> | ||
<tr> | ||
<th scope="col">{% trans 'Date/time' %}</th> | ||
<th scope="col">{% trans 'User' %}</th> | ||
<th scope="col">{% trans 'Status' %}</th> | ||
|
||
</tr> | ||
</thead> | ||
<tbody> | ||
{% with filtered_actions=action_list %} | ||
{% for action in filtered_actions %} | ||
{% should_display action as should_display %} | ||
{% if should_display %} | ||
<tr> | ||
<td> | ||
<a href="{% url opts|admin_urlname:'simple_history' object.pk action.pk %}">{{ action.history_date }}</a> | ||
</td> | ||
<td> | ||
{% if action.history_object.last_updated_by %} | ||
{% url admin_user_view action.history_object.last_updated_by.id as admin_user_url %} | ||
{% if admin_user_url %} | ||
<a href="{{ admin_user_url }}">{{ action.history_object | owner_filter }}</a> | ||
{% else %} | ||
{{ action.history_object.last_updated_by }} | ||
{% endif %} | ||
{% else %} | ||
{% trans "-" %} | ||
{% endif %} | ||
</td> | ||
<td> | ||
{{ action.history_object.status | capfirst }} | ||
</td> | ||
</tr> | ||
{% endif %} | ||
{% endfor %} | ||
{% endwith %} | ||
</tbody> | ||
</table> | ||
|
||
<h2>Full event history</h2> | ||
<table id="change-history" class="table table-bordered table-striped full_width"> | ||
<thead> | ||
<tr> | ||
<th scope="col">{% trans 'Date/time' %}</th> | ||
<th scope="col">{% trans 'Event' %}</th> | ||
<th scope="col">{% trans 'Changed by' %}</th> | ||
<th scope="col">{% trans 'Change fields' %}</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{% for action in action_list %} | ||
<tr> | ||
<td> | ||
<a href="{% url opts|admin_urlname:'simple_history' object.pk action.pk %}">{{ action.history_date }}</a> | ||
</td> | ||
<td>{{ action.get_history_type_display }}</td> | ||
<td> | ||
{% if action.history_object.last_updated_by %} | ||
{% url admin_user_view action.history_object.last_updated_by.id as admin_user_url %} | ||
{% if admin_user_url %} | ||
<a href="{{ admin_user_url }}">{{ action.history_object.last_updated_by }}</a> | ||
{% else %} | ||
{{ action.history_object.last_updated_by }} | ||
{% endif %} | ||
{% else %} | ||
{% trans "-" %} | ||
{% endif %} | ||
</td> | ||
<td> | ||
<i>{{ action | changed_fields }}</i> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why |
||
</td> | ||
</tr> | ||
{% endfor %} | ||
</tbody> | ||
</table> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{% extends "admin/object_history.html" %} | ||
{% load i18n %} | ||
{% load url from simple_history_compat %} | ||
{% load admin_urls %} | ||
{% load display_list from simple_history_admin_list %} | ||
|
||
{% block content %} | ||
<div id="content-main"> | ||
<h2>{% blocktrans %} Status change history{% endblocktrans %}</h2> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why |
||
<div class="govuk-table"> | ||
{% if action_list %} | ||
{% display_list %} | ||
{% else %} | ||
<p>{% trans "This object doesn't have a change history." %}</p> | ||
{% endif %} | ||
</div> | ||
</div> | ||
{% endblock %} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
from django import template | ||
|
||
register = template.Library() | ||
|
||
|
||
@register.filter(is_safe=True) | ||
def changed_fields(obj): | ||
""" | ||
Function to derive the changed fields from an object. | ||
If none of the fields are changed and still, there is a history object, then it suggests | ||
that the application was saved while updating the review. | ||
:param obj: | ||
:return: | ||
""" | ||
if obj.prev_record: | ||
delta = obj.diff_against(obj.prev_record) | ||
changes = list(filter(lambda x: x != "last_updated_by", delta.changed_fields)) | ||
return changes if changes else "Updated through review" | ||
return "-" | ||
|
||
|
||
@register.filter(is_safe=True) | ||
def owner_filter(app): | ||
""" | ||
Extract the owner information from the application object. | ||
""" | ||
return ( | ||
f"{app.last_updated_by.username}" | ||
if app.last_updated_by != app.owner | ||
else f"{app.last_updated_by.username} (owner)" | ||
) | ||
|
||
|
||
@register.simple_tag | ||
def should_display(action, **kwargs): | ||
""" | ||
Check the given history object should be displayed. | ||
Returns true if this is the last record in the history or if there is a difference in the following | ||
fields. | ||
# status | ||
# last_updated_by | ||
# owner | ||
:param action: | ||
:param kwargs: | ||
:return: | ||
""" | ||
return ( | ||
not action.next_record | ||
or action.next_record.history_object.status != action.history_object.status | ||
or action.next_record.history_object.last_updated_by | ||
!= action.history_object.last_updated_by | ||
or action.next_record.history_object.owner != action.history_object.owner | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Changed Fields" is better I think