dnmgmt/whoisdb/validators.py

30 lines
763 B
Python
Raw Normal View History

2017-02-15 02:35:46 +01:00
from django.core import validators
from django.utils import six
from django.utils.deconstruct import deconstructible
from django.utils.translation import ugettext_lazy as _
2017-02-23 22:28:06 +01:00
import re
2017-02-24 03:43:59 +01:00
2017-02-15 02:35:46 +01:00
@deconstructible
class HandleValidator(validators.RegexValidator):
2017-02-24 03:43:59 +01:00
regex = r'^(?:[A-Z]+[0-9]+(-[A-Z]+)|AUTO)'
message = _(
'Enter a valid handle (all uppercase)'
)
flags = re.ASCII if six.PY3 else 0
@deconstructible
class HandleValidatorWithSuffix(validators.RegexValidator):
flags = re.ASCII if six.PY3 else 0
def __init__(self, suffix):
self.regex = r'^(?:[A-Z]+[0-9]+-%s|AUTO)' % re.escape(suffix)
print(self.regex)
self.message = _(
'Enter a valid handle with suffix %s (all uppercase)' % suffix
)
2017-02-15 02:35:46 +01:00
2017-02-24 03:43:59 +01:00
super(HandleValidatorWithSuffix, self).__init__()