diff --git a/django/api/admin.py b/django/api/admin.py index 9b7faf2d..fd1ae11f 100644 --- a/django/api/admin.py +++ b/django/api/admin.py @@ -8,6 +8,7 @@ DriverLicenceEditableGoElectricRebateApplication, ChangeRedeemedGoElectricRebateApplication, ExpiredGoElectricRebateApplication, + LegacyGoElectricRebateApplication, ) from .models.household_member import HouseholdMember from .models.go_electric_rebate import GoElectricRebate @@ -590,3 +591,81 @@ def response_change(self, request, obj): else: raise Exception("There exists an associated Go Elecric Rebate!") return ret + + +@admin.register(LegacyGoElectricRebateApplication) +class LegacyGoElectricRebateApplicationAdmin(ITVRModelAdminStringent): + + def has_delete_permission(self, request, obj=None): + return admin.ModelAdmin.has_delete_permission(self, request, obj) + + search_fields = ["drivers_licence", "id"] + exclude = ( + "sin", + "doc1", + "doc2", + "user", + "spouse_email", + "status", + "address", + "city", + "postal_code", + "application_type", + "doc1_tag", + "doc2_tag", + "consent_personal", + "consent_tax", + "reason_for_decline", + ) + readonly_fields = ( + "id", + "last_name", + "first_name", + "middle_names", + "status", + "email", + "user_is_bcsc", + "drivers_licence", + "date_of_birth", + "tax_year", + "is_legacy", + "confirmation_email_success", + "spouse_email_success", + "created", + "approved_on", + "not_approved_on", + ) + + def get_queryset(self, request): + return GoElectricRebateApplication.objects.filter(is_legacy=True) + + def render_delete_form(self, request, context): + new_perms_lacking = set() + perms_lacking = context.get("perms_lacking") + if perms_lacking is not None: + for p in perms_lacking: + if p != "go electric rebate application": + new_perms_lacking.add(p) + context["perms_lacking"] = new_perms_lacking + return super().render_delete_form(request, context) + + def get_deleted_objects(self, objs, request): + ( + deleted_objects, + model_count, + perms_needed, + protected, + ) = super().get_deleted_objects(objs, request) + + new_perms_needed = set() + if perms_needed is not None: + for p in perms_needed: + if p != "go electric rebate application": + new_perms_needed.add(p) + + return ( + deleted_objects, + model_count, + new_perms_needed, + protected, + ) diff --git a/django/api/migrations/0022_legacygoelectricrebateapplication.py b/django/api/migrations/0022_legacygoelectricrebateapplication.py new file mode 100644 index 00000000..03a3e555 --- /dev/null +++ b/django/api/migrations/0022_legacygoelectricrebateapplication.py @@ -0,0 +1,25 @@ +# Generated by Django 4.0.9 on 2024-06-20 18:31 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0021_expiredgoelectricrebateapplication'), + ] + + operations = [ + migrations.CreateModel( + name='LegacyGoElectricRebateApplication', + fields=[ + ], + options={ + 'ordering': ['-modified'], + 'proxy': True, + 'indexes': [], + 'constraints': [], + }, + bases=('api.goelectricrebateapplication',), + ), + ] diff --git a/django/api/models/go_electric_rebate_application.py b/django/api/models/go_electric_rebate_application.py index 1ee63e24..c6536cc1 100644 --- a/django/api/models/go_electric_rebate_application.py +++ b/django/api/models/go_electric_rebate_application.py @@ -90,7 +90,9 @@ class Status(TextChoices): city = CharField(max_length=250, unique=False, null=True) postal_code = CharField(max_length=6, unique=False, blank=True, null=True) drivers_licence = CharField( - max_length=8, unique=False, validators=[MinLengthValidator(7), validate_drivers_licence] + max_length=8, + unique=False, + validators=[MinLengthValidator(7), validate_drivers_licence], ) date_of_birth = DateField(validators=[validate_driving_age], null=True) tax_year = IntegerField(null=True) @@ -299,3 +301,13 @@ class Meta: @classproperty def admin_label(cls): return "Extend Expiry Dates" + + +class LegacyGoElectricRebateApplication(GoElectricRebateApplication): + class Meta: + proxy = True + ordering = ["-modified"] + + @classproperty + def admin_label(cls): + return "Delete Legacy Applications" diff --git a/django/api/templates/admin/api/expiredgoelectricrebateapplication/submit_line.html b/django/api/templates/admin/api/expiredgoelectricrebateapplication/submit_line.html index 5ba1f1c4..c0796d98 100644 --- a/django/api/templates/admin/api/expiredgoelectricrebateapplication/submit_line.html +++ b/django/api/templates/admin/api/expiredgoelectricrebateapplication/submit_line.html @@ -3,7 +3,6 @@ {% get_jazzmin_ui_tweaks as jazzmin_ui %} {% load static %} {% block submit-row %} -