Ticket #1636: django_cidr.diff
File django_cidr.diff, 6.1 KB (added by , 19 years ago) |
---|
-
django/db/models/fields/__init__.py
670 670 def validate(self, field_data, all_data): 671 671 validators.isValidIPAddress4(field_data, None) 672 672 673 class CIDRAddressField(Field): 674 def __init__(self, *args, **kwargs): 675 kwargs['maxlength'] = 18 676 Field.__init__(self, *args, **kwargs) 677 678 def get_manipulator_field_objs(self): 679 return [forms.CIDRAddressField] 680 681 def valid(self, field_data, all_data): 682 validators.isValidCIDRAddress4(field_data, None) 683 673 684 class NullBooleanField(Field): 674 685 def __init__(self, *args, **kwargs): 675 686 kwargs['null'] = True -
django/db/backends/ado_mssql/creation.py
11 11 'ImageField': 'varchar(100)', 12 12 'IntegerField': 'int', 13 13 'IPAddressField': 'char(15)', 14 'CIDRAddressField': 'char(18)', 14 15 'ManyToManyField': None, 15 16 'NullBooleanField': 'bit', 16 17 'OneToOneField': 'int', -
django/db/backends/postgresql/introspection.py
74 74 21: 'SmallIntegerField', 75 75 23: 'IntegerField', 76 76 25: 'TextField', 77 650: 'CIDRAddressField', 77 78 869: 'IPAddressField', 78 79 1043: 'CharField', 79 80 1082: 'DateField', -
django/db/backends/postgresql/creation.py
15 15 'ImageField': 'varchar(100)', 16 16 'IntegerField': 'integer', 17 17 'IPAddressField': 'inet', 18 'CIDRAddressField': 'cidr', 18 19 'ManyToManyField': None, 19 20 'NullBooleanField': 'boolean', 20 21 'OneToOneField': 'integer', -
django/db/backends/sqlite3/creation.py
14 14 'ImageField': 'varchar(100)', 15 15 'IntegerField': 'integer', 16 16 'IPAddressField': 'char(15)', 17 'CIDRAddressField': 'char(18)', 17 18 'ManyToManyField': None, 18 19 'NullBooleanField': 'bool', 19 20 'OneToOneField': 'integer', -
django/db/backends/mysql/creation.py
15 15 'ImageField': 'varchar(100)', 16 16 'IntegerField': 'integer', 17 17 'IPAddressField': 'char(15)', 18 'CIDRAddressField': 'char(18)', 18 19 'ManyToManyField': None, 19 20 'NullBooleanField': 'bool', 20 21 'OneToOneField': 'integer', -
django/forms/__init__.py
863 863 return data or None 864 864 html2python = staticmethod(html2python) 865 865 866 class CIDRAddressField(TextField): 867 def __init__(self, field_name, length=18, maxlength=18, is_required=False, validator_list=[]): 868 validator_list = [self.isValidCIDRAddress] + validator_list 869 TextField.__init__(self, field_name, length=length, maxlength=maxlength, is_required=is_required, validator_list=validator_list) 870 871 def isValidCIDRAddress(self, field_data, all_data): 872 try: 873 validators.isValidCIDRAddress4(field_data, all_data) 874 except validators.ValidationError, e: 875 raise validators.CriticalValidationError, e.messages 876 866 877 #################### 867 878 # MISCELLANEOUS # 868 879 #################### -
django/core/validators.py
23 23 email_re = re.compile(r'^[A-Z0-9._%-][+A-Z0-9._%-]*@(?:[A-Z0-9-]+\.)+[A-Z]{2,4}$', re.IGNORECASE) 24 24 integer_re = re.compile(r'^-?\d+$') 25 25 ip4_re = re.compile(r'^(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}$') 26 ip4_cidr_re = re.compile(r'^([0-9]|1?\d\d|2[0-4]\d|25[0-5])\.([0-9]|1?\d\d|2[0-4]\d|25[0-5])\.([0-9]|1?\d\d|2[0-4]\d|25[0-5])\.([0-9]|1?\d\d|2[0-4]\d|25[0-5])(\/([1-9]|1\d|2\d|3[0-2]))$') 26 27 phone_re = re.compile(r'^[A-PR-Y0-9]{3}-[A-PR-Y0-9]{3}-[A-PR-Y0-9]{4}$', re.IGNORECASE) 27 28 slug_re = re.compile(r'^[-\w]+$') 28 29 url_re = re.compile(r'^https?://\S+$') … … 98 99 if not ip4_re.search(field_data): 99 100 raise ValidationError, gettext("Please enter a valid IP address.") 100 101 102 def isValidCIDRAddress4(field_data, all_data): 103 if not ip4_cidr_re.search(field_data): 104 raise ValidationError, gettext("Please enter a valid CIDR address.") 105 cidr_parts = field_data.split('/') 106 if not 0 <= int(cidr_parts[1]) <= 32: 107 raise ValidationError, gettext("CIDR Mask not in valid range.") 108 inet_octets = cidr_parts[0].split('.') 109 inet_dec = 0L 110 inet_dec = inet_dec | (long(inet_octets[0]) << 24) 111 inet_dec = inet_dec | (long(inet_octets[1]) << 16) 112 inet_dec = inet_dec | (long(inet_octets[2]) << 8) 113 inet_dec = inet_dec | (long(inet_octets[3])) 114 115 inet_bin = '' 116 for i in xrange(0, 32): 117 if inet_dec & 1: 118 inet_bin = '1' + inet_bin 119 else: 120 inet_bin = '0' + inet_bin 121 inet_dec = inet_dec >> 1 122 for i in range(int(cidr_parts[1]), 32): 123 if int(inet_bin[i]) == 1: 124 raise ValidationError, gettext("CIDR addresses must not have host bits.") 125 126 101 127 def isNotEmpty(field_data, all_data): 102 128 if field_data.strip() == '': 103 129 raise ValidationError, gettext("Empty values are not allowed here.")