diff --git a/src/registrar/admin.py b/src/registrar/admin.py index 292ecf01f..1f96571a5 100644 --- a/src/registrar/admin.py +++ b/src/registrar/admin.py @@ -1079,9 +1079,15 @@ class DomainAdmin(ListHeaderAdmin): def changeform_view(self, request, object_id=None, form_url="", extra_context=None): if extra_context is None: extra_context = {} - # Pass in what the an extended expiration date would be - # for the expiration date modal - extra_context["extended_expiration_date"] = date.today() + relativedelta(years=1) + + # Pass in what the an extended expiration date would be for the expiration date modal + if object_id is not None: + domain = Domain.objects.get(pk=object_id) + years_to_extend_by = self._get_calculated_years_for_exp_date(domain) + extra_context["extended_expiration_date"] = date.today() + relativedelta(years=years_to_extend_by) + else: + extra_context["extended_expiration_date"] = None + return super().changeform_view(request, object_id, form_url, extra_context) def export_data_type(self, request): @@ -1161,26 +1167,7 @@ class DomainAdmin(ListHeaderAdmin): self.message_user(request, "Object is not of type Domain.", messages.ERROR) return None - # Get the date we want to update to - desired_date = self._get_current_date() + relativedelta(years=1) - - # Grab the current expiration date - try: - exp_date = obj.registry_expiration_date - except KeyError: - # if no expiration date from registry, set it to today - logger.warning("current expiration date not set; setting to today") - exp_date = self._get_current_date() - - # If the expiration date is super old (2020, for example), we need to - # "catch up" to the current year, so we add the difference. - # If both years match, then lets just proceed as normal. - calculated_exp_date = exp_date + relativedelta(years=1) - - year_difference = desired_date.year - exp_date.year - # Max probably isn't needed here (no code flow), but it guards against negative and 0. - years = max(1, year_difference) if desired_date > calculated_exp_date else 1 - + years = self._get_calculated_years_for_exp_date(obj) # Renew the domain. try: obj.renew_domain(length=years) @@ -1208,6 +1195,37 @@ class DomainAdmin(ListHeaderAdmin): return HttpResponseRedirect(".") + def _get_calculated_years_for_exp_date(self, obj, extension_period: int = 1): + """Given the current date, an extension period, and a registry_expiration_date + on the domain object, calculate the number of years needed to extend the + current expiration date by the extension period. + """ + # Get the date we want to update to + desired_date = self._get_current_date() + relativedelta(years=extension_period) + + # Grab the current expiration date + try: + exp_date = obj.registry_expiration_date + except KeyError: + # if no expiration date from registry, set it to today + logger.warning("current expiration date not set; setting to today") + exp_date = self._get_current_date() + + # If the expiration date is super old (2020, for example), we need to + # "catch up" to the current year, so we add the difference. + # If both years match, then lets just proceed as normal. + calculated_exp_date = exp_date + relativedelta(years=extension_period) + + year_difference = desired_date.year - exp_date.year + + years = extension_period + if desired_date > calculated_exp_date: + # Max probably isn't needed here (no code flow), but it guards against negative and 0. + # In both of those cases, we just want to extend by the extension_period. + years = max(extension_period, year_difference) + + return years + # Workaround for unit tests, as we cannot mock date directly. # it is immutable. Rather than dealing with a convoluted workaround, # lets wrap this in a function. diff --git a/src/registrar/assets/sass/_theme/_admin.scss b/src/registrar/assets/sass/_theme/_admin.scss index d238c7c54..ccbbeaa15 100644 --- a/src/registrar/assets/sass/_theme/_admin.scss +++ b/src/registrar/assets/sass/_theme/_admin.scss @@ -275,17 +275,24 @@ h1, h2, h3, } } -.cancel-extend-button{ - background-color: var(--delete-button-bg) !important; +input.admin-confirm-button { + text-transform: none; } -input.admin-confirm-button{ - text-transform: none !important; -} - - // Button groups in /admin incorrectly have bullets. // Remove that! -.usa-modal__footer .usa-button-group__item{ +.usa-modal__footer .usa-button-group__item { list-style-type: none; +} + +@include at-media(tablet) { + .button-list-mobile { + display: contents !important; + } +} + +@include at-media(mobile) { + .button-list-mobile { + display: contents !important; + } } \ No newline at end of file diff --git a/src/registrar/templates/django/admin/domain_change_form.html b/src/registrar/templates/django/admin/domain_change_form.html index 8388d8768..57e073f17 100644 --- a/src/registrar/templates/django/admin/domain_change_form.html +++ b/src/registrar/templates/django/admin/domain_change_form.html @@ -66,15 +66,14 @@
This will extend the expiration date by one year. -
-
- Domain: {{ original.name }}
- New expiration date: {{ extended_expiration_date }}
- {{test}}
+ This action cannot be undone.
- This action cannot be undone.
+ Domain: {{ original.name }}
+
+ New expiration date: {{ extended_expiration_date }}
+ {{test}}