Exemple #1
0
 def validate(form, field):
     if field.data == '':
         return
     if min is not None and len(field.data) < min:
         raise ValidationError("Minimum length is " + str(min))
     if max is not None and len(field.data) > max:
         raise ValidationError("Maximum length is " + str(min))
Exemple #2
0
 def validate_password(form, field):
     user = UserModel().get_by_username(form.username.data) 
     if user is None:
         raise ValidationError("auth error")
     entry_password = get_password_hash(settings.SECRET_KEY, user.username, field.data)
     if entry_password != user.password:
         raise ValidationError("auth error")
     form.user = user
Exemple #3
0
 def validate(form, field):
     try:
         datetime.strptime(field.data, format)
     except ValueError, e:
         if format in str(e):
             raise ValidationError(message)
         else:
             raise ValidationError(str(e))
Exemple #4
0
 def __call__(self, form, field):
     if not isinstance(field.data, Decimal):
         try:
             dec_data = Decimal(field.data)
             field.data = dec_data
         except InvalidOperation:
             raise ValidationError(self.message)
     if field.data.as_tuple.exponent > self.places:
         raise ValidationError(self.message)
     elif field.data.as_tuple.digits[0] > size:
         raise ValidationError(self.message)
Exemple #5
0
 def validate_parents(form, field):
     if len(field.data) > 3:
         raise ValidationError("You must reply to three or less posts.")
     if len(field.data) < 1:
         raise ValidationError("You must reply to at least one post.")
     parents = set(graph.posts.get(parent) for parent in field.data)
     for parent in parents:
         ancestor = parent.has_ancestor_any(parents - set((parent, )))
         if ancestor:
             raise ValidationError("%s is an ancestor of %s." %
                                   (ancestor, parent))
Exemple #6
0
def validate_enrollment_subjects(form, field):
    subjects = []
    for key, value in form.data.items():
        if key.startswith('subject_'):
            if value == True:
                subjects.append(key.split('_')[1])
    if not 'de' in subjects:
        raise ValidationError(u'Eine Prüfung in Deutsch ist Pflicht.')
    if len(subjects) > 3:
        raise ValidationError(
            u'Sie können sich in maximal drei Sprachen (inkl. Deutsch) prüfen lassen.'
        )
    if len(subjects) < 2:
        raise ValidationError(
            u'Sie müssen in mindestens einer Fremdsprache den Eignungsprüfungstest ablegen.'
        )
Exemple #7
0
def valid_mailing_list_name(form, mailing_list):
    if not mailing_list.data:
        return
    if not mailing_list.data.startswith(form.project_name.data + '-'):
        raise ValidationError("Mailing lists must start with the project "
                              "name and a dash, e.g. '%s-users'" %
                              (form.project_name.data))
Exemple #8
0
 def validate_on_submit(self, *args, **kwargs):
     if self.is_submitted():
         referrer = request.environ.get('HTTP_REFERER', '')
         if not referrer.startswith(request.host_url):
             raise ValidationError('Invalid referrer')
     return super(ReferrerCheckForm,
                  self).validate_on_submit(*args, **kwargs)
Exemple #9
0
 def validate(form, field):
     if field.data == '':
         return
     if '@' not in field.data:
         raise ValidationError("Invalid e-mail address.")
     v = validators.Email()
     v(form, field)
Exemple #10
0
 def __call__(self, form, field):
     check = self.session.query(
         self.model).filter(self.field == field.data).first()
     if 'id' in form:
         id = form.id.data
     else:
         id = None
     if check and (id is None or id != check.id):
         raise ValidationError(self.message)
Exemple #11
0
def phone_is_unique(form, field):
    try:
        user = cdw.users.with_fields(origin="web",
                                     phoneNumber=field.data).first()
    except:
        return
    if user != None:
        raise ValidationError(
            'Phone number is associated with an account already')
Exemple #12
0
 def validate(form, field):
     if field.data == '':
         return
     ret = FascistCheck(field.data, form.username.data)
     if ret is not None:
         error = "Password rejected: %s." % ret
         raise ValidationError(error)
     else:
         return
Exemple #13
0
def tags_check(form, field):
    if not field.data:
        return True
    if len(field.data.split(' ')) > 3:
        raise ValidationError(u'标签不能超过3个.')
Exemple #14
0
def check_if_username_exists(form, field):
    try:
        cdw.users.with_username(field.data)
    except:
        return
    raise ValidationError('Username %s exists' % field.data)
Exemple #15
0
def email_is_unique(form, field):
    try:
        cdw.users.with_email(field.data)
    except:
        return
    raise ValidationError('Email is already associated with an account')
Exemple #16
0
def check_if_category_exists(form, field):
    try:
        cdw.categories.with_id(field.data)
    except:
        raise ValidationError('Invalid category ID')
Exemple #17
0
 def check_id(uid):
     try:
         cdw.users.with_id(uid)
     except:
         raise ValidationError('Invalid user ID')
Exemple #18
0
def check_if_post_exists(form, field):
    try:
        cdw.posts.with_id(field.data)
    except:
        raise ValidationError("Invalid post ID")
Exemple #19
0
def check_if_thread_exists(form, field):
    try:
        cdw.threads.with_id(field.data)
    except:
        raise ValidationError("Invalid thread ID")
Exemple #20
0
def does_not_have_bad_words(form, field):
    if has_bad_words(field.data):
        raise ValidationError('Content contains bad words')
Exemple #21
0
def email_unique(form, field):
    if len(db_session.query(User).filter_by(email=field.data).all()) > 0:
        raise ValidationError(u'这个邮件地址已经有人注册了.')
Exemple #22
0
 def __call__(self, form, field):
     if any(c in field.data for c in self.not_valid_chars):
         raise ValidationError(self.message)
Exemple #23
0
def unique_user(form, field):
    """
    Check if user's pseudo is not already used.
    """
    if count_user_by_pseudo(field.data) > 0:
        raise ValidationError("Pseudo unavailable.")
Exemple #24
0
 def __call__(self, form, field):
     if not self.model.query.filter(self.field == field.data).first():
         raise ValidationError(self.message)
Exemple #25
0
 def __call__(self, form, field):
     user = User.query.filter(User.email == form.email.data).first()
     if not user:
         return
     if not user.check_password(field.data):
         raise ValidationError(self.message)
Exemple #26
0
def validate_phonenumber(form, field):
    try:
        normalize_phonenumber(field.data)
    except InvalidPhoneNumberException, e:
        raise ValidationError("Invalid phone number: %s" % field.data)
Exemple #27
0
def user_exists(form, field):
    if count_user_by_pseudo(field.data) == 0:
        raise ValidationError("Does not exists.")
Exemple #28
0
def valid_question(form, field):
    try:
        cdw.questions.with_id(field.data)
    except:
        raise ValidationError("Invalid Question ID")
Exemple #29
0
 def validate_S3_url(form, field):
     """Checks that field is a valid S3 url.
         Needs improvement. :) """
     if field.data == "s3://":
         raise ValidationError(u'This field must be an S3 url.')
Exemple #30
0
def existing_category(form, field):
    try:
        cdw.categories.with_id(field.data)
    except:
        raise ValidationError("Invalid category")