Rename to CacheableForm

This commit is contained in:
richard-dds
2018-11-19 14:37:24 -05:00
parent 26cd9b4cb0
commit 3215cfca32
9 changed files with 21 additions and 28 deletions

View File

@@ -2,11 +2,11 @@ from wtforms.fields.html5 import EmailField, TelField
from wtforms.fields import StringField, TextAreaField from wtforms.fields import StringField, TextAreaField
from wtforms.validators import Email, Optional from wtforms.validators import Email, Optional
from .forms import ValidatedForm from .forms import CacheableForm
from .validators import Name, PhoneNumber from .validators import Name, PhoneNumber
class CCPOReviewForm(ValidatedForm): class CCPOReviewForm(CacheableForm):
comment = TextAreaField( comment = TextAreaField(
"Instructions or comments", "Instructions or comments",
description="Provide instructions or notes for additional information that is necessary to approve the request here. The requestor may then re-submit the updated request or initiate contact outside of AT-AT if further discussion is required. <strong>This message will be shared with the person making the JEDI request.</strong>.", description="Provide instructions or notes for additional information that is necessary to approve the request here. The requestor may then re-submit the updated request or initiate contact outside of AT-AT if further discussion is required. <strong>This message will be shared with the person making the JEDI request.</strong>.",

View File

@@ -5,7 +5,7 @@ from wtforms.fields import RadioField, StringField
from wtforms.validators import Email, DataRequired, Optional from wtforms.validators import Email, DataRequired, Optional
from .fields import SelectField from .fields import SelectField
from .forms import ValidatedForm from .forms import CacheableForm
from .data import SERVICE_BRANCHES from .data import SERVICE_BRANCHES
from atst.models.user import User from atst.models.user import User
@@ -77,7 +77,7 @@ def inherit_user_field(field_name):
return inherit_field(USER_FIELDS[field_name], required=required) return inherit_field(USER_FIELDS[field_name], required=required)
class EditUserForm(ValidatedForm): class EditUserForm(CacheableForm):
first_name = inherit_user_field("first_name") first_name = inherit_user_field("first_name")
last_name = inherit_user_field("last_name") last_name = inherit_user_field("last_name")

View File

@@ -7,7 +7,7 @@ from flask_wtf.file import FileAllowed
from werkzeug.datastructures import FileStorage from werkzeug.datastructures import FileStorage
from .fields import NewlineListField, SelectField, NumberStringField from .fields import NewlineListField, SelectField, NumberStringField
from atst.forms.forms import ValidatedForm from atst.forms.forms import CacheableForm
from .data import FUNDING_TYPES from .data import FUNDING_TYPES
from .validators import DateRange from .validators import DateRange
@@ -31,7 +31,7 @@ def coerce_choice(val):
return val.value return val.value
class TaskOrderForm(ValidatedForm): class TaskOrderForm(CacheableForm):
def do_validate_number(self): def do_validate_number(self):
for field in self: for field in self:
if field.name != "task_order-number": if field.name != "task_order-number":
@@ -127,7 +127,7 @@ class TaskOrderForm(ValidatedForm):
) )
class RequestFinancialVerificationForm(ValidatedForm): class RequestFinancialVerificationForm(CacheableForm):
uii_ids = NewlineListField( uii_ids = NewlineListField(
"Unique Item Identifier (UII)s related to your application(s) if you already have them.", "Unique Item Identifier (UII)s related to your application(s) if you already have them.",
description="If you have more than one UII, place each one on a new line.", description="If you have more than one UII, place each one on a new line.",
@@ -174,7 +174,7 @@ class RequestFinancialVerificationForm(ValidatedForm):
self.uii_ids.process_data(self.uii_ids.data) self.uii_ids.process_data(self.uii_ids.data)
class FinancialVerificationForm(ValidatedForm): class FinancialVerificationForm(CacheableForm):
task_order = FormField(TaskOrderForm) task_order = FormField(TaskOrderForm)
request = FormField(RequestFinancialVerificationForm) request = FormField(RequestFinancialVerificationForm)

View File

@@ -2,7 +2,7 @@ from flask_wtf import FlaskForm
from flask import current_app, request as http_request from flask import current_app, request as http_request
class _ValidatedForm(FlaskForm): class ValidatedForm(FlaskForm):
def perform_extra_validation(self, *args, **kwargs): def perform_extra_validation(self, *args, **kwargs):
"""Performs any applicable extra validation. Must """Performs any applicable extra validation. Must
return True if the form is valid or False otherwise.""" return True if the form is valid or False otherwise."""
@@ -15,7 +15,7 @@ class _ValidatedForm(FlaskForm):
return _data return _data
class ValidatedForm(_ValidatedForm): class CacheableForm(ValidatedForm):
def __init__(self, formdata=None, **kwargs): def __init__(self, formdata=None, **kwargs):
formdata = formdata or {} formdata = formdata or {}
cached_data = current_app.form_cache.from_request(http_request) cached_data = current_app.form_cache.from_request(http_request)

View File

@@ -1,10 +1,10 @@
from wtforms.fields import TextAreaField from wtforms.fields import TextAreaField
from wtforms.validators import InputRequired from wtforms.validators import InputRequired
from .forms import ValidatedForm from .forms import CacheableForm
class InternalCommentForm(ValidatedForm): class InternalCommentForm(CacheableForm):
text = TextAreaField( text = TextAreaField(
"CCPO Internal Notes", "CCPO Internal Notes",
default="", default="",

View File

@@ -4,7 +4,7 @@ from wtforms.fields import BooleanField, RadioField, StringField, TextAreaField
from wtforms.validators import Email, Length, Optional, InputRequired, DataRequired from wtforms.validators import Email, Length, Optional, InputRequired, DataRequired
from .fields import SelectField from .fields import SelectField
from .forms import ValidatedForm from .forms import CacheableForm
from .edit_user import USER_FIELDS, inherit_field from .edit_user import USER_FIELDS, inherit_field
from .data import ( from .data import (
SERVICE_BRANCHES, SERVICE_BRANCHES,
@@ -16,7 +16,7 @@ from .validators import DateRange, IsNumber
from atst.domain.requests import Requests from atst.domain.requests import Requests
class DetailsOfUseForm(ValidatedForm): class DetailsOfUseForm(CacheableForm):
def validate(self, *args, **kwargs): def validate(self, *args, **kwargs):
if self.jedi_migration.data == "no": if self.jedi_migration.data == "no":
self.rationalization_software_systems.validators.append(Optional()) self.rationalization_software_systems.validators.append(Optional())
@@ -162,7 +162,7 @@ class DetailsOfUseForm(ValidatedForm):
) )
class InformationAboutYouForm(ValidatedForm): class InformationAboutYouForm(CacheableForm):
fname_request = inherit_field(USER_FIELDS["first_name"]) fname_request = inherit_field(USER_FIELDS["first_name"])
lname_request = inherit_field(USER_FIELDS["last_name"]) lname_request = inherit_field(USER_FIELDS["last_name"])
email_request = inherit_field(USER_FIELDS["email"]) email_request = inherit_field(USER_FIELDS["email"])
@@ -174,7 +174,7 @@ class InformationAboutYouForm(ValidatedForm):
date_latest_training = inherit_field(USER_FIELDS["date_latest_training"]) date_latest_training = inherit_field(USER_FIELDS["date_latest_training"])
class WorkspaceOwnerForm(ValidatedForm): class WorkspaceOwnerForm(CacheableForm):
def validate(self, *args, **kwargs): def validate(self, *args, **kwargs):
if self.am_poc.data: if self.am_poc.data:
# Prepend Optional validators so that the validation chain # Prepend Optional validators so that the validation chain
@@ -203,5 +203,5 @@ class WorkspaceOwnerForm(ValidatedForm):
) )
class ReviewAndSubmitForm(ValidatedForm): class ReviewAndSubmitForm(CacheableForm):
reviewed = BooleanField("I have reviewed this data and it is correct.") reviewed = BooleanField("I have reviewed this data and it is correct.")

View File

@@ -1,10 +1,10 @@
from wtforms.fields import StringField from wtforms.fields import StringField
from wtforms.validators import Length from wtforms.validators import Length
from .forms import ValidatedForm from .forms import CacheableForm
class WorkspaceForm(ValidatedForm): class WorkspaceForm(CacheableForm):
name = StringField( name = StringField(
"Workspace Name", "Workspace Name",
validators=[ validators=[

View File

@@ -1,4 +1,4 @@
from flask import g, render_template, redirect, url_for, current_app as app from flask import g, render_template, redirect, url_for
from flask import request as http_request from flask import request as http_request
from werkzeug.datastructures import ImmutableMultiDict, FileStorage from werkzeug.datastructures import ImmutableMultiDict, FileStorage

View File

@@ -1,11 +1,4 @@
from flask import ( from flask import g, redirect, render_template, url_for, request as http_request
g,
redirect,
render_template,
url_for,
request as http_request,
current_app,
)
from . import requests_bp from . import requests_bp
from atst.domain.requests import Requests from atst.domain.requests import Requests