Ejemplo n.º 1
0
def _generic_dt_validator(value, dt_format):
    """ Validates the date and returns the year """
    
    try:
        return datetime.datetime.strptime(value, dt_format).year
    except ValueError:
        raise validators.ValidationError("Date does not match format %s" %dt_format)
Ejemplo n.º 2
0
 def f(value, field):
     formatted_start_dt = field.parent.to_dict(with_prefix=False)["formatted_start_dt"]
     try:
         if datetime.datetime.strptime(value, dt_format).date() < datetime.datetime.strptime(formatted_start_dt, dt_format).date():
             raise validators.ValidationError("Must be greater or equal to the poll start date")
     except ValueError:
         pass # will be caught by another validator
Ejemplo n.º 3
0
def validate_uid(value, field):
    try:
        value = str(value)
    except UnicodeEncodeError:
        raise validators.ValidationError(
            "Le login ne doit contenir que de l'ASCII")
    for v in value:
        if v not in string.ascii_letters + '-_204':
            raise validators.ValidationError(
                "Le login ne doit contenir que de l'ASCII")
    if ' ' in value:
        raise validators.ValidationError(
            "Le login ne doit pas contenir d'espace")
    if len(value) < 4:
        raise validators.ValidationError(
            "Le login doit contenir au moins 4 characteres")
    if ldap.getUser(value):
        raise validators.ValidationError('Cet identifiant est pris')
    return value
Ejemplo n.º 4
0
 def f(value, field):
     
     # Step 1 : general format check with the standard library
     year = _generic_dt_validator(value, dt_format)
     
     # Step 2 : year check
     selected_season = Season.get(field.parent.season_id.value)
     allowed_years = (selected_season.start_year, selected_season.end_year)
     if not year in allowed_years:
         raise validators.ValidationError("Year should be %s" % " or ".join(map(str,allowed_years))) 
Ejemplo n.º 5
0
def validate_email(value, field):
    validators.email(value)
    conn = ldap.get_conn()
    if conn.search(filter='(mail=%s)' % value):
        raise validators.ValidationError('Cet email est pris')
    return value
Ejemplo n.º 6
0
def year_delta_validator(value, field):
    
    if value - field.parent.start_year.value != 1:
        raise validators.ValidationError("1 != end_year - start_year")
Ejemplo n.º 7
0
 def f(value, field):
     if not re.match(year_pattern, str(value)):
         raise validators.ValidationError("Year does not match %s" %year_pattern)
Ejemplo n.º 8
0
 def f(value, field):
     status = field.parent.to_dict(with_prefix=False)["status"]
     if status in statuses and value is not None:
         raise validators.ValidationError("Forbidden value (status=%s)" %status)
Ejemplo n.º 9
0
def poll_choice_dt_uniqueness_validator(value, field):

    siblings = [f for f in field.parent.possible_date_fields if f is not field]
        
    if any(value == field.parent.to_dict(with_prefix=False)[sibling.name] for sibling in siblings):
            raise validators.ValidationError("Non-unique possible date")
Ejemplo n.º 10
0
def new_password_validator(value, field):
    
    if field.parent.new_password.value != value:
        raise validators.ValidationError("Passwords do not match")
Ejemplo n.º 11
0
def old_password_validator(value, field):
    
    if field.parent.model.password != to_md5(value):
        raise validators.ValidationError("Invalid value")