Example #1
0
 def validate_name(form, field):
     if field.data == form.name.default:
         raise ValidationError(_("User name incorrect"))
     if (not form.edit and Person.query.filter(
             Person.name == field.data, Person.project == form.project,
             Person.activated == True).all()):
         raise ValidationError(_("This project already have this member"))
Example #2
0
 def validate_id(form, field):
     form.id.data = slugify(field.data)
     if (form.id.data == "dashboard") or Project.query.get(form.id.data):
         raise ValidationError(
             Markup(
                 _("The project identifier is used "
                   "to log in and for the URL of the project. "
                   "We tried to generate an identifier for you but a project "
                   "with this identifier already exists. "
                   "Please create a new identifier "
                   "that you will be able to remember.")))
Example #3
0
    def pre_validate(self, form, choices=None):
        """
        Don't forget to validate also values from embedded lists.
        """
        default_choices = choices is None
        choices = choices or self.choices

        for value, label in choices:
            found = False

            if isinstance(label, (list, tuple)):
                found = self.pre_validate(form, label)

            if found or value == self.data:
                return True

        if not default_choices:
            return False

        raise ValidationError(self.gettext(u'Not a valid choice'))
Example #4
0
def valid_user_email(form, field):
    form.user = _datastore.find_user(email=field.data)
    if form.user is None:
        raise ValidationError(get_message('USER_DOES_NOT_EXIST')[0])
Example #5
0
def unique_user_email(form, field):
    if _datastore.find_user(email=field.data) is not None:
        msg = get_message('EMAIL_ALREADY_ASSOCIATED', email=field.data)[0]
        raise ValidationError(msg)
Example #6
0
 def validate_next(self, field):
     url_next = urlparse.urlsplit(field.data)
     url_base = urlparse.urlsplit(request.host_url)
     if url_next.netloc and url_next.netloc != url_base.netloc:
         field.data = ''
         raise ValidationError(get_message('INVALID_REDIRECT')[0])
Example #7
0
 def validate_email(self, field):
     if not User.query.filter_by(email=field.data).count():
         raise ValidationError('No user with given email found')
Example #8
0
 def validate_old_password(self, field):
     if not self.user.check_password(field.data):
         raise ValidationError('Incorrect old password')
Example #9
0
def user_exists(form, field):
    if count_user_by_pseudo(field.data) == 0:
        raise ValidationError("Does not exists.")
Example #10
0
 def validate_emails(form, field):
     validator = Email()
     for email in [email.strip() for email in form.emails.data.split(",")]:
         if not validator.regex.match(email):
             raise ValidationError(
                 _("The email %(email)s is not valid", email=email))
Example #11
0
 def validate_amount(self, field):
     if field.data == 0:
         raise ValidationError(_("Bills can't be null"))
Example #12
0
 def validate_id(form, field):
     if not Project.query.get(field.data):
         raise ValidationError(_("This project does not exists"))
Example #13
0
 def _validate_mobile(form, field):
     number = field.data
     mobile_patt = re.compile(
         '^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$')
     if number and mobile_patt.match(number) is None:
         raise ValidationError(message or u'手机号码不合法')
Example #14
0
def email_check(form, field):
    if field.data:
        if User.query.filter_by(email=field.data).first():
            raise ValidationError('A user with that email address already exists.')
Example #15
0
 def validate_email(self, field):
     if User.query.filter_by(email=field.data).count():
         raise ValidationError('User with this email is already signed up')
Example #16
0
def username_check(form, field):
    if field.data:
        if User.query.filter_by(username=field.data).first():
            raise ValidationError('A user with that username already exists.')
Example #17
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.")