aboutsummaryrefslogtreecommitdiff
path: root/rpkid/rpki/gui/app/forms.py
diff options
context:
space:
mode:
authorMichael Elkins <melkins@tislabs.com>2012-11-22 01:30:58 +0000
committerMichael Elkins <melkins@tislabs.com>2012-11-22 01:30:58 +0000
commit266c85e9f4334628916ded4af2deab8c95467aea (patch)
tree0c70f9d7ca2edf15e3db6baae9c9ae05d0fdfbc2 /rpkid/rpki/gui/app/forms.py
parentd36646a01f822c6c2798cd0986594a88003f52f2 (diff)
commiting work in progress
svn path=/branches/tk329/; revision=4894
Diffstat (limited to 'rpkid/rpki/gui/app/forms.py')
-rw-r--r--rpkid/rpki/gui/app/forms.py54
1 files changed, 28 insertions, 26 deletions
diff --git a/rpkid/rpki/gui/app/forms.py b/rpkid/rpki/gui/app/forms.py
index f6b9547d..e7050284 100644
--- a/rpkid/rpki/gui/app/forms.py
+++ b/rpkid/rpki/gui/app/forms.py
@@ -288,41 +288,43 @@ class ROARequestConfirm(forms.Form):
return self.cleaned_data
-def AddASNForm(child):
+class AddASNForm(forms.Form):
"""
Returns a forms.Form subclass which verifies that the entered ASN range
does not overlap with a previous allocation to the specified child, and
that the ASN range is within the range allocated to the parent.
"""
- class _wrapped(forms.Form):
- asns = forms.CharField(
- label='ASNs',
- help_text='single ASN or range',
- widget=forms.TextInput(attrs={'autofocus': 'true'})
- )
- def clean_asns(self):
- try:
- r = resource_range_as.parse_str(self.cleaned_data.get('asns'))
- except:
- raise forms.ValidationError('invalid AS or range')
-
- if not models.ResourceRangeAS.objects.filter(
- cert__conf=child.issuer,
- min__lte=r.min,
- max__gte=r.max).exists():
- raise forms.ValidationError('AS or range is not delegated to you')
-
- # determine if the entered range overlaps with any AS already
- # allocated to this child
- if child.asns.filter(end_as__gte=r.min, start_as__lte=r.max).exists():
- raise forms.ValidationError(
- 'Overlap with previous allocation to this child')
+ asns = forms.CharField(
+ label='ASNs',
+ help_text='single ASN or range',
+ widget=forms.TextInput(attrs={'autofocus': 'true'})
+ )
- return str(r)
+ def __init__(self, *args, **kwargs):
+ self.child = kwargs.pop('child')
+ super(AddASNForm, self).__init__(*args, **kwargs)
- return _wrapped
+ def clean_asns(self):
+ try:
+ r = resource_range_as.parse_str(self.cleaned_data.get('asns'))
+ except:
+ raise forms.ValidationError('invalid AS or range')
+
+ if not models.ResourceRangeAS.objects.filter(
+ cert__conf=self.child.issuer,
+ min__lte=r.min,
+ max__gte=r.max).exists():
+ raise forms.ValidationError('AS or range is not delegated to you')
+
+ # determine if the entered range overlaps with any AS already
+ # allocated to this child
+ if self.child.asns.filter(end_as__gte=r.min, start_as__lte=r.max).exists():
+ raise forms.ValidationError(
+ 'Overlap with previous allocation to this child')
+
+ return str(r)
def AddNetForm(child):