validators.py 646 B

12345678910111213141516171819
  1. from django.core.exceptions import ValidationError
  2. from django.utils.translation import ugettext_lazy as _
  3. from misago.core.utils import slugify
  4. class validate_sluggable(object):
  5. def __init__(self, error_short=None, error_long=None):
  6. self.error_short = error_short or _(
  7. "Value has to contain alpha-numerical characters.")
  8. self.error_long = error_long or _("Value is too long.")
  9. def __call__(self, value):
  10. slug = slugify(value)
  11. if not slug.replace('-', ''):
  12. raise ValidationError(self.error_short)
  13. if len(slug) > 255:
  14. raise ValidationError(self.error_long)