mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-19 10:59:21 +02:00
started delete, added can_delete to form and template, adding logging to find source of errors
This commit is contained in:
parent
13151c9368
commit
eae2eda4f2
3 changed files with 15 additions and 0 deletions
|
@ -141,6 +141,7 @@ class RegistrarFormSet(forms.BaseFormSet):
|
|||
"""
|
||||
if not self.is_valid():
|
||||
return
|
||||
logger.info(obj)
|
||||
obj.save()
|
||||
|
||||
query = getattr(obj, join).order_by("created_at").all() # order matters
|
||||
|
@ -162,6 +163,8 @@ class RegistrarFormSet(forms.BaseFormSet):
|
|||
for db_obj, post_data in zip_longest(query, self.forms, fillvalue=None):
|
||||
cleaned = post_data.cleaned_data if post_data is not None else {}
|
||||
|
||||
logger.info(post_data)
|
||||
logger.info(cleaned)
|
||||
# matching database object exists, update it
|
||||
if db_obj is not None and cleaned:
|
||||
if should_delete(cleaned):
|
||||
|
@ -708,6 +711,7 @@ class BaseOtherContactsFormSet(RegistrarFormSet):
|
|||
return all(empty) or self.formset_data_marked_for_deletion
|
||||
|
||||
def to_database(self, obj: DomainApplication):
|
||||
logger.info("in to_database for BaseOtherContactsFormSet")
|
||||
self._to_database(obj, self.JOIN, self.REVERSE_JOINS, self.should_delete, self.pre_update, self.pre_create)
|
||||
|
||||
@classmethod
|
||||
|
@ -737,6 +741,7 @@ OtherContactsFormSet = forms.formset_factory(
|
|||
extra=0,
|
||||
absolute_max=1500, # django default; use `max_num` to limit entries
|
||||
min_num=1,
|
||||
can_delete=True,
|
||||
validate_min=True,
|
||||
formset=BaseOtherContactsFormSet,
|
||||
)
|
||||
|
|
|
@ -39,6 +39,10 @@
|
|||
<h2>Organization contact {{ forloop.counter }} (optional)</h2>
|
||||
</legend>
|
||||
|
||||
{% if forms.1.can_delete %}
|
||||
{{ form.DELETE }}
|
||||
{% endif %}
|
||||
|
||||
{% input_with_errors form.first_name %}
|
||||
|
||||
{% input_with_errors form.middle_name %}
|
||||
|
|
|
@ -277,6 +277,7 @@ class ApplicationWizard(ApplicationWizardPermissionView, TemplateView):
|
|||
for form in forms:
|
||||
data = form.from_database(self.application) if self.has_pk() else None
|
||||
if use_post:
|
||||
logger.info("about to instantiate form ")
|
||||
instantiated.append(form(self.request.POST, **kwargs))
|
||||
elif use_db:
|
||||
instantiated.append(form(data, **kwargs))
|
||||
|
@ -389,6 +390,7 @@ class ApplicationWizard(ApplicationWizardPermissionView, TemplateView):
|
|||
return self.goto(self.steps.first)
|
||||
|
||||
forms = self.get_forms(use_post=True)
|
||||
logger.info("after geting forms")
|
||||
if self.is_valid(forms):
|
||||
# always save progress
|
||||
self.save(forms)
|
||||
|
@ -506,10 +508,14 @@ class OtherContacts(ApplicationWizard):
|
|||
if other_contacts_yes_no_form.is_valid():
|
||||
# test for has_contacts
|
||||
if other_contacts_yes_no_form.cleaned_data.get("has_other_contacts"):
|
||||
logger.info("has other contacts")
|
||||
# mark the no_other_contacts_form for deletion
|
||||
no_other_contacts_form.mark_form_for_deletion()
|
||||
logger.info("after marking for deletion")
|
||||
# test that the other_contacts_forms and no_other_contacts_forms are valid
|
||||
all_forms_valid = all(form.is_valid() for form in forms[1:])
|
||||
logger.info("after checking forms for validity")
|
||||
logger.info(f"all forms valid = {all_forms_valid}")
|
||||
else:
|
||||
# mark the other_contacts_forms formset for deletion
|
||||
other_contacts_forms.mark_formset_for_deletion()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue