Skip to content

Commit

Permalink
Add new superform everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
rmarow committed Sep 28, 2023
1 parent 99df535 commit 8de1a98
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from flask import Blueprint, Request, redirect, render_template, request, url_for
from flask_wtf import FlaskForm
from usaon_vvta_survey.util.superform import SuperForm
from wtforms import FormField

from usaon_vta_survey import db
Expand All @@ -14,7 +14,7 @@


def _update_super_form(
super_form: type[FlaskForm],
super_form: type[SuperForm],
/,
*,
societal_benefit_area_id: int | None,
Expand Down Expand Up @@ -150,7 +150,7 @@ def view_response_application_societal_benefit_area_relationships(survey_id: str
societal_benefit_area_id, application_id = _request_args(request)
survey = db.get_or_404(Survey, survey_id)

class SuperForm(FlaskForm):
class ApplicationSocietalBenefitAreaForm(SuperForm):
"""Combine all necessary forms into one super-form.
NOTE: Additional class attributes are added dynamically below.
Expand All @@ -176,7 +176,7 @@ class SuperForm(FlaskForm):
)

_update_super_form(
SuperForm,
ApplicationSocietalBenefitAreaForm,
societal_benefit_area_id=societal_benefit_area_id,
application_id=application_id,
)
Expand All @@ -200,8 +200,7 @@ class SuperForm(FlaskForm):

if request.method == 'POST':
limit_response_editors()
form = SuperForm(request.form, obj=form_obj)
form.relationship._fields.pop('csrf_token')
form = ApplicationSocietalBenefitAreaForm(request.form, obj=form_obj)

if form.validate():
# Add only submitted sub-forms into the db session
Expand All @@ -227,7 +226,7 @@ class SuperForm(FlaskForm):

return redirect(url_for('sba.view_response_sbas', survey_id=survey.id))

form = SuperForm(obj=form_obj)
form = ApplicationSocietalBenefitAreaForm(obj=form_obj)
return render_template(
'response/relationships/application_societal_benefit_area.html',
form=form,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ def view_response_data_product_application_relationships(survey_id: str):
data_product_id, application_id = _request_args(request)
survey = db.get_or_404(Survey, survey_id)

# class SuperForm(FlaskForm):
class ResponseDataProductApplicationForm(SuperForm):
"""Combine all necessary forms into one super-form.
Expand All @@ -150,8 +149,7 @@ class ResponseDataProductApplicationForm(SuperForm):

relationship = FormField(FORMS_BY_MODEL[ResponseDataProductApplication])

# looking for submit button at this point
# breakpoint()
# submit_button present on dir(SuperForm)
response_data_product_application = _response_data_product_application(
data_product_id=data_product_id,
application_id=application_id,
Expand All @@ -177,6 +175,7 @@ class ResponseDataProductApplicationForm(SuperForm):
data_product_id=data_product_id,
application_id=application_id,
)
# submit_button present in 2 places
# breakpoint()

form_obj: dict[
Expand All @@ -189,11 +188,13 @@ class ResponseDataProductApplicationForm(SuperForm):
'relationship': response_data_product_application,
}

# breakpoint()
if request.method == 'POST':
# currently cant get here because we have no submit button
limit_response_editors()
form = ResponseDataProductApplicationForm(request.form, obj=form_obj)

# breakpoint()
if form.validate():
# Add only submitted sub-forms into the db session
for key, obj in form_obj.items():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from flask import Blueprint, Request, redirect, render_template, request, url_for
from flask_wtf import FlaskForm
from usaon_vvta_survey.util.superform import SuperForm
from wtforms import FormField

from usaon_vta_survey import db
Expand All @@ -14,7 +14,7 @@


def _update_super_form(
super_form: type[FlaskForm],
super_form: type[SuperForm],
/,
*,
data_product_id: int | None,
Expand Down Expand Up @@ -145,7 +145,7 @@ def view_response_observing_system_data_product_relationships(survey_id: str):
data_product_id, observing_system_id = _request_args(request)
survey = db.get_or_404(Survey, survey_id)

class SuperForm(FlaskForm):
class ObservingSystemDataProductForm(SuperForm):
"""Combine all necessary forms into one super-form.
NOTE: Additional class attributes are added dynamically below.
Expand All @@ -169,7 +169,7 @@ class SuperForm(FlaskForm):
)

_update_super_form(
SuperForm,
ObservingSystemDataProductForm,
observing_system_id=observing_system_id,
data_product_id=data_product_id,
)
Expand All @@ -193,7 +193,7 @@ class SuperForm(FlaskForm):

if request.method == 'POST':
limit_response_editors()
form = SuperForm(request.form, obj=form_obj)
form = ObservingSystemDataProductForm(request.form, obj=form_obj)

if form.validate():
# Add only submitted sub-forms into the db session
Expand Down Expand Up @@ -221,7 +221,7 @@ class SuperForm(FlaskForm):
url_for('data_product.view_response_data_products', survey_id=survey.id)
)

form = SuperForm(obj=form_obj)
form = ObservingSystemDataProductForm(obj=form_obj)
return render_template(
'response/relationships/observing_system_data_product.html',
form=form,
Expand Down

0 comments on commit 8de1a98

Please sign in to comment.