added renew method

This commit is contained in:
asaki222 2024-12-30 12:44:52 -05:00
parent 8b9eb93b68
commit e23d81f7e7
No known key found for this signature in database
GPG key ID: C51913A3A09FDC03
2 changed files with 11 additions and 6 deletions

View file

@ -322,28 +322,32 @@ class Domain(TimeStampedModel, DomainHelper):
""" """
# If no date is specified, grab the registry_expiration_date # If no date is specified, grab the registry_expiration_date
print("checking if there is a date")
try: try:
exp_date = self.registry_expiration_date exp_date = self.registry_expiration_date
except KeyError: except KeyError:
# if no expiration date from registry, set it to today # if no expiration date from registry, set it to today
logger.warning("current expiration date not set; setting to today") logger.warning("current expiration date not set; setting to today")
exp_date = date.today() exp_date = date.today()
print("we got the date", exp_date)
# create RenewDomain request # create RenewDomain request
request = commands.RenewDomain(name=self.name, cur_exp_date=exp_date, period=epp.Period(length, unit)) request = commands.RenewDomain(name=self.name, cur_exp_date=exp_date, period=epp.Period(length, unit))
try: try:
# update expiration date in registry, and set the updated # update expiration date in registry, and set the updated
# expiration date in the registrar, and in the cache # expiration date in the registrar, and in the cache
print("we are in the second try")
self._cache["ex_date"] = registry.send(request, cleaned=True).res_data[0].ex_date self._cache["ex_date"] = registry.send(request, cleaned=True).res_data[0].ex_date
self.expiration_date = self._cache["ex_date"] self.expiration_date = self._cache["ex_date"]
self.save() self.save()
except RegistryError as err: except RegistryError as err:
# if registry error occurs, log the error, and raise it as well # if registry error occurs, log the error, and raise it as well
print("registry error")
logger.error(f"registry error renewing domain: {err}") logger.error(f"registry error renewing domain: {err}")
raise (err) raise (err)
except Exception as e: except Exception as e:
# exception raised during the save to registrar # exception raised during the save to registrar
print("this is the last error")
logger.error(f"error updating expiration date in registrar: {e}") logger.error(f"error updating expiration date in registrar: {e}")
raise (e) raise (e)

View file

@ -381,12 +381,13 @@ class DomainRenewalView(DomainBaseView):
print("*** Checkbox is acknowledged") print("*** Checkbox is acknowledged")
if "submit_button" in request.POST: if "submit_button" in request.POST:
print("*** Submit button clicked") print("*** Submit button clicked")
updated_expiration = domain.update_expiration(success=True) # updated_expiration = domain.update_expiration(success=True)
print("*** Updated expiration result:", updated_expiration) # print("*** Updated expiration result:", updated_expiration)
try:
if updated_expiration is True: domain.renew_domain()
messages.success(request, "This domain has been renewed for one year") messages.success(request, "This domain has been renewed for one year")
else: except Exception as e:
print(f'An error occured: {e}')
messages.error(request, "This domain has not been renewed") messages.error(request, "This domain has not been renewed")
return HttpResponseRedirect(reverse("domain", kwargs={"pk": pk})) return HttpResponseRedirect(reverse("domain", kwargs={"pk": pk}))