Пример #1
0
def _validate_type(type_, value):
    if isinstance(value, str):
        try:
            # Just converting to see if any errors are raised.
            converter.from_string(type_, value)
        except ValidationError:
            return False
    else:
        if not isinstance(value, type_):
            return False

    return True
Пример #2
0
def _validate_type(type_, value):
    if isinstance(value, basestring):
        try:
            # Just converting to see if any errors are raised.
            converter.from_string(type_, value)
        except ValidationError:
            return False
    else:
        if not isinstance(value, type_):
            return False

    return True
Пример #3
0
def validate_area_code(code):
    """Validates Brazilian area codes"""
    if isinstance(code, str):
        try:
            code = converter.from_string(int, code)
        except ValidationError:
            return False

    # Valid brazilian codes are on the range of 10-99
    return 10 <= code <= 99
Пример #4
0
def validate_area_code(code):
    """Validates Brazilian area codes"""
    if isinstance(code, basestring):
        try:
            code = converter.from_string(int, code)
        except ValidationError:
            return False

    # Valid brazilian codes are on the range of 10-99
    return 10 <= code <= 99
Пример #5
0
 def create_new_record(self):
     """Adiciona um item padrão a lista para depois ser editado"""
     self.notify.hide()
     obj = ListItem()
     for field in self.fields:
         if field.tipo == str or field.tabelacombo:
             setattr(obj, field.field_name, '')
         else:
             setattr(obj, field.field_name, converter.from_string(field.tipo, '0'))
     return obj
Пример #6
0
def validate_percentage(value):
    """Se if a given value is a valid percentage.

    Works for int, float, Decimal and basestring (if it
    can be converted to Decimal).
    """
    if isinstance(value, str):
        try:
            value = converter.from_string(Decimal, value)
        except ValidationError:
            return False

    return 0 <= value <= 100
Пример #7
0
def validate_percentage(value):
    """Se if a given value is a valid percentage.

    Works for int, float, Decimal and basestring (if it
    can be converted to Decimal).
    """
    if isinstance(value, basestring):
        try:
            value = converter.from_string(Decimal, value)
        except ValidationError:
            return False

    return 0 <= value <= 100