Merge branch 'main' into sspj/draft-test-cases

This commit is contained in:
Seamus Johnston 2023-06-16 14:17:49 -05:00
commit 12d3f5bdb7
No known key found for this signature in database
GPG key ID: 2F21225985069105
32 changed files with 513 additions and 374 deletions

View file

@ -1,11 +1,13 @@
import logging
from django.contrib import admin, messages
from django.contrib.auth.admin import UserAdmin
from django.contrib.contenttypes.models import ContentType
from django.http.response import HttpResponseRedirect
from django.urls import reverse
from . import models
logger = logging.getLogger(__name__)
class AuditedAdmin(admin.ModelAdmin):
@ -78,13 +80,37 @@ class DomainAdmin(AuditedAdmin):
return super().response_change(request, obj)
class DomainApplicationAdmin(AuditedAdmin):
"""Customize the applications listing view."""
# Trigger action when a fieldset is changed
def save_model(self, request, obj, form, change):
if change: # Check if the application is being edited
# Get the original application from the database
original_obj = models.DomainApplication.objects.get(pk=obj.pk)
if (
obj.status != original_obj.status
and obj.status == models.DomainApplication.INVESTIGATING
):
# This is a transition annotated method in model which will throw an
# error if the condition is violated. To make this work, we need to
# call it on the original object which has the right status value,
# but pass the current object which contains the up-to-date data
# for the email.
original_obj.in_review(obj)
super().save_model(request, obj, form, change)
admin.site.register(models.User, MyUserAdmin)
admin.site.register(models.UserDomainRole, AuditedAdmin)
admin.site.register(models.Contact, AuditedAdmin)
admin.site.register(models.DomainInvitation, AuditedAdmin)
admin.site.register(models.DomainApplication, AuditedAdmin)
admin.site.register(models.DomainInformation, AuditedAdmin)
admin.site.register(models.Domain, DomainAdmin)
admin.site.register(models.Host, MyHostAdmin)
admin.site.register(models.Nameserver, MyHostAdmin)
admin.site.register(models.Website, AuditedAdmin)
admin.site.register(models.DomainApplication, DomainApplicationAdmin)