22 lines
554 B
Python
22 lines
554 B
Python
from __future__ import unicode_literals
|
|
|
|
import yaml
|
|
|
|
from django.core.exceptions import ValidationError
|
|
from django.utils.translation import ugettext_lazy as _
|
|
from django.utils.deconstruct import deconstructible
|
|
|
|
|
|
@deconstructible
|
|
class YAMLValidator(object):
|
|
"""
|
|
Validates that the input is YAML compliant.
|
|
"""
|
|
|
|
def __call__(self, value):
|
|
value = value.strip()
|
|
try:
|
|
yaml.safe_load(value)
|
|
except yaml.error.YAMLError:
|
|
raise ValidationError(_('Enter a valid YAML value.'), code='invalid')
|