Implement form objects for request forms

This commit is contained in:
Brian Duggan
2018-06-08 11:32:19 -04:00
committed by Jason Garber
parent 4dd4fbf201
commit 9152ffe91e
21 changed files with 1673 additions and 1542 deletions

8
atst/forms/date.py Normal file
View File

@@ -0,0 +1,8 @@
from wtforms.fields.html5 import IntegerField
from wtforms.validators import Required, ValidationError
from wtforms_tornado import Form
class DateForm(Form):
month = IntegerField('Month', validators=[Required()])
day = IntegerField('Day', validators=[Required()])
year = IntegerField('Year', validators=[Required()])

4
atst/forms/funding.py Normal file
View File

@@ -0,0 +1,4 @@
from wtforms_tornado import Form
class FundingForm(Form):
pass

View File

@@ -0,0 +1,4 @@
from wtforms_tornado import Form
class OrganizationInfoForm(Form):
pass

4
atst/forms/readiness.py Normal file
View File

@@ -0,0 +1,4 @@
from wtforms_tornado import Form
class ReadinessForm(Form):
pass

38
atst/forms/request.py Normal file
View File

@@ -0,0 +1,38 @@
from wtforms.fields.html5 import IntegerField
from wtforms.fields import RadioField, StringField, SelectField, TextAreaField
from wtforms.validators import Required, ValidationError
from wtforms_tornado import Form
from .date import DateForm
class RequestForm(Form):
application_name = StringField('Application name', validators=[Required()])
application_description = TextAreaField('Application description', validators=[Required()])
dollar_value = IntegerField('Estimated dollar value of use', validators=[Required()])
input_estimate = SelectField('How did you arrive at this estimate?', validators=[Required()],
choices=[('','- Select -'),
('calculator','CSP usage calculator'),
('B','Option B'),
('C','Option C') ])
# no way to apply a label to a whole nested form like this
date_start = DateForm()
period_of_performance = SelectField('Desired period of performance', validators=[Required()],
choices=[('','- Select -'),
('value1','30 days'),
('value2','60 days'),
('value3','90 days') ])
classification_level = RadioField('Classification level', validators=[Required()],
choices=[('unclassified', 'Unclassified'),
('secret', 'Secret'),
('top-secret', 'Top Secret') ])
primary_service_branch = StringField('Primary service branch usage', validators=[Required()])
cloud_model = RadioField('Cloud model service', validators=[Required()],
choices=[('iaas', 'IaaS'),
('paas', 'PaaS'),
('both', 'Both') ])
number_of_cores = IntegerField('Number of cores', validators=[Required()])
total_ram = IntegerField('Total RAM', validators=[Required()])
# this is just an example validation; obviously this is wrong.
def validate_total_ram(self,field):
if (field.data % 2) != 0:
raise ValidationError("RAM must be in increments of 2.")

4
atst/forms/review.py Normal file
View File

@@ -0,0 +1,4 @@
from wtforms_tornado import Form
class ReviewForm(Form):
pass

View File

@@ -14,7 +14,7 @@ css = Bundle(
assets.register( 'css', css )
helpers = {
'assets': assets
'assets': assets,
}

View File

@@ -1,10 +1,16 @@
import tornado
from atst.handler import BaseHandler
from atst.forms.request import RequestForm
from atst.forms.organization_info import OrganizationInfoForm
from atst.forms.funding import FundingForm
from atst.forms.readiness import ReadinessForm
from atst.forms.review import ReviewForm
import tornado.httputil
class RequestNew(BaseHandler):
screens = [
{ 'title' : 'Details of Use',
'form' : RequestForm,
'subitems' : [
{'title' : 'Application Details',
'id' : 'application-details'},
@@ -15,10 +21,22 @@ class RequestNew(BaseHandler):
{'title' : 'Usage',
'id' : 'usage' },
]},
{ 'title' : 'Organizational Info', },
{ 'title' : 'Funding/Contracting', },
{ 'title' : 'Readiness Survey', },
{ 'title' : 'Review & Submit', }
{
'title' : 'Organizational Info',
'form' : OrganizationInfoForm,
},
{
'title' : 'Funding/Contracting',
'form' : FundingForm,
},
{
'title' : 'Readiness Survey',
'form' : ReadinessForm,
},
{
'title' : 'Review & Submit',
'form' : ReviewForm,
}
]
def initialize(self, page):
@@ -27,18 +45,25 @@ class RequestNew(BaseHandler):
@tornado.web.authenticated
def post(self, screen = 1):
self.check_xsrf_cookie()
all = {
arg: self.get_argument(arg)
for arg in self.request.arguments
if not arg.startswith('_')
}
print( all )
import json
self.write( json.dumps( all ) )
screen = int(screen)
form = self.screens[ screen - 1 ]['form'](self.request.arguments)
print( 'data---------' )
print( form.data )
if form.validate():
where=self.application.default_router.reverse_url('request_form', str(screen + 1))
self.redirect(where)
else:
self.show_form(screen, form)
@tornado.web.authenticated
def get(self, screen = 1):
self.show_form(screen=screen)
def show_form(self, screen = 1, form = None):
if not form:
form = self.screens[ int(screen) - 1 ]['form'](self.request.arguments)
self.render( 'requests/screen-%d.html.to' % int(screen),
f = form,
page = self.page,
screens = self.screens,
current = int(screen),