From 8de1a98dfcb3130e9101cf7a92e6a3ef6f70411d Mon Sep 17 00:00:00 2001 From: Robyn Marowitz Date: Thu, 28 Sep 2023 15:29:08 -0600 Subject: [PATCH] Add new superform everywhere --- .../application_societal_benefit_area.py | 13 ++++++------- .../relationships/data_product_application.py | 7 ++++--- .../relationships/observing_system_data_product.py | 12 ++++++------ 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/usaon_vta_survey/routes/response/relationships/application_societal_benefit_area.py b/usaon_vta_survey/routes/response/relationships/application_societal_benefit_area.py index 93b8442b..06b6ac08 100644 --- a/usaon_vta_survey/routes/response/relationships/application_societal_benefit_area.py +++ b/usaon_vta_survey/routes/response/relationships/application_societal_benefit_area.py @@ -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 @@ -14,7 +14,7 @@ def _update_super_form( - super_form: type[FlaskForm], + super_form: type[SuperForm], /, *, societal_benefit_area_id: int | None, @@ -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. @@ -176,7 +176,7 @@ class SuperForm(FlaskForm): ) _update_super_form( - SuperForm, + ApplicationSocietalBenefitAreaForm, societal_benefit_area_id=societal_benefit_area_id, application_id=application_id, ) @@ -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 @@ -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, diff --git a/usaon_vta_survey/routes/response/relationships/data_product_application.py b/usaon_vta_survey/routes/response/relationships/data_product_application.py index a2d32dce..7423a136 100644 --- a/usaon_vta_survey/routes/response/relationships/data_product_application.py +++ b/usaon_vta_survey/routes/response/relationships/data_product_application.py @@ -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. @@ -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, @@ -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[ @@ -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(): diff --git a/usaon_vta_survey/routes/response/relationships/observing_system_data_product.py b/usaon_vta_survey/routes/response/relationships/observing_system_data_product.py index ce5ace68..8f522dd6 100644 --- a/usaon_vta_survey/routes/response/relationships/observing_system_data_product.py +++ b/usaon_vta_survey/routes/response/relationships/observing_system_data_product.py @@ -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 @@ -14,7 +14,7 @@ def _update_super_form( - super_form: type[FlaskForm], + super_form: type[SuperForm], /, *, data_product_id: int | None, @@ -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. @@ -169,7 +169,7 @@ class SuperForm(FlaskForm): ) _update_super_form( - SuperForm, + ObservingSystemDataProductForm, observing_system_id=observing_system_id, data_product_id=data_product_id, ) @@ -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 @@ -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,