text.py 586 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
from rest_framework.validators import ValidationError


def validate_text(config, string):
    string = str(string)  # might cause error with number ?
    try:
        validators = config['validators']
        for validator in validators:
            validator_content = validators[validator]
            if validator == 'max_length':
                if len(string) > validator_content:
                    raise ValidationError('Your text is too long !')
            else:
                raise Exception("Dev, you have implement something here...")

    except KeyError:
        pass