Last active
June 1, 2020 01:26
-
-
Save phsheth/7d11d0bc49917afbcac1242ef19ddd22 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from wtforms import Form, FloatField, validators, StringField, SelectField | |
from siggen import check_starttime_float, check_endtime_float, check_starttime, check_endtime | |
class siggen_InputForm(Form): | |
signame = StringField(label='Signal Name', | |
validators=[validators.InputRequired()]) | |
starttime = FloatField(label = 'Start Time [sec]', | |
default = 0.0, | |
validators = [validators.InputRequired(), check_starttime_float, check_starttime]) | |
endtime = FloatField(label = 'End Time [sec]', | |
default = 10.0, | |
validators = [validators.InputRequired(), check_endtime_float, check_endtime]) | |
def check_endtime(form, field): | |
""" Form Validation: Check if end time is smaller than start time """ | |
starttime = form.starttime.data | |
endtime = field.data | |
if starttime is None or endtime is None: | |
raise validators.StopValidation( | |
'Start Time or End Time has to be a number!') | |
elif endtime <= starttime: | |
raise validators.ValidationError( | |
'End Time cannot be smaller than Start Time!') | |
def check_starttime(form, field): | |
""" Form Validation: Check if end time is smaller than start time """ | |
endtime = form.endtime.data | |
starttime = field.data | |
if starttime is None or endtime is None: | |
raise validators.StopValidation( | |
'Start Time or End Time has to be a number!') | |
if endtime <= starttime: | |
raise validators.ValidationError( | |
'Start Time cannot be bigger than End Time!') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment