|
@@ -4,6 +4,7 @@ import re
|
|
|
|
|
|
from django import forms
|
|
|
from django.core.urlresolvers import reverse_lazy
|
|
|
+from django.core.validators import URLValidator
|
|
|
from django.utils.encoding import force_text
|
|
|
from django.utils.html import format_html
|
|
|
from django.utils.safestring import mark_safe
|
|
@@ -253,6 +254,21 @@ class FilterChoiceField(forms.ModelMultipleChoiceField):
|
|
|
choices = property(_get_choices, forms.ChoiceField._set_choices)
|
|
|
|
|
|
|
|
|
+class LaxURLField(forms.URLField):
|
|
|
+ """
|
|
|
+ Custom URLField which allows any valid URL scheme
|
|
|
+ """
|
|
|
+
|
|
|
+ class AnyURLScheme(object):
|
|
|
+ # A fake URL list which "contains" all scheme names abiding by the syntax defined in RFC 3986 section 3.1
|
|
|
+ def __contains__(self, item):
|
|
|
+ if not item or not re.match('^[a-z][0-9a-z+\-.]*$', item.lower()):
|
|
|
+ return False
|
|
|
+ return True
|
|
|
+
|
|
|
+ default_validators = [URLValidator(schemes=AnyURLScheme())]
|
|
|
+
|
|
|
+
|
|
|
#
|
|
|
# Forms
|
|
|
#
|