Skip to content
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

Merged
merged 5 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions request_a_govuk_domain/request/admin/model_admins.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,19 +559,31 @@ class FilterAndOrderByName(ModelAdmin):
actions_on_bottom = True


class RegistrarPersonAdmin(FilterAndOrderByName):
class DisableHistoryMixin:
"""
Disable change for the given entity, this in turn
disables the history button.
"""

def render_change_form(
self, request, context, add=False, change=False, form_url="", obj=None
):
return super().render_change_form(request, context, add, False, form_url, obj)


class RegistrarPersonAdmin(DisableHistoryMixin, FilterAndOrderByName):
model = RegistrarPerson


class RegistrantPersonAdmin(FilterAndOrderByName):
class RegistrantPersonAdmin(DisableHistoryMixin, FilterAndOrderByName):
model = RegistrantPerson


class RegistryPublishedPersonAdmin(FilterAndOrderByName):
class RegistryPublishedPersonAdmin(DisableHistoryMixin, FilterAndOrderByName):
model = RegistryPublishedPerson


class RegistrantAdmin(FilterAndOrderByName):
class RegistrantAdmin(DisableHistoryMixin, FilterAndOrderByName):
model = Registrant


Expand Down
9 changes: 7 additions & 2 deletions request_a_govuk_domain/request/admin/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging

import os

from django.views import View
from django.contrib import admin, messages
Expand Down Expand Up @@ -45,7 +45,12 @@ def post(self, request):
if "_confirm" in request.POST:
try:
# send email
send_approval_or_rejection_email(request)
if os.environ.get("ENVIRONMENT") != "local":
maxf marked this conversation as resolved.
Show resolved Hide resolved
send_approval_or_rejection_email(request)
else:
LOGGER.warning(
"Not sending approval or rejection email as marked as local environment"
)
self._set_application_status(request)
# To show the backend app user a message "[Approval/Rejection] email sent", get the type of
# action ( i.e. whether it is Approval or Rejection )
Expand Down
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",
),
]
6 changes: 1 addition & 5 deletions request_a_govuk_domain/request/models/organisation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from django.utils.translation import gettext_lazy as _
from django.db import models

from django.utils.translation import gettext_lazy as _
from simple_history.models import HistoricalRecords


Expand Down Expand Up @@ -49,9 +48,6 @@ class Registrant(models.Model):
name = models.CharField()
type = models.CharField(choices=RegistrantTypeChoices.choices, max_length=100)

# maintain history
history = HistoricalRecords()

class Meta:
unique_together = ("name", "type")

Expand Down
4 changes: 0 additions & 4 deletions request_a_govuk_domain/request/models/person.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from django.db import models
from phonenumber_field.modelfields import PhoneNumberField
from simple_history.models import HistoricalRecords


class Person(models.Model):
Expand All @@ -13,9 +12,6 @@ class Person(models.Model):
email_address = models.EmailField(max_length=320)
phone_number = PhoneNumberField(blank=True)

# maintain history
history = HistoricalRecords(inherit=True)

def __str__(self):
return self.name

Expand Down
2 changes: 1 addition & 1 deletion request_a_govuk_domain/request/models/review.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@


# We've added simple-history to the dependencies but need to implement it,
# principally for this this class.
# principally for this class.
class Review(models.Model):
"""
An extension of the Application class (has a one-to-one) relationship
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{% load i18n %}
{% load url from simple_history_compat %}
{% load admin_urls %}
{% load getattribute from getattributes %}
{% load admin_tags %}
<style nonce="{{ request.csp_nonce }}">
.full_width {
width: 100%;
align-items: center;
}

.full_width td {
width: 30%;
}

h2 {
margin-top: 2%;
}
</style>


<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 'User' %}</th>
<th scope="col">{% trans 'Changed 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 | format_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.last_updated_by }}</a>
{% else %}
{{ action.history_object.last_updated_by }}
{% endif %}
{% else %}
{% trans "-" %}
{% endif %}
</td>
<td>
{{ action | changed_fields }}
</td>
</tr>
{% endfor %}
</tbody>
</table>
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
{% load i18n %}
{% load url from simple_history_compat %}
{% load admin_urls %}
{% load getattribute from getattributes %}
{% load admin_tags %}
<style nonce="{{ request.csp_nonce }}">
.full_width {
width: 100%;
align-items: center;
}

.full_width td {
width: 30%;
}

h2 {
margin-top: 2%;
}
</style>

<h2>Status change history</h2>
<table id="change-history-summary" 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=application_history %}
{% for action in filtered_actions %}
{% should_display action as should_display %}
{% if should_display %}
<tr>
<td>
<a href="{% url opts|application_admin_url:'simple_history' action.id action.pk %}">{{ action.history_date | format_date }}</a>
</td>
<td>
{% if action.last_updated_by %}
{% url admin_user_view action.last_updated_by.id as admin_user_url %}
{% if admin_user_url %}
<a href="{{ admin_user_url }}">{{ action| owner_filter }}</a>
{% else %}
{{ action.last_updated_by }}
{% endif %}
{% else %}
{% trans "-" %}
{% endif %}
</td>
<td>
{{ action.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 'User' %}</th>
<th scope="col">{% trans 'Changed 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| format_date }}</a>
</td>
<td>
{% if action.history_user %}
{% url admin_user_view action.history_user.id as admin_user_url %}
{% if admin_user_url %}
<a href="{{ admin_user_url }}">{{ action.history_user }}</a>
{% else %}
{{ action.history_user }}
{% endif %}
{% else %}
{% trans "-" %}
{% endif %}
</td>
<td>
<i>{{ action | changed_fields }}</i>
</td>
</tr>
{% endfor %}
</tbody>
</table>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{% extends "admin/object_history.html" %}
{% load i18n %}
{% load url from simple_history_compat %}
{% load admin_urls %}
{% load display_list from simple_history_admin_list %}
{% load admin_tags %}

{% block content %}
<div id="content-main">
<div class="govuk-table">
{% if action_list %}
{% history_type action_list as history_type %}
{% if history_type == "Review" %}
{% display_review_list %}
{% elif history_type == "Application" %}
{% display_application_list %}
{% else %}
{% display_list %}
{% endif %}
{% else %}
<p>{% trans "This object doesn't have a change history." %}</p>
{% endif %}
</div>
</div>
{% endblock %}
Empty file.
Loading