class InstructionForm(FlaskForm): integration_name = StringField('Integration Name', validators=[DataRequired()]) int_uuid = StringField('Integration ID', validators=[UUID(), DataRequired()]) tenant_id = StringField('Tenant ID', validators=[UUID(), DataRequired()]) active = BooleanField('Current Rule', default="true") run_next = BooleanField('Run Next Poll', default="") db_info = TextAreaField('DB Connection Info', validators=[DataRequired()]) command = TextAreaField('DB Query', validators=[DataRequired()])
def test_uuid(self): self.assertEqual(UUID()(self.form, DummyField( '2bc1c94f-0deb-43e9-92a1-4775189ec9f8')), None) self.assertRaises(ValidationError, UUID(), self.form, DummyField('2bc1c94f-deb-43e9-92a1-4775189ec9f8')) self.assertRaises(ValidationError, UUID(), self.form, DummyField('2bc1c94f-0deb-43e9-92a1-4775189ec9f')) self.assertRaises(ValidationError, UUID(), self.form, DummyField('gbc1c94f-0deb-43e9-92a1-4775189ec9f8')) self.assertRaises(ValidationError, UUID(), self.form, DummyField('2bc1c94f 0deb-43e9-92a1-4775189ec9f8'))
class OrgConfirmationForm(FlaskForm): """Registered organisation confirmation form.""" name = StringField('Organisation Name', validators=[DataRequired()]) email = EmailField('Organisation EmailId', validators=[DataRequired(), email()]) show_api_credentials = BooleanField("Show API Credentials", default=False) orcid_client_id = StringField( "Organisation Orcid Client Id: ", validators=[ DataRequired(), Regexp(r"^\S+$", message="The value shouldn't contain any spaces"), Regexp( r"^APP-[A-Z0-9]+$", message=("The Cient ID should match patter " "'APP-(sequence of digits or uppercase characters), " "for example, 'APP-FDFN3F52J3M4L34S'.")), ]) orcid_secret = StringField( 'Organisation Orcid Client Secret: ', validators=[ DataRequired(), Regexp(r"^\S+$", message="The value shouldn't contain any spaces"), UUID(message="The secret should be a valid UUID") ]) country = CountrySelectField("Country", [validators.required()], default=DEFAULT_COUNTRY) city = StringField("City", [validators.required()]) disambiguated_id = StringField("Disambiguated Id", [validators.required()]) disambiguation_source = SelectField( "Disambiguation Source", validators=[validators.required()], choices=EMPTY_CHOICES + models.disambiguation_source_choices)
class LoginForm(Form): email = StringField(validators=[Email()]) username = StringField(validators=[InputRequired()]) age = IntegerField(validators=[NumberRange(12, 100)]) phone = StringField(validators=[Regexp(r'1[357]\d{9}')]) homepage = StringField(validators=[URL()]) uuid = StringField(validators=[UUID()])
def test_valid_uuid_passes(uuid_val, dummy_form, dummy_field): """ Valid UUID should pass without raising """ validator = UUID() dummy_field.data = uuid_val validator(dummy_form, dummy_field)
class MonitorRuleForm(Form): name = StringField(validators=[Required()]) regions = FieldList(StringField(validators=[Required(), UUID()]), min_entries=1) triggers = FieldList(FormField(MonitorTriggerForm), min_entries=1) actions = FieldList(FormField(MonitorContactForm), min_entries=1)
class LoginForm(FlaskForm): email = StringField("邮箱", validators=[Email(message="必须是邮箱类型")]) username = StringField("用户名", validators=[ Length(min=6, max=20, message="用户名长度在6-20位"), InputRequired("请填写用户名") ]) age = IntegerField(validators=[NumberRange(18, 90)]) phone = StringField(validators=[Regexp(r'1[3-9]\d{9}')]) homepage = StringField(validators=[URL()]) uuid = StringField(validators=[UUID()]) captcha = StringField(validators=[Length(4, 4)]) creat_time = DateField("注册时间", validators=[]) remember = BooleanField("记住我:") tags = SelectField("标签", choices=[('1', 'python'), ('2', 'java')]) submit = SubmitField("立即登录") #http://www.jiabin.com #单独对某个字段做验证 那么需要在字段前加上 validate_ def validate_email(self, field): #第一步导入模型 #email = db.session.query(User).fileter(User.email==self.email).first() #if email: #抛出错误 该邮箱已经存在了 # email = self.email.data #表示用户在表单中输入的内容 email = field.data #表示用户在表单中输入的内容 if email != '*****@*****.**': raise ValidationError("邮箱已经存在")
def test_bad_uuid_raises(uuid_val, dummy_form, dummy_field): """ Bad UUID should raise ValueError """ validator = UUID() dummy_field.data = uuid_val with pytest.raises(ValidationError): validator(dummy_form, dummy_field)
class NewFolderForm(FlaskForm): title = StringField('Title', validators=[DataRequired()]) owner_id = HiddenField(validators=[DataRequired()]) # parent_id = QuerySelectField('Parent') parent_id = HiddenField(validators=[Optional(), UUID()], default=None, filters=[lambda x: x or None]) add = SubmitField('Add')
class EmployeeData(db.Model): emp_id = db.Column(UUID(as_uuid=True), primary_key=True, unique=True, nullable=False) name = db.Column(db.String(), unique=True, nullable=False) password = db.Column(db.String(), unique=True, nullable=False) email = db.Column(db.String(), unique=True, nullable=False) org = db.relationship("Organization", backref='employeedata', lazy=True) __tablename__ = "employeedata"
class MonitorAlertDashDetailForm(Form): starttime = DateTimeField(validators=[Required()], format='%Y-%m-%d+%H:%M:%S') stoptime = DateTimeField(validators=[Required()], format='%Y-%m-%d+%H:%M:%S') # datatype = StringField(validators=[Required(), AnyOf(['delay', 'loss_rate', 'all'])]) broadband = StringField(validators=[Required()]) region = StringField(validators=[Required(), UUID()]) province = StringField(validators=[Required()])
class VerifyRegistrationForm(FlaskForm): booking_id = StringField("Booking ID", validators=[get_id_checker("Booking ID")]) token = StringField( "Token", validators=[ DataRequired(message="Token cannot be empty."), UUID(message="The token is invalid."), ], ) submit = SubmitField("Get my badge!")
class LoginForm(Form): email = StringField(label='邮箱', validators=[Email(message='邮箱输入有误')]) username = StringField(label='用户名', validators=[InputRequired()]) age = IntegerField(label='年龄', validators=[NumberRange(min=18, max=30)]) phone = StringField( label='手机号', validators=[Regexp(r'1[35687]\d{9}', message='手机号输入有误')]) home_page = StringField(label='个人主页', validators=[URL()]) uuid = StringField(label='uuid', validators=[UUID()]) captcha = StringField(label='验证码', validators=[Length(4, 4)]) def validate_captcha(self, field): if field.data != '1111': return '验证码错误'
class ModuleSetValueForm(FlaskForm): device_id = StringField( 'device_id', validators=[ DataRequired(message='Hodnota device_id je povinná.'), UUID(message='Hodnota nie je vo formáte UUID.') ]) datapoint = StringField( 'datapoint', validators=[DataRequired(message='Hodnota datapoint je povinná.')]) value = StringField( 'value', validators=[DataRequired(message='Hodnota value je povinná.')])
class ModuleSetConfigForm(FlaskForm): device_id = StringField( 'device_id', validators=[ DataRequired(message='Hodnota device_id je povinná.'), UUID(message='Hodnota nie je vo formáte UUID.') ]) address = StringField( 'address', validators=[DataRequired(message='Hodnota address je povinná.')]) poll_rate = StringField( 'poll_rate', validators=[DataRequired(message='Hodnota poll_rate je povinná.')])
class FormIpAddressAdd(Form): # ipaddress = TextField( 'ipaddress', validators = [Required(), IPAddress(ipv4=True, ipv6=True) ]) # doesn't allow cidr formats ipaddress = TextField('ipaddress', validators=[Required(), ValidateIpAddress()]) parent = SelectField( 'parent', validators=[Optional(), UUID()], coerce=str) # show the enclosing ip address rather than the key idorganization = SelectField('idorganization', validators=[Required()]) name = TextField('name') # optional name description = TextField('description') # optional description fqdn = TextField('fqdn', validators=[Optional()]) url = TextField('url') # optional url for management or for info
class LoginForm(Form): # TODO: 1.Email:验证上传的数据是否为邮箱。 email = StringField(validators=[Email(message='邮箱格式错误')]) # TODO: 2.InputRequir:原始数据的需要验证。如果不是特殊情况,应该使用InputRequired。 username = StringField(validators=[InputRequired(message='username不能传为空')]) # TODO: 3.NumberRange:数字的区间,有min和max两个值限制,如果处在这两个数字之间则满足。 age = IntegerField( validators=[NumberRange(min=12, max=100, message='有效年纪为:12-100岁')]) # TODO: 4.Regexp:自定义正则表达式 phone = StringField(validators=[ Length(min=11, max=11, message='手机号为11位数字'), Regexp(regex=r'1[356789]\d{9}', message='手机号格式输入有误') ]) # TODO: 5.URL:必须要是URL的形式 homepage = StringField(validators=[URL(message='URL格式输入有误...')]) # TODO: 6.UUID:验证UUID uuidstr = StringField(validators=[UUID(message='uuid格式有误...')])
class LoginForm(FlaskForm): email = StringField("邮箱", validators=[Email(message="必须是邮箱类型")]) username = StringField("用户名", validators=[Length(min=6, max=20, message="用户名长度必须在6-20位"), InputRequired("请填写用户名")]) phone=StringField(validators=[Regexp(r'1[3,9]\d{9}')]) age=IntegerField(validators=[NumberRange(0,100)]) homepage=StringField(validators=[URL()]) uuid=StringField(validators=[UUID()]) captcha=StringField(validators=[Length(4,4)]) create_time=DateField("注册时间",validators=[]) remember=BooleanField("记住我") tags=SelectField("标签",choices=[('1','python'),('2','java')]) submit=SubmitField("立即登录") def validate_email(self,field): email = field.data if email != '*****@*****.**': raise ValidationError("邮箱已经存在")
class SignupForm(FlaskForm): username = StringField( 'Username', validators=[ Regexp( r'^[a-z][a-z0-9_]+$', message='Usernames must start with a lowercase letter. ' + 'Subsequent characters must be lowercase alphanumeric or _.'), Length(min=3, max=16, message='Username needs to be between 3 and 16 chars long') ]) if os.environ.get('IS_BETA'): beta_key = StringField('Beta Key', validators=[ UUID(message='Message must be a beta-key'), validate_beta_key ]) submit = SubmitField('Register')
class MonitorTriggerForm(Form): period = StringField(validators=[ Required(), AnyOf(['1min', '5min', '10min', '30min', '1h']) ], ) time = StringField(validators=[ Required(), AnyOf(['1c', '2c', '3c', '4c', '5c', '6c', '7c', '8c', '9c', '10c']) ]) repeat = StringField(validators=[ Required(), AnyOf([ 'no_repeat', '5min', '10min', '15min', '30min', '1h', '2h', '3h', '5h', '12h' ]) ]) compare = StringField(validators=[Required(), AnyOf(['>', '<', '='])]) threshold = IntegerField(validators=[Required()]) item_id = StringField(validators=[Required(), UUID()])
def uuid_field(self, kwargs): kwargs['validators'].append(Length(36, 36)) kwargs['validators'].append(UUID()) kwargs['default'] = str(uuid.uuid4()) return StringField(**kwargs)
class Organization(db.Model): org_id = db.Column(UUID(as_uuid=True), unique=True, primary_key=True, nullable=False) emp_id = db.Column(UUID(as_uuid=True), db.ForeignKey('employeedata'))
class MonitorRegionPutForm(Form): # name = StringField(validators=[Required()]) # id = StringField(validators=[Required(), UUID]) serverips = FieldList(StringField(validators=[UUID()]), min_entries=0)
class CheckoutForm(Form): commit_id = StringField(validators=[DataRequired(), Length(min=40, max=40)]) repo_id = StringField(validators=[UUID(), DataRequired(), InputRequired()])
class CheckoutMasterForm(Form): repo_id = StringField(validators=[UUID(), DataRequired(), InputRequired()])
class CommitForm(Form): repo_id = StringField(validators=[UUID(), DataRequired(), InputRequired()]) page = IntegerField(validators=[NumberRange(min=1)], default=1) per_page = IntegerField(validators=[NumberRange(min=1, max=100)], default=50) is_whole = BooleanField(default=False)