1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Closes #3510: Add minimum/maximum prefix length enforcement for IPNetworkVar

This commit is contained in:
Jeremy Stretch
2019-09-17 16:36:36 -04:00
parent 0601619f50
commit a742d897d7
3 changed files with 34 additions and 1 deletions

View File

@@ -1,6 +1,6 @@
import re
from django.core.validators import _lazy_re_compile, URLValidator
from django.core.validators import _lazy_re_compile, BaseValidator, URLValidator
class EnhancedURLValidator(URLValidator):
@@ -26,3 +26,19 @@ class EnhancedURLValidator(URLValidator):
r'(?:[/?#][^\s]*)?' # Path
r'\Z', re.IGNORECASE)
schemes = AnyURLScheme()
class MaxPrefixLengthValidator(BaseValidator):
message = 'The prefix length must be less than or equal to %(limit_value)s.'
code = 'max_prefix_length'
def compare(self, a, b):
return a.prefixlen > b
class MinPrefixLengthValidator(BaseValidator):
message = 'The prefix length must be greater than or equal to %(limit_value)s.'
code = 'min_prefix_length'
def compare(self, a, b):
return a.prefixlen < b