You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

25 lines
712 B

from croniter import croniter
from django.core.exceptions import ValidationError
from six.moves.urllib_parse import urlparse
class WebhookValidator(object):
message = "Enter a valid URL."
def __call__(self, value):
parsed = urlparse(value)
if parsed.scheme not in ("http", "https"):
raise ValidationError(message=self.message)
if parsed.hostname in ("127.0.0.1", "localhost"):
raise ValidationError(message=self.message)
class CronExpressionValidator(object):
message = "Not a valid cron expression."
def __call__(self, value):
try:
croniter(value)
except:
raise ValidationError(message=self.message)