mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-06-02 02:28:32 +02:00
wip
This commit is contained in:
parent
0cada58c23
commit
55f9792b32
4 changed files with 60 additions and 4 deletions
|
@ -39,9 +39,11 @@ class RegistrarForm(forms.Form):
|
|||
|
||||
Does nothing if form is not valid.
|
||||
"""
|
||||
logger.info(f"to_database called on {self.__class__.__name__}")
|
||||
if not self.is_valid():
|
||||
return
|
||||
for name, value in self.cleaned_data.items():
|
||||
logger.info(f"{name}: {value}")
|
||||
setattr(obj, name, value)
|
||||
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):
|
||||
first_name = forms.CharField(
|
||||
label="First name / given name",
|
||||
|
|
|
@ -835,6 +835,17 @@ class DomainApplication(TimeStampedModel):
|
|||
"""Show this step if the other contacts are blank."""
|
||||
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]:
|
||||
"""Is this application for a federal agency?
|
||||
|
||||
|
|
|
@ -17,9 +17,13 @@
|
|||
{% endblock %}
|
||||
|
||||
{% block form_fields %}
|
||||
{{ forms.0.management_form }}
|
||||
{# forms.0 is a formset and this iterates over its forms #}
|
||||
{% for form in forms.0.forms %}
|
||||
|
||||
{{ forms.0 }}
|
||||
{# 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">
|
||||
<legend>
|
||||
<h2>Organization contact {{ forloop.counter }} (optional)</h2>
|
||||
|
@ -42,6 +46,10 @@
|
|||
</fieldset>
|
||||
{% 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">
|
||||
<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>
|
||||
|
|
|
@ -373,6 +373,9 @@ class ApplicationWizard(ApplicationWizardPermissionView, TemplateView):
|
|||
|
||||
def post(self, request, *args, **kwargs) -> HttpResponse:
|
||||
"""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 self.__class__ == ApplicationWizard:
|
||||
return self.goto(self.steps.first)
|
||||
|
@ -481,7 +484,24 @@ class YourContact(ApplicationWizard):
|
|||
|
||||
class OtherContacts(ApplicationWizard):
|
||||
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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue