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,96 +22,79 @@
<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" %}
{% include "includes/required_fields.html" %}
<form class="usa-form usa-form--extra-large" method="post" novalidate id="form-container">
{% csrf_token %}
{{ formset.management_form }}
<form class="usa-form usa-form--extra-large" method="post" novalidate id="form-container">
{% csrf_token %}
{{ formset.management_form }}
{% for form in formset %}
<fieldset class="ds-record">
{% for form in formset %}
<fieldset class="ds-record">
<legend class="sr-only">DS Data record {{forloop.counter}}</legend>
<legend class="sr-only">DS Data record {{forloop.counter}}</legend>
<h2 class="margin-top-0">DS Data record {{forloop.counter}}</h2>
<h2 class="margin-top-0">DS Data record {{forloop.counter}}</h2>
<div class="grid-row grid-gap-2 flex-end">
<div class="tablet:grid-col-4">
{% with attr_required=True add_group_class="usa-form-group--unstyled-error" %}
{% input_with_errors form.key_tag %}
{% endwith %}
</div>
<div class="tablet:grid-col-4">
{% with attr_required=True add_group_class="usa-form-group--unstyled-error" %}
{% input_with_errors form.algorithm %}
{% endwith %}
</div>
<div class="tablet:grid-col-4">
{% with attr_required=True add_group_class="usa-form-group--unstyled-error" %}
{% input_with_errors form.digest_type %}
{% endwith %}
</div>
<div class="grid-row grid-gap-2 flex-end">
<div class="tablet:grid-col-4">
{% with attr_required=True add_group_class="usa-form-group--unstyled-error" %}
{% input_with_errors form.key_tag %}
{% endwith %}
</div>
<div class="grid-row">
<div class="grid-col">
{% with attr_required=True add_group_class="usa-form-group--unstyled-error" %}
{% input_with_errors form.digest %}
{% endwith %}
</div>
<div class="tablet:grid-col-4">
{% with attr_required=True add_group_class="usa-form-group--unstyled-error" %}
{% input_with_errors form.algorithm %}
{% endwith %}
</div>
<div class="grid-row margin-top-1">
<div class="grid-col">
<button type="button" class="usa-button usa-button--unstyled display-block float-right-tablet delete-record">
<svg class="usa-icon" aria-hidden="true" focusable="false" role="img" width="24" height="24">
<use xlink:href="{%static 'img/sprite.svg'%}#delete"></use>
</svg><span class="margin-left-05">Delete</span>
</button>
</div>
<div class="tablet:grid-col-4">
{% with attr_required=True add_group_class="usa-form-group--unstyled-error" %}
{% input_with_errors form.digest_type %}
{% endwith %}
</div>
</div>
</fieldset>
{% endfor %}
<div class="grid-row">
<div class="grid-col">
{% with attr_required=True add_group_class="usa-form-group--unstyled-error" %}
{% input_with_errors form.digest %}
{% endwith %}
</div>
</div>
<button type="button" class="usa-button usa-button--unstyled display-block margin-bottom-2" id="add-ds-form">
<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>
<div class="grid-row margin-top-1">
<div class="grid-col">
<button type="button" class="usa-button usa-button--unstyled display-block float-right-tablet delete-record">
<svg class="usa-icon" aria-hidden="true" focusable="false" role="img" width="24" height="24">
<use xlink:href="{%static 'img/sprite.svg'%}#delete"></use>
</svg><span class="margin-left-05">Delete</span>
</button>
</div>
</div>
<button
id="save-ds-data"
type="submit"
class="usa-button"
>Save
</button>
<!-- </form>
</fieldset>
{% endfor %}
<form aria-label="form to undo changes to the DS records"> -->
<button
type="submit"
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
</button>
</form>
{% comment %} {% endif %} {% endcomment %}
<button type="button" class="usa-button usa-button--unstyled display-block margin-bottom-2" id="add-ds-form">
<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>
<button
id="save-ds-data"
type="submit"
class="usa-button"
>Save
</button>
<button
type="submit"
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
</button>
</form>
{% if trigger_modal %}
<a

View file

@ -324,16 +324,6 @@ class DomainDsDataView(DomainPermissionView, FormMixin):
context = super().get_context_data(**kwargs)
# 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
@ -342,30 +332,22 @@ class DomainDsDataView(DomainPermissionView, FormMixin):
self.object = self.get_object()
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)