Update tab titles for specific admin models

This commit is contained in:
Rebecca Hsieh 2024-06-05 16:28:52 -07:00
parent 03b943cd9b
commit 9291bb5850
No known key found for this signature in database
3 changed files with 129 additions and 7 deletions

View file

@ -383,6 +383,39 @@ class CustomLogEntryAdmin(LogEntryAdmin):
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"
# Select log entry to change -> Log entries
def changelist_view(self, request, extra_context=None):
if extra_context is None:
extra_context = {}
extra_context["tabtitle"] = "Log entries"
return super().changelist_view(request, extra_context=extra_context)
# #786: Skipping on updating audit log tab titles for now
# def change_view(self, request, object_id, form_url="", extra_context=None):
# if extra_context is None:
# extra_context = {}
# log_entry = self.get_object(request, object_id)
# if log_entry:
# # Reset title to empty string
# extra_context["subtitle"] = ""
# extra_context["tabtitle"] = ""
# object_repr = log_entry.object_repr # Hold name of the object
# changes = log_entry.changes
# # Check if this is a log entry for an addition and related to the contact model
# # Created [name] -> Created [name] contact | Change log entry
# if (
# all(new_value != "None" for field, (old_value, new_value) in changes.items())
# and log_entry.content_type.model == "contact"
# ):
# extra_context["subtitle"] = f"Created {object_repr} contact"
# extra_context["tabtitle"] = "Change log entry"
# return super().change_view(request, object_id, form_url, extra_context=extra_context)
class AdminSortFields: class AdminSortFields:
_name_sort = ["first_name", "last_name", "email"] _name_sort = ["first_name", "last_name", "email"]
@ -778,6 +811,14 @@ class MyHostAdmin(AuditedAdmin, ImportExportModelAdmin):
search_help_text = "Search by domain or host name." search_help_text = "Search by domain or host name."
inlines = [HostIPInline] inlines = [HostIPInline]
# Select host to change -> Host
def changelist_view(self, request, extra_context=None):
if extra_context is None:
extra_context = {}
extra_context["tabtitle"] = "Host"
# Get the filtered values
return super().changelist_view(request, extra_context=extra_context)
class HostIpResource(resources.ModelResource): class HostIpResource(resources.ModelResource):
"""defines how each field in the referenced model should be mapped to the corresponding fields in the """defines how each field in the referenced model should be mapped to the corresponding fields in the
@ -793,6 +834,14 @@ class HostIpAdmin(AuditedAdmin, ImportExportModelAdmin):
resource_classes = [HostIpResource] resource_classes = [HostIpResource]
model = models.HostIP model = models.HostIP
# Select host ip to change -> Host ip
def changelist_view(self, request, extra_context=None):
if extra_context is None:
extra_context = {}
extra_context["tabtitle"] = "Host IP"
# Get the filtered values
return super().changelist_view(request, extra_context=extra_context)
class ContactResource(resources.ModelResource): class ContactResource(resources.ModelResource):
"""defines how each field in the referenced model should be mapped to the corresponding fields in the """defines how each field in the referenced model should be mapped to the corresponding fields in the
@ -926,6 +975,14 @@ class ContactAdmin(ListHeaderAdmin, ImportExportModelAdmin):
return super().change_view(request, object_id, form_url, extra_context=extra_context) return super().change_view(request, object_id, form_url, extra_context=extra_context)
# Select contact to change -> Contacts
def changelist_view(self, request, extra_context=None):
if extra_context is None:
extra_context = {}
extra_context["tabtitle"] = "Contacts"
# Get the filtered values
return super().changelist_view(request, extra_context=extra_context)
class WebsiteResource(resources.ModelResource): class WebsiteResource(resources.ModelResource):
"""defines how each field in the referenced model should be mapped to the corresponding fields in the """defines how each field in the referenced model should be mapped to the corresponding fields in the
@ -1043,6 +1100,21 @@ class UserDomainRoleAdmin(ListHeaderAdmin, ImportExportModelAdmin):
else: else:
return response return response
# User Domain manager [email] is manager on domain [domain name] ->
# Domain manager [email] on [domain name]
def changeform_view(self, request, object_id=None, form_url="", extra_context=None):
if extra_context is None:
extra_context = {}
if object_id:
obj = self.get_object(request, object_id)
if obj:
email = obj.user.email
domain_name = obj.domain.name
extra_context["subtitle"] = f"Domain manager {email} on {domain_name}"
return super().changeform_view(request, object_id, form_url, extra_context=extra_context)
class DomainInvitationAdmin(ListHeaderAdmin): class DomainInvitationAdmin(ListHeaderAdmin):
"""Custom domain invitation admin class.""" """Custom domain invitation admin class."""
@ -1079,6 +1151,14 @@ class DomainInvitationAdmin(ListHeaderAdmin):
change_form_template = "django/admin/email_clipboard_change_form.html" change_form_template = "django/admin/email_clipboard_change_form.html"
# Select domain invitations to change -> Domain invitations
def changelist_view(self, request, extra_context=None):
if extra_context is None:
extra_context = {}
extra_context["tabtitle"] = "Domain invitations"
# Get the filtered values
return super().changelist_view(request, extra_context=extra_context)
class DomainInformationResource(resources.ModelResource): class DomainInformationResource(resources.ModelResource):
"""defines how each field in the referenced model should be mapped to the corresponding fields in the """defines how each field in the referenced model should be mapped to the corresponding fields in the
@ -1219,6 +1299,14 @@ class DomainInformationAdmin(ListHeaderAdmin, ImportExportModelAdmin):
readonly_fields.extend([field for field in self.analyst_readonly_fields]) readonly_fields.extend([field for field in self.analyst_readonly_fields])
return readonly_fields # Read-only fields for analysts return readonly_fields # Read-only fields for analysts
# Select domain information to change -> Domain information
def changelist_view(self, request, extra_context=None):
if extra_context is None:
extra_context = {}
extra_context["tabtitle"] = "Domain information"
# Get the filtered values
return super().changelist_view(request, extra_context=extra_context)
class DomainRequestResource(FsmModelResource): class DomainRequestResource(FsmModelResource):
"""defines how each field in the referenced model should be mapped to the corresponding fields in the """defines how each field in the referenced model should be mapped to the corresponding fields in the
@ -1687,6 +1775,14 @@ class DomainRequestAdmin(ListHeaderAdmin, ImportExportModelAdmin):
self.display_restricted_warning(request, obj) self.display_restricted_warning(request, obj)
return super().change_view(request, object_id, form_url, extra_context) return super().change_view(request, object_id, form_url, extra_context)
# Select domain request to change -> Domain requests
def changelist_view(self, request, extra_context=None):
if extra_context is None:
extra_context = {}
extra_context["tabtitle"] = "Domain requests"
# Get the filtered values
return super().changelist_view(request, extra_context=extra_context)
class TransitionDomainAdmin(ListHeaderAdmin): class TransitionDomainAdmin(ListHeaderAdmin):
"""Custom transition domain admin class.""" """Custom transition domain admin class."""
@ -2244,6 +2340,14 @@ class DraftDomainAdmin(ListHeaderAdmin, ImportExportModelAdmin):
# If no redirection is needed, return the original response # If no redirection is needed, return the original response
return response return response
# Select draft domain to change -> Draft domains
def changelist_view(self, request, extra_context=None):
if extra_context is None:
extra_context = {}
extra_context["tabtitle"] = "Draft domains"
# Get the filtered values
return super().changelist_view(request, extra_context=extra_context)
class PublicContactResource(resources.ModelResource): class PublicContactResource(resources.ModelResource):
"""defines how each field in the referenced model should be mapped to the corresponding fields in the """defines how each field in the referenced model should be mapped to the corresponding fields in the
@ -2288,6 +2392,20 @@ class PublicContactAdmin(ListHeaderAdmin, ImportExportModelAdmin):
change_form_template = "django/admin/email_clipboard_change_form.html" change_form_template = "django/admin/email_clipboard_change_form.html"
autocomplete_fields = ["domain"] autocomplete_fields = ["domain"]
def changeform_view(self, request, object_id=None, form_url="", extra_context=None):
if extra_context is None:
extra_context = {}
if object_id:
obj = self.get_object(request, object_id)
if obj:
name = obj.name
email = obj.email
registry_id = obj.registry_id
extra_context["subtitle"] = f"{name} <{email}> id: {registry_id}"
return super().changeform_view(request, object_id, form_url, extra_context=extra_context)
class VerifiedByStaffAdmin(ListHeaderAdmin): class VerifiedByStaffAdmin(ListHeaderAdmin):
list_display = ("email", "requestor", "truncated_notes", "created_at") list_display = ("email", "requestor", "truncated_notes", "created_at")
@ -2340,6 +2458,14 @@ class UserGroupAdmin(AuditedAdmin):
def user_group(self, obj): def user_group(self, obj):
return obj.name return obj.name
# Select user groups to change -> User groups
def changelist_view(self, request, extra_context=None):
if extra_context is None:
extra_context = {}
extra_context["tabtitle"] = "User groups"
# Get the filtered values
return super().changelist_view(request, extra_context=extra_context)
class WaffleFlagAdmin(FlagAdmin): class WaffleFlagAdmin(FlagAdmin):
"""Custom admin implementation of django-waffle's Flag class""" """Custom admin implementation of django-waffle's Flag class"""

View file

@ -30,12 +30,8 @@
{% if subtitle %} {% if subtitle %}
{{ subtitle }} | {{ subtitle }} |
{% endif %} {% endif %}
{% if title == "Audit log administration" %} {% if tabtitle %}
Audit log | {{ tabtitle }} |
{% elif title == "Select log entry to change" %}
Log entries |
{% elif title == "Select log entry to view" %}
Log entries |
{% else %} {% else %}
{{ title }} | {{ title }} |
{% endif %} {% endif %}

View file

@ -3,7 +3,7 @@
<div class="usa-logo display-inline-block" id="extended-logo"> <div class="usa-logo display-inline-block" id="extended-logo">
<strong class="usa-logo__text" > <strong class="usa-logo__text" >
{% if logo_clickable %} {% if logo_clickable %}
<a href="{% url 'home' %}">.gov Registrar </a> <a href="{% url 'home' %}">.gov Registrar</a>
{% else %} {% else %}
<button <button
class="usa-button--unstyled disabled-button usa-tooltip" class="usa-button--unstyled disabled-button usa-tooltip"