|
|
|
@ -14,18 +14,19 @@ class WhoisObjectFormMixin(object):
|
|
|
|
|
|
|
|
|
|
instance = getattr(self, 'instance', None)
|
|
|
|
|
if instance and instance.pk:
|
|
|
|
|
self._create = False
|
|
|
|
|
self.fields['handle'].widget.attrs['readonly'] = True
|
|
|
|
|
else:
|
|
|
|
|
self._create = True
|
|
|
|
|
|
|
|
|
|
# only show users contacts and already present contacts
|
|
|
|
|
mnts = self._user.maintainer_set.all()
|
|
|
|
|
if 'admin_c' in self.fields:
|
|
|
|
|
self.fields['admin_c'].queryset = Contact.objects.filter(mnt_by__in=self._user.maintainer_set.all())
|
|
|
|
|
if instance and instance.pk:
|
|
|
|
|
self.fields['admin_c'].queryset |= instance.admin_c.all()
|
|
|
|
|
self.fields['admin_c'].queryset = Contact.getMntQueryset(mnts, self.instance, "admin_c")
|
|
|
|
|
|
|
|
|
|
def clean_handle(self):
|
|
|
|
|
instance = getattr(self, 'instance', None)
|
|
|
|
|
if instance and instance.pk:
|
|
|
|
|
return instance.handle
|
|
|
|
|
if not self._create:
|
|
|
|
|
return self.instance.handle
|
|
|
|
|
else:
|
|
|
|
|
return self.cleaned_data['handle']
|
|
|
|
|
|
|
|
|
@ -56,17 +57,14 @@ class MntFormMixin(object):
|
|
|
|
|
mntQs = Maintainer.objects.annotate(card=Case(*mntWhens, default=0, output_field=IntegerField())).order_by("-card")
|
|
|
|
|
self.fields["mnt_by"].queryset = mntQs
|
|
|
|
|
|
|
|
|
|
class MntForm(forms.ModelForm):
|
|
|
|
|
if "mnt_lower" in self.fields:
|
|
|
|
|
self.fields["mnt_lower"].queryset = mntQs
|
|
|
|
|
|
|
|
|
|
class MntForm(WhoisObjectFormMixin, forms.ModelForm):
|
|
|
|
|
class Meta:
|
|
|
|
|
model = Maintainer
|
|
|
|
|
fields = ['handle', 'description', 'admin_c']
|
|
|
|
|
|
|
|
|
|
def __init__(self, user, *args, **kwargs):
|
|
|
|
|
super(MntForm, self).__init__(*args, **kwargs)
|
|
|
|
|
self._user = user
|
|
|
|
|
if 'admin_c' in self.fields:
|
|
|
|
|
self.fields['admin_c'].queryset = Contact.objects.filter(mnt_by=user.maintainer_set.all())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MntInitialForm(MntForm):
|
|
|
|
|
class Meta:
|
|
|
|
@ -82,7 +80,7 @@ class ContactForm(WhoisObjectFormMixin, forms.ModelForm):
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
|
super(ContactForm, self).__init__(*args, **kwargs)
|
|
|
|
|
|
|
|
|
|
self.fields['mnt_by'].queryset = Maintainer.objects.filter(auth=self._user)
|
|
|
|
|
self.fields['mnt_by'].queryset = Maintainer.objects.filter(auth=self._user).distinct()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ContactInitialForm(ContactForm):
|
|
|
|
@ -101,16 +99,18 @@ class InetNumForm(MntFormMixin, WhoisObjectFormMixin, forms.ModelForm):
|
|
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
|
super(InetNumForm, self).__init__(*args, **kwargs)
|
|
|
|
|
if 'admin_c' in self.fields:
|
|
|
|
|
self.fields['admin_c'].queryset = Contact.objects.filter(mnt_by__in=self.user.maintainer_set.all())
|
|
|
|
|
instance = getattr(self, "instance", None)
|
|
|
|
|
if instance and instance.pk:
|
|
|
|
|
self.fields['admin_c'].queryset |= instance.admin_c.all()
|
|
|
|
|
|
|
|
|
|
if self._editLower:
|
|
|
|
|
for key in self.protectedFields:
|
|
|
|
|
self.fields[key].disabled = True
|
|
|
|
|
self.fields[key].widget.attrs['readonly'] = False
|
|
|
|
|
|
|
|
|
|
mnts = self._user.maintainer_set.all()
|
|
|
|
|
#self.fields['parent_range'].queryset = InetNum.objects.filter(Q(mnt_by__in=mnts) | Q(mnt_lower__in=mnts))
|
|
|
|
|
#if not self._create:
|
|
|
|
|
# self.fields['parent_range'].queryset |= InetNum.objects.filter(pk=self.instance.pk)
|
|
|
|
|
|
|
|
|
|
#self.fields['parent_range'].queryset = self.fields['parent_range'].queryset.distinct()
|
|
|
|
|
self.fields['parent_range'].queryset = InetNum.getMntQueryset(mnts, self.instance, "parent_range")
|
|
|
|
|
|
|
|
|
|
def clean_prefix(self):
|
|
|
|
|
# make sure this is a subnet we're getting
|
|
|
|
@ -128,9 +128,19 @@ class InetNumForm(MntFormMixin, WhoisObjectFormMixin, forms.ModelForm):
|
|
|
|
|
parent_range = self.cleaned_data.get('parent_range', None)
|
|
|
|
|
|
|
|
|
|
# allow parent range to be unset for already present objects
|
|
|
|
|
if not (self.instance and self.instance.pk) and not parent_range:
|
|
|
|
|
if not parent_range and (self._create or not self._create and self.instance.parent_range):
|
|
|
|
|
raise forms.ValidationError("Parent range must be set")
|
|
|
|
|
|
|
|
|
|
if not self._create and parent_range:
|
|
|
|
|
# make sure we don't have circular dependencies
|
|
|
|
|
obj = parent_range
|
|
|
|
|
while obj.parent_range:
|
|
|
|
|
if obj.pk == self.instance.pk:
|
|
|
|
|
raise forms.ValidationError("No circular dependencies allowed")
|
|
|
|
|
obj = obj.parent_range
|
|
|
|
|
|
|
|
|
|
return parent_range
|
|
|
|
|
|
|
|
|
|
def clean(self):
|
|
|
|
|
cleaned_data = super(InetNumForm, self).clean()
|
|
|
|
|
|
|
|
|
@ -177,6 +187,9 @@ class ASBlockForm(MntFormMixin, WhoisObjectFormMixin, forms.ModelForm):
|
|
|
|
|
if self.instance and self.instance.pk:
|
|
|
|
|
self.fields["parent_block"].disabled = True
|
|
|
|
|
|
|
|
|
|
mnts = self._user.maintainer_set.all()
|
|
|
|
|
self.fields['parent_block'].queryset = ASBlock.getMntQueryset(mnts, self.instance, "parent_block")
|
|
|
|
|
|
|
|
|
|
def clean(self):
|
|
|
|
|
cleaned_data = super(ASBlockForm, self).clean()
|
|
|
|
|
|
|
|
|
@ -229,6 +242,9 @@ class ASNumberForm(MntFormMixin, WhoisObjectFormMixin, forms.ModelForm):
|
|
|
|
|
else:
|
|
|
|
|
self.fields["asblock"].disabled = True
|
|
|
|
|
|
|
|
|
|
mnts = self._user.maintainer_set.all()
|
|
|
|
|
self.fields['asblock'].queryset = ASBlock.getMntQueryset(mnts, self.instance, "asblock")
|
|
|
|
|
|
|
|
|
|
def clean(self):
|
|
|
|
|
cleaned_data = super(ASNumberForm, self).clean()
|
|
|
|
|
|
|
|
|
|