cleaned up working code for review

This commit is contained in:
David Kennedy 2023-10-23 18:32:22 -04:00
parent be00e8249c
commit d50628f14d
No known key found for this signature in database
GPG key ID: 6528A5386E66B96B
2 changed files with 67 additions and 105 deletions

View file

@ -22,20 +22,6 @@
<p>Enter the values given by your DNS provider for DS Data.</p>
{% comment %} {% if not dnssec_ds_confirmed %}
<p>Required fields are marked with an asterisk (<abbr
title="required"
class="usa-hint usa-hint--required"
>*</abbr>).</p>
<form class="usa-form usa-form--large" method="post" novalidate id="form-container">
{% csrf_token %}
<button type="submit" class="usa-button usa-button--unstyled display-block" name="confirm-ds">
<svg class="usa-icon" aria-hidden="true" focusable="false" role="img" width="24" height="24">
<use xlink:href="{%static 'img/sprite.svg'%}#add_circle"></use>
</svg><span class="margin-left-05">Add new record</span>
</button>
</form>
{% else %} {% endcomment %}
{% include "includes/required_fields.html" %}
<form class="usa-form usa-form--extra-large" method="post" novalidate id="form-container">
@ -100,9 +86,7 @@
class="usa-button"
>Save
</button>
<!-- </form>
<form aria-label="form to undo changes to the DS records"> -->
<button
type="submit"
class="usa-button usa-button--outline"
@ -111,7 +95,6 @@
>Cancel
</button>
</form>
{% comment %} {% endif %} {% endcomment %}
{% if trigger_modal %}
<a

View file

@ -325,16 +325,6 @@ class DomainDsDataView(DomainPermissionView, FormMixin):
# use "formset" instead of "form" for the key
context["formset"] = context.pop("form")
# 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 context
def post(self, request, *args, **kwargs):
@ -343,29 +333,21 @@ 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:
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})
# This is called by the Disable DNSSEC modal to override
if "disable-override-click" in request.POST:
logger.info(">>>>>>>>clicked disable")
override = True
if len(formset) == 0 and formset.initial != [{}] and override == False:
# This is called when all DNSSEC data has been deleted and the
# Save button is pressed
if len(formset) == 0 and formset.initial == [{}] and override == False:
# trigger the modal
logger.info(">>>>>>>>clicked save")
# get context data from super() rather than self
# to preserve the context["form"]
context = super().get_context_data(form=formset)
context["trigger_modal"] = True
# Create HTML for the modal button
@ -387,7 +369,6 @@ 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()
@ -411,9 +392,7 @@ 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)