add email address to contact table, add domain info search, columns, filters, add domain invite columns, search, add domain columns, filters, add domain roles, add website search

This commit is contained in:
Rachid Mrad 2023-09-08 17:50:28 -04:00
parent 4ca3a2712e
commit b45c5665d3
No known key found for this signature in database
GPG key ID: EF38E4CEC4A8F3CF

View file

@ -6,38 +6,34 @@ from django.http.response import HttpResponseRedirect
from django.urls import reverse from django.urls import reverse
from registrar.models.utility.admin_sort_fields import AdminSortFields from registrar.models.utility.admin_sort_fields import AdminSortFields
from . import models from . import models
from auditlog.models import LogEntry # type: ignore from auditlog.models import LogEntry # type: ignore
from auditlog.admin import LogEntryAdmin # type: ignore from auditlog.admin import LogEntryAdmin # type: ignore
from django.contrib.auth import get_user_model
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
class CustomLogEntryAdmin(LogEntryAdmin): class CustomLogEntryAdmin(LogEntryAdmin):
# Overwrite the generated LogEntry admin class """Overwrite the generated LogEntry admin class"""
# list_select_related = ["content_type", "actor"]
list_display = [ list_display = [
"created", "created",
"custom_resource_url", "resource",
"action", "action",
"msg_short", "msg_short",
"user_url", "user_url",
] ]
# search_fields = [
# "content_type",
# "object_repr",
# "changes",
# ]
def custom_resource_url(self, obj): # We name the custom prop 'resource' because linter
# Replace 'my_field' with the name of your field # is not allowing a short_description attr on it
return f"{obj.content_type} - {obj.object_repr}" # Return the field value without a link # This gets around the linter limitation, for now.
def resource(self, obj):
custom_resource_url.short_description = 'Resource' # Return the field value without a link
return f"{obj.content_type} - {obj.object_repr}"
search_help_text = "Search by resource, changes, or user." search_help_text = "Search by resource, changes, or user."
change_form_template = 'admin/change_form_no_submit.html' change_form_template = "admin/change_form_no_submit.html"
add_form_template = 'admin/change_form_no_submit.html' add_form_template = "admin/change_form_no_submit.html"
class AuditedAdmin(admin.ModelAdmin, AdminSortFields): class AuditedAdmin(admin.ModelAdmin, AdminSortFields):
@ -121,14 +117,12 @@ class ListHeaderAdmin(AuditedAdmin):
class UserContactInline(admin.StackedInline): class UserContactInline(admin.StackedInline):
"""Edit a user's profile on the user page.""" """Edit a user's profile on the user page."""
model = models.Contact model = models.Contact
class MyUserAdmin(BaseUserAdmin): class MyUserAdmin(BaseUserAdmin):
"""Custom user admin class to use our inlines.""" """Custom user admin class to use our inlines."""
inlines = [UserContactInline] inlines = [UserContactInline]
@ -182,23 +176,35 @@ class MyUserAdmin(BaseUserAdmin):
class HostIPInline(admin.StackedInline): class HostIPInline(admin.StackedInline):
"""Edit an ip address on the host page.""" """Edit an ip address on the host page."""
model = models.HostIP model = models.HostIP
class MyHostAdmin(AuditedAdmin): class MyHostAdmin(AuditedAdmin):
"""Custom host admin class to use our inlines.""" """Custom host admin class to use our inlines."""
inlines = [HostIPInline] inlines = [HostIPInline]
class DomainAdmin(ListHeaderAdmin): class DomainAdmin(ListHeaderAdmin):
"""Custom domain admin class to add extra buttons.""" """Custom domain admin class to add extra buttons."""
# Columns
list_display = [
"name",
"organization_type",
"state",
]
def organization_type(self, obj):
return (
obj.domain_info.organization_type
)
# Filters
list_filter = ["domain_info__organization_type"]
search_fields = ["name"] search_fields = ["name"]
search_help_text = "Search by domain name." search_help_text = "Search by domain name."
change_form_template = "django/admin/domain_change_form.html" change_form_template = "django/admin/domain_change_form.html"
@ -252,11 +258,97 @@ class ContactAdmin(ListHeaderAdmin):
search_fields = ["email", "first_name", "last_name"] search_fields = ["email", "first_name", "last_name"]
search_help_text = "Search by firstname, lastname or email." search_help_text = "Search by firstname, lastname or email."
list_display = [
"contact",
"email",
]
# We name the custom prop 'contact' because linter
# is not allowing a short_description attr on it
# This gets around the linter limitation, for now.
def contact(self, obj):
if obj.first_name or obj.last_name:
return obj.get_formatted_name()
elif obj.email:
return obj.email
elif obj.pk:
return str(obj.pk)
else:
return ""
class WebsiteAdmin(ListHeaderAdmin):
"""Custom website admin class."""
# Search
search_fields = [
"website",
]
search_help_text = "Search by website."
class UserDomainRoleAdmin(ListHeaderAdmin):
"""Custom domain role admin class."""
# Columns
list_display = [
"user",
"domain",
"role",
]
# Search
search_fields = [
"user__first_name",
"user__last_name",
"domain__name",
"role",
]
search_help_text = "Search by user, domain, or role."
class DomainInvitationAdmin(ListHeaderAdmin):
"""Custom domain invitation admin class."""
# Columns
list_display = [
"email",
"domain",
"status",
]
# Search
search_fields = [
"email",
"domain__name",
]
search_help_text = "Search by email or domain."
class DomainInformationAdmin(ListHeaderAdmin):
"""Customize domain information admin class."""
# Columns
list_display = [
"domain",
"organization_type",
"created_at",
"submitter",
]
# Filters
list_filter = ["organization_type"]
# Search
search_fields = [
"domain__name",
]
search_help_text = "Search by domain."
class DomainApplicationAdmin(ListHeaderAdmin): class DomainApplicationAdmin(ListHeaderAdmin):
"""Customize the applications listing view.""" """Custom domain applications admin class."""
# Set multi-selects 'read-only' (hide selects and show data) # Set multi-selects 'read-only' (hide selects and show data)
# based on user perms and application creator's status # based on user perms and application creator's status
@ -433,12 +525,12 @@ class DomainApplicationAdmin(ListHeaderAdmin):
admin.site.unregister(LogEntry) # Unregister the default registration admin.site.unregister(LogEntry) # Unregister the default registration
admin.site.register(LogEntry, CustomLogEntryAdmin) admin.site.register(LogEntry, CustomLogEntryAdmin)
admin.site.register(models.User, MyUserAdmin) admin.site.register(models.User, MyUserAdmin)
admin.site.register(models.UserDomainRole, AuditedAdmin) admin.site.register(models.UserDomainRole, UserDomainRoleAdmin)
admin.site.register(models.Contact, ContactAdmin) admin.site.register(models.Contact, ContactAdmin)
admin.site.register(models.DomainInvitation, AuditedAdmin) admin.site.register(models.DomainInvitation, DomainInvitationAdmin)
admin.site.register(models.DomainInformation, AuditedAdmin) admin.site.register(models.DomainInformation, DomainInformationAdmin)
admin.site.register(models.Domain, DomainAdmin) admin.site.register(models.Domain, DomainAdmin)
admin.site.register(models.Host, MyHostAdmin) admin.site.register(models.Host, MyHostAdmin)
admin.site.register(models.Nameserver, MyHostAdmin) admin.site.register(models.Nameserver, MyHostAdmin)
admin.site.register(models.Website, AuditedAdmin) admin.site.register(models.Website, WebsiteAdmin)
admin.site.register(models.DomainApplication, DomainApplicationAdmin) admin.site.register(models.DomainApplication, DomainApplicationAdmin)