merge from main

This commit is contained in:
Rachid Mrad 2024-03-29 13:18:17 -04:00
commit a3739193d7
No known key found for this signature in database
26 changed files with 1084 additions and 29 deletions

View file

@ -910,6 +910,9 @@ class DomainInformationAdmin(ListHeaderAdmin):
),
]
# Readonly fields for analysts and superusers
readonly_fields = ("other_contacts",)
# Read only that we'll leverage for CISA Analysts
analyst_readonly_fields = [
"creator",
@ -938,6 +941,8 @@ class DomainInformationAdmin(ListHeaderAdmin):
# Table ordering
ordering = ["domain__name"]
change_form_template = "django/admin/domain_information_change_form.html"
def get_readonly_fields(self, request, obj=None):
"""Set the read-only state on form elements.
We have 1 conditions that determine which fields are read-only:
@ -1116,6 +1121,9 @@ class DomainRequestAdmin(ListHeaderAdmin):
),
]
# Readonly fields for analysts and superusers
readonly_fields = ("other_contacts", "current_websites", "alternative_domains")
# Read only that we'll leverage for CISA Analysts
analyst_readonly_fields = [
"creator",
@ -1142,6 +1150,8 @@ class DomainRequestAdmin(ListHeaderAdmin):
# Table ordering
ordering = ["requested_domain__name"]
change_form_template = "django/admin/domain_request_change_form.html"
# Trigger action when a fieldset is changed
def save_model(self, request, obj, form, change):
"""Custom save_model definition that handles edge cases"""
@ -1296,7 +1306,7 @@ class DomainRequestAdmin(ListHeaderAdmin):
readonly_fields.extend([field.name for field in self.model._meta.fields])
# Add the multi-select fields to readonly_fields:
# Complex fields like ManyToManyField require special handling
readonly_fields.extend(["current_websites", "other_contacts", "alternative_domains"])
readonly_fields.extend(["alternative_domains"])
if request.user.has_perm("registrar.full_access_permission"):
return readonly_fields
@ -1407,7 +1417,6 @@ class DomainAdmin(ListHeaderAdmin):
)
def queryset(self, request, queryset):
logger.debug(self.value())
if self.value() == "1":
return queryset.filter(domain_info__is_election_board=True)
if self.value() == "0":
@ -1813,6 +1822,13 @@ class VerifiedByStaffAdmin(ListHeaderAdmin):
super().save_model(request, obj, form, change)
class FederalAgencyAdmin(ListHeaderAdmin):
list_display = ["agency"]
search_fields = ["agency"]
search_help_text = "Search by agency name."
ordering = ["agency"]
admin.site.unregister(LogEntry) # Unregister the default registration
admin.site.register(LogEntry, CustomLogEntryAdmin)
admin.site.register(models.User, MyUserAdmin)
@ -1826,6 +1842,7 @@ admin.site.register(models.DomainInvitation, DomainInvitationAdmin)
admin.site.register(models.DomainInformation, DomainInformationAdmin)
admin.site.register(models.Domain, DomainAdmin)
admin.site.register(models.DraftDomain, DraftDomainAdmin)
admin.site.register(models.FederalAgency, FederalAgencyAdmin)
# Host and HostIP removed from django admin because changes in admin
# do not propagate to registry and logic not applied
admin.site.register(models.Host, MyHostAdmin)