This commit is contained in:
David Kennedy 2024-01-02 18:31:36 -05:00
parent 0cada58c23
commit 55f9792b32
No known key found for this signature in database
GPG key ID: 6528A5386E66B96B
4 changed files with 60 additions and 4 deletions

View file

@ -39,9 +39,11 @@ class RegistrarForm(forms.Form):
Does nothing if form is not valid. Does nothing if form is not valid.
""" """
logger.info(f"to_database called on {self.__class__.__name__}")
if not self.is_valid(): if not self.is_valid():
return return
for name, value in self.cleaned_data.items(): for name, value in self.cleaned_data.items():
logger.info(f"{name}: {value}")
setattr(obj, name, value) setattr(obj, name, value)
obj.save() obj.save()
@ -547,6 +549,21 @@ class YourContactForm(RegistrarForm):
) )
class OtherContactsYesNoForm(RegistrarForm):
has_other_contacts = forms.TypedChoiceField(
choices=(
(True, "Yes, I can name other employees."),
(False, "No (We'll ask you to explain why).")
),
widget=forms.RadioSelect
)
def is_valid(self):
val = super().is_valid()
logger.info(f"yes no form is valid = {val}")
return val
class OtherContactsForm(RegistrarForm): class OtherContactsForm(RegistrarForm):
first_name = forms.CharField( first_name = forms.CharField(
label="First name / given name", label="First name / given name",

View file

@ -835,6 +835,17 @@ class DomainApplication(TimeStampedModel):
"""Show this step if the other contacts are blank.""" """Show this step if the other contacts are blank."""
return not self.other_contacts.exists() return not self.other_contacts.exists()
def has_other_contacts(self) -> bool:
"""Does this application have other contacts listed?"""
return self.other_contacts.exists()
# def __setattr__(self, name, value):
# # Check if the attribute exists in the class
# if not hasattr(self, name):
# logger.info(f"{self.__class__.__name__} object has no attribute '{name}'")
# # If the attribute exists, set its value
# super().__setattr__(name, value)
def is_federal(self) -> Union[bool, None]: def is_federal(self) -> Union[bool, None]:
"""Is this application for a federal agency? """Is this application for a federal agency?

View file

@ -17,9 +17,13 @@
{% endblock %} {% endblock %}
{% block form_fields %} {% block form_fields %}
{{ forms.0.management_form }}
{# forms.0 is a formset and this iterates over its forms #} {{ forms.0 }}
{% for form in forms.0.forms %} {# forms.0 is a small yes/no form that toggles the visibility of "other contact" formset #}
{{ forms.1.management_form }}
{# forms.1 is a formset and this iterates over its forms #}
{% for form in forms.1.forms %}
<fieldset class="usa-fieldset"> <fieldset class="usa-fieldset">
<legend> <legend>
<h2>Organization contact {{ forloop.counter }} (optional)</h2> <h2>Organization contact {{ forloop.counter }} (optional)</h2>
@ -42,6 +46,10 @@
</fieldset> </fieldset>
{% endfor %} {% endfor %}
{% with attr_maxlength=1000 %}
{% input_with_errors forms.2.no_other_contacts_rationale %}
{% endwith %}
<button type="submit" name="submit_button" value="save" class="usa-button usa-button--unstyled"> <button type="submit" name="submit_button" value="save" class="usa-button usa-button--unstyled">
<svg class="usa-icon" aria-hidden="true" focusable="false" role="img" width="24" height="24"> <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> <use xlink:href="{%static 'img/sprite.svg'%}#add_circle"></use>

View file

@ -373,6 +373,9 @@ class ApplicationWizard(ApplicationWizardPermissionView, TemplateView):
def post(self, request, *args, **kwargs) -> HttpResponse: def post(self, request, *args, **kwargs) -> HttpResponse:
"""This method handles POST requests.""" """This method handles POST requests."""
# Log the keys and values of request.POST
for key, value in request.POST.items():
logger.info("Key: %s, Value: %s", key, value)
# if accessing this class directly, redirect to the first step # if accessing this class directly, redirect to the first step
if self.__class__ == ApplicationWizard: if self.__class__ == ApplicationWizard:
return self.goto(self.steps.first) return self.goto(self.steps.first)
@ -481,7 +484,24 @@ class YourContact(ApplicationWizard):
class OtherContacts(ApplicationWizard): class OtherContacts(ApplicationWizard):
template_name = "application_other_contacts.html" template_name = "application_other_contacts.html"
forms = [forms.OtherContactsFormSet] forms = [forms.OtherContactsYesNoForm, forms.OtherContactsFormSet, forms.NoOtherContactsForm]
def post(self, request, *args, **kwargs) -> HttpResponse:
parent_form = forms.OtherContactsYesNoForm(request.POST)
other_contacts_formset = forms.OtherContactsFormSet(request.POST, request.FILES)
no_other_contacts_form = forms.NoOtherContactsForm(request.POST)
logger.info("in post")
has_other_contacts_selected = parent_form.data.get('other_contacts-has_other_contacts')
logger.info(f"has other contacts = {has_other_contacts_selected}")
if parent_form.is_valid():
if has_other_contacts_selected:
logger.info("has other contacts")
other_contacts_formset.data = {}
else:
logger.info("doesn't have other contacts")
no_other_contacts_form.data = {}
super().post(request, *args, **kwargs)
class NoOtherContacts(ApplicationWizard): class NoOtherContacts(ApplicationWizard):