From e5f0a97595ff9280c7876fc917f6feb27b5ea95d Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Mon, 22 Sep 2014 16:45:06 +0100 Subject: More compat fixes --- rest_framework/compat.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'rest_framework/compat.py') diff --git a/rest_framework/compat.py b/rest_framework/compat.py index 2b4ddb02..7303c32a 100644 --- a/rest_framework/compat.py +++ b/rest_framework/compat.py @@ -139,6 +139,29 @@ else: self.message = kwargs.pop('message', self.message) super(MaxValueValidator, self).__init__(*args, **kwargs) +# URLValidator only accept `message` in 1.6+ +if django.VERSION >= (1, 6): + from django.core.validators import URLValidator +else: + from django.core.validators import URLValidator as DjangoURLValidator + + class URLValidator(DjangoURLValidator): + def __init__(self, *args, **kwargs): + self.message = kwargs.pop('message', self.message) + super(URLValidator, self).__init__(*args, **kwargs) + + +# EmailValidator requires explicit regex prior to 1.6+ +if django.VERSION >= (1, 6): + from django.core.validators import EmailValidator +else: + from django.core.validators import EmailValidator as DjangoEmailValidator + from django.core.validators import email_re + + class EmailValidator(DjangoEmailValidator): + def __init__(self, *args, **kwargs): + super(EmailValidator, self).__init__(email_re, *args, **kwargs) + # PATCH method is not implemented by Django if 'patch' not in View.http_method_names: -- cgit v1.2.3