diff --git a/src/registrar/admin.py b/src/registrar/admin.py index 7c164ae27..ed5f143bb 100644 --- a/src/registrar/admin.py +++ b/src/registrar/admin.py @@ -1136,7 +1136,7 @@ class DomainAdmin(ListHeaderAdmin): "_get_status": self.do_get_status, "_extend_expiration_date": self.do_extend_expiration_date, } - + print(f"this is the response! {request.POST}") # Check which action button was pressed and call the corresponding function for action, function in ACTION_FUNCTIONS.items(): if action in request.POST: @@ -1147,7 +1147,7 @@ class DomainAdmin(ListHeaderAdmin): def do_extend_expiration_date(self, request, obj): if not isinstance(obj, Domain): - self.message_user(request, "Object is not of type Domain", messages.ERROR) + self.message_user(request, "Object is not of type Domain.", messages.ERROR) return None try: @@ -1156,24 +1156,32 @@ class DomainAdmin(ListHeaderAdmin): if err.code: self.message_user( request, - f"Error extending this domain: {err}", + f"Error extending this domain: {err}.", messages.ERROR, ) elif err.is_connection_error(): self.message_user( request, - "Error connecting to the registry", + "Error connecting to the registry.", messages.ERROR, ) else: self.message_user(request, err, messages.ERROR) + except KeyError: + # In normal code flow, a keyerror can only occur when + # fresh data can't be pulled from the registry, and thus there is no cache. + self.message_user( + request, + "Error connecting to the registry. No expiration date was found.", + messages.ERROR, + ) except Exception as err: self.message_user(request, err, messages.ERROR) else: updated_domain = Domain.objects.filter(id=obj).get() self.message_user( request, - f"Successfully extended expiration date to {updated_domain.registry_expiration_date}", + f"Successfully extended expiration date to {updated_domain.registry_expiration_date}.", ) return HttpResponseRedirect(".") @@ -1328,6 +1336,17 @@ class DomainAdmin(ListHeaderAdmin): return True return super().has_change_permission(request, obj) + def changelist_view(self, request, extra_context=None): + extra_context = extra_context or {} + # Create HTML for the modal button + modal_button = ( + '' + ) + extra_context["modal_button"] = modal_button + return super().changelist_view(request, extra_context=extra_context) + class DraftDomainAdmin(ListHeaderAdmin): """Custom draft domain admin class.""" diff --git a/src/registrar/assets/js/get-gov-admin.js b/src/registrar/assets/js/get-gov-admin.js index 866c7bd7d..007ded215 100644 --- a/src/registrar/assets/js/get-gov-admin.js +++ b/src/registrar/assets/js/get-gov-admin.js @@ -44,6 +44,29 @@ function openInNewTab(el, removeAttribute = false){ domainSubmitButton.addEventListener("mouseover", () => openInNewTab(domainFormElement, true)); domainSubmitButton.addEventListener("mouseout", () => openInNewTab(domainFormElement, false)); } + + let extendExpirationDateButton = document.getElementById("extend_expiration_date_button") + if (extendExpirationDateButton){ + extendExpirationDateButton.addEventListener("click", () => { + form = document.getElementById("domain_form") + /* + For some reason, Django admin has the propensity to ignore nested + inputs and delete nested form objects. + The workaround is to manually create an element as so, after the DOM + has been generated. + + Its not the most beautiful thing every, but it works. + */ + var input = document.createElement("input"); + input.type = "hidden"; + input.name = "_extend_expiration_date"; + // The value doesn't matter, just needs to be present + input.value = "1"; + // Add the hidden input to the form + form.appendChild(input); + form.submit(); + }) + } } prepareDjangoAdmin(); diff --git a/src/registrar/assets/sass/_theme/_admin.scss b/src/registrar/assets/sass/_theme/_admin.scss index 760c4f13a..4c0a1f7cc 100644 --- a/src/registrar/assets/sass/_theme/_admin.scss +++ b/src/registrar/assets/sass/_theme/_admin.scss @@ -270,3 +270,9 @@ h1, h2, h3, margin: 0!important; } } + +// Button groups in /admin incorrectly have bullets. +// Remove that! +.usa-button-group .usa-button-group__item { + list-style-type: none; +} diff --git a/src/registrar/templates/django/admin/domain_change_form.html b/src/registrar/templates/django/admin/domain_change_form.html index c67d95235..bf8a0de2e 100644 --- a/src/registrar/templates/django/admin/domain_change_form.html +++ b/src/registrar/templates/django/admin/domain_change_form.html @@ -5,19 +5,57 @@
- + {{ modal_button }} Disable DNSSEC + > + Extend expiration date +
- {% include 'includes/modal.html' with modal_heading="Are you sure you want to disable DNSSEC?" modal_button=modal_button|safe %} +
+
+ +
+ +
+ + +
+
+ {# {% include 'includes/modal.html' with modal_heading="Are you sure you want to extend this expiration date?" modal_button=modal_button|safe %} #}
{% if original.state == original.State.READY %}