working wip

This commit is contained in:
David Kennedy 2023-10-23 18:15:48 -04:00
parent 8bf2432b15
commit be00e8249c
No known key found for this signature in database
GPG key ID: 6528A5386E66B96B
3 changed files with 35 additions and 8 deletions

View file

@ -100,12 +100,12 @@
class="usa-button"
>Save
</button>
</form>
<!-- </form>
<form aria-label="form to undo changes to the DS records">
<form aria-label="form to undo changes to the DS records"> -->
<button
type="submit"
class="usa-button usa-button--outline btn-cancel"
class="usa-button usa-button--outline"
name="btn-cancel-click"
aria-label="Reset the data in the DS records to the registry state (undo changes)"
>Cancel

View file

@ -53,7 +53,7 @@
<form method="post">
{% csrf_token %}
<button
type="button"
type="submit"
class="usa-button usa-modal__close"
aria-label="Close this window"
name="btn-cancel-click"

View file

@ -10,6 +10,7 @@ import logging
from django.contrib import messages
from django.contrib.messages.views import SuccessMessageMixin
from django.db import IntegrityError
from django.http import HttpResponseRedirect
from django.shortcuts import redirect
from django.template import RequestContext
from django.urls import reverse
@ -342,20 +343,43 @@ class DomainDsDataView(DomainPermissionView, FormMixin):
formset = self.get_form()
override = False
# log the context and the formset
logger.info("==================FORMSET================")
logger.info(formset)
logger.info("=======>>>>>>CONTEXT<<<<<<===========")
logger.info(self.get_context_data(**kwargs))
logger.info("========^^^^^^^CONTEXT^^^^^^^^========")
# This is called by the form cancel button, and also by the modal's X and cancel buttons
if "btn-cancel-click" in request.POST:
return redirect("domain-dns-dnssec-dsdata", {"formset": formset}, RequestContext(request))
logger.info(">>>>>>>clicked cancel")
url = self.get_success_url()
return HttpResponseRedirect(url)
#return reverse("domain-dns-dnssec-dsdata", kwargs={"pk": self.object.pk})
# return redirect("domain-dns-dnssec-dsdata", kwargs={"pk": self.object.pk})
if "disable-override-click" in request.POST:
logger.info(">>>>>>>>clicked disable")
override = True
if len(formset) == 0 and formset.initial == [{}] and override == False:
if len(formset) == 0 and formset.initial != [{}] and override == False:
# trigger the modal
context = self.get_context_data(**kwargs)
logger.info(">>>>>>>>clicked save")
context = super().get_context_data(form=formset)
context["trigger_modal"] = True
# Create HTML for the modal button
modal_button = (
'<button type="submit" '
'class="usa-button usa-button--secondary" '
'name="disable-override-click">Disable DNSSEC</button>'
)
# context to back out of a broken form on all fields delete
context["modal_button"] = modal_button
return self.render_to_response(context)
if formset.is_valid():
if formset.is_valid() or override:
return self.form_valid(formset)
else:
return self.form_invalid(formset)
@ -363,6 +387,7 @@ class DomainDsDataView(DomainPermissionView, FormMixin):
def form_valid(self, formset, **kwargs):
"""The formset is valid, perform something with it."""
logger.info("form_valid is called")
# Set the dnssecdata from the formset
dnssecdata = extensions.DNSSECExtension()
@ -386,7 +411,9 @@ class DomainDsDataView(DomainPermissionView, FormMixin):
pass
domain = self.get_object()
try:
logger.debug("attempting to set dnssecdata")
domain.dnssecdata = dnssecdata
logger.debug("successfully set the dnssecdata")
except RegistryError as err:
errmsg = "Error updating DNSSEC data in the registry."
logger.error(errmsg)