From 2891391382d9ca227f0d43960df851ea1d949b4a Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Fri, 2 Feb 2024 15:33:42 -0700 Subject: [PATCH 01/55] Backend stuff --- src/registrar/admin.py | 21 +++++++++++++++++++++ src/registrar/models/domain.py | 19 +++++++++++-------- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/registrar/admin.py b/src/registrar/admin.py index 77d827d05..8e2f7af68 100644 --- a/src/registrar/admin.py +++ b/src/registrar/admin.py @@ -1,3 +1,4 @@ +from datetime import date import logging from django import forms from django.db.models.functions import Concat @@ -1133,6 +1134,7 @@ def response_change(self, request, obj): "_edit_domain": self.do_edit_domain, "_delete_domain": self.do_delete_domain, "_get_status": self.do_get_status, + "_extend_expiration_date": self.do_extend_expiration_date } # Check which action button was pressed and call the corresponding function @@ -1143,6 +1145,25 @@ def response_change(self, request, obj): # If no matching action button is found, return the super method return super().response_change(request, obj) + def do_extend_expiration_date(self, request, obj): + if not isinstance(obj, Domain): + # Could be problematic if the type is similar, + # but not the same (same field/func names). + # We do not want to accidentally delete records. + self.message_user(request, "Object is not of type Domain", messages.ERROR) + return None + try: + obj.renew_domain(date_to_extend=date.today()) + 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}", + ) + return HttpResponseRedirect(".") + def do_delete_domain(self, request, obj): if not isinstance(obj, Domain): # Could be problematic if the type is similar, diff --git a/src/registrar/models/domain.py b/src/registrar/models/domain.py index 27a8364bc..84f451f56 100644 --- a/src/registrar/models/domain.py +++ b/src/registrar/models/domain.py @@ -239,22 +239,25 @@ def registry_expiration_date(self, ex_date: date): To update the expiration date, use renew_domain method.""" raise NotImplementedError() - def renew_domain(self, length: int = 1, unit: epp.Unit = epp.Unit.YEAR): + def renew_domain(self, length: int = 1, date_to_extend = None, unit: epp.Unit = epp.Unit.YEAR): """ Renew the domain to a length and unit of time relative to the current expiration date. Default length and unit of time are 1 year. """ - # if no expiration date from registry, set to today - try: - cur_exp_date = self.registry_expiration_date - except KeyError: - logger.warning("current expiration date not set; setting to today") - cur_exp_date = date.today() + + # If no date is specified, grab the registry_expiration_date + if date_to_extend is None: + try: + date_to_extend = self.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") + date_to_extend = date.today() # create RenewDomain request - request = commands.RenewDomain(name=self.name, cur_exp_date=cur_exp_date, period=epp.Period(length, unit)) + request = commands.RenewDomain(name=self.name, cur_exp_date=date_to_extend, period=epp.Period(length, unit)) try: # update expiration date in registry, and set the updated From b3401d8bfc492b1b5d09f7c62b028107df274d18 Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Fri, 2 Feb 2024 15:39:51 -0700 Subject: [PATCH 02/55] Basic button --- src/registrar/admin.py | 3 ++- src/registrar/templates/django/admin/domain_change_form.html | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/registrar/admin.py b/src/registrar/admin.py index 8e2f7af68..0571a1743 100644 --- a/src/registrar/admin.py +++ b/src/registrar/admin.py @@ -1134,7 +1134,7 @@ def response_change(self, request, obj): "_edit_domain": self.do_edit_domain, "_delete_domain": self.do_delete_domain, "_get_status": self.do_get_status, - "_extend_expiration_date": self.do_extend_expiration_date + "_extend_expiration_date": self.do_extend_expiration_date, } # Check which action button was pressed and call the corresponding function @@ -1152,6 +1152,7 @@ def do_extend_expiration_date(self, request, obj): # We do not want to accidentally delete records. self.message_user(request, "Object is not of type Domain", messages.ERROR) return None + try: obj.renew_domain(date_to_extend=date.today()) except Exception as err: diff --git a/src/registrar/templates/django/admin/domain_change_form.html b/src/registrar/templates/django/admin/domain_change_form.html index c4461d07f..bf2be1754 100644 --- a/src/registrar/templates/django/admin/domain_change_form.html +++ b/src/registrar/templates/django/admin/domain_change_form.html @@ -5,6 +5,7 @@
+ This action will extend the expiration date by a year. +
+- This action will extend the expiration date by a year. -
-- This action will extend the expiration date by a year. -
-+ This action will extend the expiration date by a year. +
+- This action will extend the expiration date by a year. -
-+ This action will extend the expiration date by a year. +
+- This action will extend the expiration date by a year. -
-+ This action will extend the expiration date by a year. +
+From 49a8360675ceee27393e3ba865a70b92bc3c93ff Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Mon, 12 Feb 2024 08:42:49 -0700 Subject: [PATCH 33/55] Update modal text --- src/registrar/admin.py | 8 ++++++++ .../django/admin/domain_change_form.html | 15 ++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/registrar/admin.py b/src/registrar/admin.py index 393cdf23d..292ecf01f 100644 --- a/src/registrar/admin.py +++ b/src/registrar/admin.py @@ -1076,6 +1076,14 @@ def organization_type(self, obj): # Table ordering ordering = ["name"] + 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) + return super().changeform_view(request, object_id, form_url, extra_context) + def export_data_type(self, request): # match the CSV example with all the fields response = HttpResponse(content_type="text/csv") diff --git a/src/registrar/templates/django/admin/domain_change_form.html b/src/registrar/templates/django/admin/domain_change_form.html index d0fd46800..b48f04e60 100644 --- a/src/registrar/templates/django/admin/domain_change_form.html +++ b/src/registrar/templates/django/admin/domain_change_form.html @@ -70,8 +70,17 @@
- This action will extend the expiration date by a year. +
+ This will extend the expiration date by one year. +
+
+ Domain: {{ original.name }}
+
+ New expiration date: {{ extended_expiration_date }}
+ {{test}}
+
+ This action cannot be undone.