Skip to content

Commit

Permalink
Merge pull request #283 from co-cddo/feature/revert-ucd-36-changes-fo…
Browse files Browse the repository at this point in the history
…r-removing-history-button

Add historical records back
  • Loading branch information
dhvander authored Sep 24, 2024
2 parents 2f8bf0e + cde84a4 commit fd6f53d
Show file tree
Hide file tree
Showing 4 changed files with 247 additions and 16 deletions.
20 changes: 4 additions & 16 deletions request_a_govuk_domain/request/admin/model_admins.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,31 +576,19 @@ class FilterAndOrderByName(ModelAdmin):
actions_on_bottom = True


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):
class RegistrarPersonAdmin(FilterAndOrderByName):
model = RegistrarPerson


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


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


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


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,236 @@
# Generated by Django 4.2.13 on 2024-09-24 09:27

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import phonenumber_field.modelfields
import simple_history.models


class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
("request", "0020_remove_historicalregistrantperson_history_user_and_more"),
]

operations = [
migrations.CreateModel(
name="HistoricalRegistryPublishedPerson",
fields=[
(
"id",
models.BigIntegerField(
auto_created=True, blank=True, db_index=True, verbose_name="ID"
),
),
("name", models.CharField()),
("email_address", models.EmailField(max_length=320)),
(
"phone_number",
phonenumber_field.modelfields.PhoneNumberField(
blank=True, max_length=128, region=None
),
),
("role", models.CharField()),
("history_id", models.AutoField(primary_key=True, serialize=False)),
("history_date", models.DateTimeField(db_index=True)),
("history_change_reason", models.CharField(max_length=100, null=True)),
(
"history_type",
models.CharField(
choices=[("+", "Created"), ("~", "Changed"), ("-", "Deleted")],
max_length=1,
),
),
(
"history_user",
models.ForeignKey(
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="+",
to=settings.AUTH_USER_MODEL,
),
),
],
options={
"verbose_name": "historical registry published person",
"verbose_name_plural": "historical registry published persons",
"ordering": ("-history_date", "-history_id"),
"get_latest_by": ("history_date", "history_id"),
},
bases=(simple_history.models.HistoricalChanges, models.Model),
),
migrations.CreateModel(
name="HistoricalRegistrarPerson",
fields=[
(
"id",
models.BigIntegerField(
auto_created=True, blank=True, db_index=True, verbose_name="ID"
),
),
("name", models.CharField()),
("email_address", models.EmailField(max_length=320)),
(
"phone_number",
phonenumber_field.modelfields.PhoneNumberField(
blank=True, max_length=128, region=None
),
),
("history_id", models.AutoField(primary_key=True, serialize=False)),
("history_date", models.DateTimeField(db_index=True)),
("history_change_reason", models.CharField(max_length=100, null=True)),
(
"history_type",
models.CharField(
choices=[("+", "Created"), ("~", "Changed"), ("-", "Deleted")],
max_length=1,
),
),
(
"history_user",
models.ForeignKey(
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="+",
to=settings.AUTH_USER_MODEL,
),
),
(
"registrar",
models.ForeignKey(
blank=True,
db_constraint=False,
null=True,
on_delete=django.db.models.deletion.DO_NOTHING,
related_name="+",
to="request.registrar",
),
),
],
options={
"verbose_name": "historical registrar person",
"verbose_name_plural": "historical registrar persons",
"ordering": ("-history_date", "-history_id"),
"get_latest_by": ("history_date", "history_id"),
},
bases=(simple_history.models.HistoricalChanges, models.Model),
),
migrations.CreateModel(
name="HistoricalRegistrantPerson",
fields=[
(
"id",
models.BigIntegerField(
auto_created=True, blank=True, db_index=True, verbose_name="ID"
),
),
("name", models.CharField()),
("email_address", models.EmailField(max_length=320)),
(
"phone_number",
phonenumber_field.modelfields.PhoneNumberField(
blank=True, max_length=128, region=None
),
),
("history_id", models.AutoField(primary_key=True, serialize=False)),
("history_date", models.DateTimeField(db_index=True)),
("history_change_reason", models.CharField(max_length=100, null=True)),
(
"history_type",
models.CharField(
choices=[("+", "Created"), ("~", "Changed"), ("-", "Deleted")],
max_length=1,
),
),
(
"history_user",
models.ForeignKey(
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="+",
to=settings.AUTH_USER_MODEL,
),
),
],
options={
"verbose_name": "historical registrant person",
"verbose_name_plural": "historical registrant persons",
"ordering": ("-history_date", "-history_id"),
"get_latest_by": ("history_date", "history_id"),
},
bases=(simple_history.models.HistoricalChanges, models.Model),
),
migrations.CreateModel(
name="HistoricalRegistrant",
fields=[
(
"id",
models.BigIntegerField(
auto_created=True, blank=True, db_index=True, verbose_name="ID"
),
),
("name", models.CharField()),
(
"type",
models.CharField(
choices=[
(
"central_government",
"Central government department or agency",
),
(
"alb",
"Non-departmental body - also known as an arm's length body",
),
("parish_council", "Parish, town or community council"),
(
"local_authority",
"District, borough, city or county council",
),
("fire_service", "Fire service"),
("combined_authority", "Combined or unitary authority"),
("pcc", "Police and crime commissioner"),
("joint_authority", "Joint authority"),
("joint_committee", "Joint committee"),
(
"psb_group",
"Organisation representing a group of public sector bodies",
),
(
"psb_profession",
"Organisation representing a profession across public sector bodies",
),
],
max_length=100,
),
),
("history_id", models.AutoField(primary_key=True, serialize=False)),
("history_date", models.DateTimeField(db_index=True)),
("history_change_reason", models.CharField(max_length=100, null=True)),
(
"history_type",
models.CharField(
choices=[("+", "Created"), ("~", "Changed"), ("-", "Deleted")],
max_length=1,
),
),
(
"history_user",
models.ForeignKey(
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="+",
to=settings.AUTH_USER_MODEL,
),
),
],
options={
"verbose_name": "historical registrant",
"verbose_name_plural": "historical registrants",
"ordering": ("-history_date", "-history_id"),
"get_latest_by": ("history_date", "history_id"),
},
bases=(simple_history.models.HistoricalChanges, models.Model),
),
]
3 changes: 3 additions & 0 deletions request_a_govuk_domain/request/models/organisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ 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: 4 additions & 0 deletions request_a_govuk_domain/request/models/person.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.db import models
from phonenumber_field.modelfields import PhoneNumberField
from simple_history.models import HistoricalRecords


class Person(models.Model):
Expand All @@ -12,6 +13,9 @@ 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

0 comments on commit fd6f53d

Please sign in to comment.