Noot
This commit is contained in:
parent
d544e3364f
commit
ed5fee0b13
11
api/views.py
11
api/views.py
|
@ -84,6 +84,16 @@ def freeSubnet(request):
|
|||
raise ValidationError("Given prefix length is out of range")
|
||||
except ValueError:
|
||||
raise ValidationError("PrefixLen is not a number")
|
||||
|
||||
usableNet = None
|
||||
# FIXME: use first biggest usable netblock...
|
||||
#biggestNet = parentRange.inetnum_set.order_by("-address")
|
||||
#if biggestNet
|
||||
# candidateNet =
|
||||
# and (biggestNet.getNetwork().broadcast_address.:
|
||||
|
||||
if not usableNet:
|
||||
# search for free network
|
||||
nets = list(parentRange.getNetwork().subnets())
|
||||
for subRange in parentRange.inetnum_set.all():
|
||||
newNet = None
|
||||
|
@ -98,7 +108,6 @@ def freeSubnet(request):
|
|||
nets.extend(newNet.address_exclude(subRange.getNetwork()))
|
||||
|
||||
nets = sorted(nets)
|
||||
usableNet = None
|
||||
for net in nets:
|
||||
if net.prefixlen <= prefixLen:
|
||||
usableNet = net
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
from django import forms
|
||||
|
||||
|
||||
class MultiTextInput(forms.widgets.Input):
|
||||
input_type = "text"
|
||||
|
||||
def render(self, name, value, attrs=None):
|
||||
if value is not None:
|
||||
selectedOptions = []
|
||||
for val in value:
|
||||
for k, v in self.choices:
|
||||
if val == k:
|
||||
selectedOptions.append(v)
|
||||
|
||||
value = " ".join(selectedOptions)
|
||||
|
||||
return super(MultiTextInput, self).render(name, value, attrs)
|
||||
|
||||
def value_from_datadict(self, data, files, name):
|
||||
values = list(filter(bool, map(lambda _x: _x.strip(), data.get(name).split(" "))))
|
||||
|
||||
result = []
|
||||
for value in values:
|
||||
# FIXME: using value here throws a weird error message at some point
|
||||
# could be handled by overriding the messages in ChoiceField
|
||||
# or... well, don't know
|
||||
kId = value
|
||||
for k, v in self.choices:
|
||||
if v.lower() == value.lower():
|
||||
kId = str(k)
|
||||
break
|
||||
result.append(kId)
|
||||
|
||||
return result
|
|
@ -3,6 +3,7 @@ from django.db.models import Case, When, IntegerField
|
|||
|
||||
from .models import Maintainer, Contact, InetNum, ASBlock, ASNumber
|
||||
from .validators import HandleValidatorWithSuffix, IP46CIDRValidator
|
||||
from .formfields import MultiTextInput
|
||||
|
||||
import ipaddress
|
||||
|
||||
|
@ -69,7 +70,20 @@ class MntFormMixin(object):
|
|||
class MntForm(WhoisObjectFormMixin, forms.ModelForm):
|
||||
class Meta:
|
||||
model = Maintainer
|
||||
fields = ['handle', 'description', 'admin_c']
|
||||
fields = ['handle', 'description', 'admin_c', 'auth']
|
||||
widgets = {'auth': MultiTextInput()}
|
||||
|
||||
help_texts = {
|
||||
'auth': 'Enter names of users which can edit this object (space separated; '
|
||||
'and yes, validation is somewhat broken (values disappear on error - just reload))'
|
||||
}
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(MntForm, self).__init__(*args, **kwargs)
|
||||
print(args, kwargs)
|
||||
|
||||
#if self._create:
|
||||
# self.fields['auth'].text("noot")
|
||||
|
||||
|
||||
class MntInitialForm(MntForm):
|
||||
|
|
Loading…
Reference in New Issue