Ticket #811: ipv6field.diff
File ipv6field.diff, 6.8 KB (added by , 19 years ago) |
---|
-
django/core/formfields.py
807 807 808 808 class IPAddressField(TextField): 809 809 def __init__(self, field_name, length=15, maxlength=15, is_required=False, validator_list=[]): 810 validator_list = [self.isValidIP Address] + validator_list810 validator_list = [self.isValidIPv4Address] + validator_list 811 811 TextField.__init__(self, field_name, length=length, maxlength=maxlength, 812 812 is_required=is_required, validator_list=validator_list) 813 813 814 def isValidIP Address(self, field_data, all_data):814 def isValidIPv4Address(self, field_data, all_data): 815 815 try: 816 validators.isValidIP Address4(field_data, all_data)816 validators.isValidIPv4Address(field_data, all_data) 817 817 except validators.ValidationError, e: 818 818 raise validators.CriticalValidationError, e.messages 819 819 … … 821 821 return data or None 822 822 html2python = staticmethod(html2python) 823 823 824 class IPv6AddressField(TextField): 825 def __init__(self, field_name, length=39, maxlength=39, is_required=False, validator_list=[]): 826 validator_list = [self.isValidIPv6Address] + validator_list 827 TextField.__init__(self, field_name, length=length, maxlength=maxlength, 828 is_required=is_required, validator_list=validator_list) 829 830 def isValidIPv6Address(self, field_data, all_data): 831 try: 832 validators.isValidIPv6Address(field_data, all_data) 833 except validators.ValidationError, e: 834 raise validators.CriticalValidationError, e.messages 835 836 def html2python(data): 837 return data or None 838 html2python = staticmethod(html2python) 839 824 840 #################### 825 841 # MISCELLANEOUS # 826 842 #################### -
django/core/db/backends/ado_mssql.py
150 150 'ImageField': 'varchar(100)', 151 151 'IntegerField': 'int', 152 152 'IPAddressField': 'char(15)', 153 'IPv6AddressField': 'char(39)', 153 154 'ManyToManyField': None, 154 155 'NullBooleanField': 'bit', 155 156 'OneToOneField': 'int', -
django/core/db/backends/postgresql.py
200 200 'ImageField': 'varchar(100)', 201 201 'IntegerField': 'integer', 202 202 'IPAddressField': 'inet', 203 'IPv6AddressField': 'inet', 203 204 'ManyToManyField': None, 204 205 'NullBooleanField': 'boolean', 205 206 'OneToOneField': 'integer', -
django/core/db/backends/sqlite3.py
174 174 'ImageField': 'varchar(100)', 175 175 'IntegerField': 'integer', 176 176 'IPAddressField': 'char(15)', 177 'IPv6AddressField': 'char(39)', 177 178 'ManyToManyField': None, 178 179 'NullBooleanField': 'bool', 179 180 'OneToOneField': 'integer', -
django/core/db/backends/mysql.py
184 184 'ImageField': 'varchar(100)', 185 185 'IntegerField': 'integer', 186 186 'IPAddressField': 'char(15)', 187 'IPv6AddressField': 'char(39)', 187 188 'ManyToManyField': None, 188 189 'NullBooleanField': 'bool', 189 190 'OneToOneField': 'integer', -
django/core/meta/fields.py
580 580 def get_manipulator_field_objs(self): 581 581 return [formfields.IPAddressField] 582 582 583 class IPv6AddressField(Field): 584 def __init__(self, *args, **kwargs): 585 kwargs['maxlength'] = 39 586 Field.__init__(self, *args, **kwargs) 587 588 def get_manipulator_field_objs(self): 589 return [formfields.IPv6AddressField] 590 583 591 class NullBooleanField(Field): 584 592 def __init__(self, *args, **kwargs): 585 593 kwargs['null'] = True -
django/core/validators.py
19 19 ansi_datetime_re = re.compile('^%s %s$' % (_datere, _timere)) 20 20 email_re = re.compile(r'^[A-Z0-9._%-][+A-Z0-9._%-]*@(?:[A-Z0-9-]+\.)+[A-Z]{2,4}$', re.IGNORECASE) 21 21 integer_re = re.compile(r'^-?\d+$') 22 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}$') 22 ipv4_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}$') 23 _ipv6_hex_re = r'(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}' 24 _ipv6_hex_compressed_re = r'((?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?)::((?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?)' 25 _ipv6_ipv4_compat_re = r'((?:[0-9A-Fa-f]{1,4}:){6,6})(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}' 26 _ipv6_ipv4_compat_compressed_re = r'((?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?)::((?:[0-9A-Fa-f]{1,4}:)*)(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}' 27 ipv6_re = re.compile('^(%s|%s|%s|%s)$' % (_ipv6_hex_re, _ipv6_hex_compressed_re, _ipv6_ipv4_compat_re, _ipv6_ipv4_compat_compressed_re)) 23 28 phone_re = re.compile(r'^[A-PR-Y0-9]{3}-[A-PR-Y0-9]{3}-[A-PR-Y0-9]{4}$', re.IGNORECASE) 24 29 slug_re = re.compile(r'^[-\w]+$') 25 30 url_re = re.compile(r'^https?://\S+$') … … 95 100 except ValidationError: 96 101 raise ValidationError, _("Enter valid e-mail addresses separated by commas.") 97 102 98 def isValidIPAddress 4(field_data, all_data):99 if not ip4_re.search(field_data):100 raise ValidationError, _("Please enter a valid IP address.")103 def isValidIPAddress(field_data, all_data): 104 if not (ipv4_re.search(field_data) or ipv6_re.search(field_data)): 105 raise ValidationError, _("Please enter a valid IPv4 or IPv6 address.") 101 106 107 def isValidIPv4Address(field_data, all_data): 108 if not ipv4_re.search(field_data): 109 raise ValidationError, _("Please enter a valid IPv4 address.") 110 111 def isValidIPv6Address(field_data, all_data): 112 if not ipv6_re.search(field_data): 113 raise ValidationError, _("Please enter a valid IPv6 address.") 114 102 115 def isNotEmpty(field_data, all_data): 103 116 if field_data.strip() == '': 104 117 raise ValidationError, _("Empty values are not allowed here.")