Exemple #1
0
class ChildForm(BaseForm):
    modifiedon = DateTimeField(validators=[
                                   DataOptional(default=datetime.now),
                                   DateRange(min=datetime(1900, 1, 1), max=datetime.now)
                               ],
                               format="%Y-%m-%dT%H:%M:%SZ")
    name = StringField(validators=[DataRequired()])
    known_age = IntegerField(validators=[DataOptional(), NumberRange(min=0, max=99)])
    birthdate = DateField(validators=[DataOptional(), DateRange(min=date(1900, 1, 1), max=date.today)],
                          format="%Y-%m-%d")
Exemple #2
0
class PatientForm(BaseForm):
    record = IntegerField(validators=[DataAuto(Patient), NumberRange(min=1)])
    firstname = StringField(validators=[DataRequired(), Length(min=2)])
    middlename = StringField(validators=[DataOptional()])
    surname = StringField(validators=[DataOptional(), Length(min=2)])
    birthdate = DateField(validators=[DataRequired(), DateRange(min=date(1900, 1, 1), max=date.today)],
                          format="%Y-%m-%d")
    nationality = StringField(validators=[DataRequired(), AnyOf(values=NATIONALITIES)])
    occupation = StringField(validators=[DataRequired(), Length(min=3)])
    children = FieldList(Field(validators=[DataOptional(), Entity(ChildForm, Child)]))
    cellphone = StringField(validators=[DataOptional(), Telephone()])
    cellphone2 = StringField(validators=[DataOptional(), Telephone()])
    telephone = StringField(validators=[DataOptional(), Telephone()])
    email = StringField(validators=[DataOptional(), Email()])
    province = StringField(validators=[DataOptional(), AnyOf(values=PROVINCES)])
    city = StringField(validators=[DataOptional(), Length(min=2)])
    district = StringField(validators=[DataOptional()])
    advisor = Field(validators=[DataOptional(), Entity(AdvisorForm, Advisor)])
    coadvisors = FieldList(Field(validators=[DataOptional(), Entity(AdvisorForm, Advisor)]), validators=[Coadvisors()])
    notes = StringField(validators=[DataOptional()])
Exemple #3
0
 def test_min_and_max_should_succeed(self):
     validator = DateRange(min=date(1999, 12, 31), max=date(2000, 1, 2))
     validator(self.form, self.field)
Exemple #4
0
    def test_max_should_succeed(self):
        validator = DateRange(max=date(2000, 1, 1))
        validator(self.form, self.field)

        validator = DateRange(max=date(2000, 1, 2))
        validator(self.form, self.field)
Exemple #5
0
 def test_max_should_fail(self):
     validator = DateRange(max=date(1999, 12, 31))
     with self.assertRaises(ValidationError):
         validator(self.form, self.field)
Exemple #6
0
 def test_min_should_fail(self):
     validator = DateRange(min=date(2000, 1, 2))
     with self.assertRaises(ValidationError):
         validator(self.form, self.field)
Exemple #7
0
 def test_validation_should_succeed_when_no_data(self):
     self.field.data = None
     validator = DateRange(min=date(1999, 12, 31), max=date(2000, 1, 2))
     validator(self.form, self.field)
Exemple #8
0
 def test_new_instance_should_fail(self):
     with self.assertRaises(ValueError):
         DateRange()