...
 
Commits (15)
......@@ -23,7 +23,7 @@
"""
from rest_framework import permissions, exceptions
from django.http import Http404
from . import acl
......@@ -273,6 +273,8 @@ class AutodetectACLPermission(permissions.BasePermission):
# they have read permissions to see 403, or not, and simply see
# a 404 response.
SAFE_METHODS = ("GET", "OPTIONS", "HEAD", "POST", "PUT", "PATCH", "DELETE")
if request.method in SAFE_METHODS:
# Read permissions already checked and failed, no need
# to make another lookup.
......
......@@ -160,11 +160,6 @@ class DomainForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
fields = ["name", "ttl"]
def __init__(self, *args, **kwargs):
if "user" in kwargs:
user = kwargs["user"]
initial = kwargs.get("initial", {})
initial["name"] = user.get_next_domain_name()
kwargs["initial"] = initial
prefix = kwargs.pop("prefix", self.Meta.model.__name__)
super(DomainForm, self).__init__(*args, prefix=prefix, **kwargs)
......@@ -400,7 +395,7 @@ class NsForm(FormRevMixin, ModelForm):
class DelNsForm(FormRevMixin, Form):
"""Suppresion d'un ou plusieurs NS"""
ns = forms.ModelMultipleChoiceField(
nss = forms.ModelMultipleChoiceField(
queryset=Ns.objects.none(),
label=_("Current NS records"),
widget=forms.CheckboxSelectMultiple,
......@@ -410,9 +405,9 @@ class DelNsForm(FormRevMixin, Form):
instances = kwargs.pop("instances", None)
super(DelNsForm, self).__init__(*args, **kwargs)
if instances:
self.fields["ns"].queryset = instances
self.fields["nss"].queryset = instances
else:
self.fields["ns"].queryset = Ns.objects.all()
self.fields["nss"].queryset = Ns.objects.all()
class TxtForm(FormRevMixin, ModelForm):
......
......@@ -1131,7 +1131,7 @@ class Interface(RevMixin, AclMixin, FieldPermissionModelMixin, models.Model):
try:
oui = mac.oui
vendor = oui.registration().org
except NotRegisteredError:
except (IndexError, NotRegisteredError) as error:
vendor = _("Unknown vendor.")
return vendor
......
......@@ -48,7 +48,7 @@ class IpTypeField(serializers.RelatedField):
""" Serializer for an IpType object field """
def to_representation(self, value):
return value.type
return str(value)
def to_internal_value(self, data):
pass
......@@ -164,7 +164,7 @@ class TypeSerializer(serializers.ModelSerializer):
class Meta:
model = IpType
fields = (
"type",
"name",
"extension",
"domaine_ip_start",
"domaine_ip_stop",
......
......@@ -228,7 +228,7 @@ def new_machine(request, user, **_kwargs):
machine = NewMachineForm(request.POST or None, user=request.user)
interface = AddInterfaceForm(request.POST or None, user=request.user)
domain = DomainForm(request.POST or None, user=user)
domain = DomainForm(request.POST or None, user=user, initial={'name': user.get_next_domain_name()})
if machine.is_valid() and interface.is_valid():
new_machine_obj = machine.save(commit=False)
new_machine_obj.user = user
......@@ -325,7 +325,7 @@ def new_interface(request, machine, **_kwargs):
""" Ajoute une interface et son domain associé à une machine existante"""
interface_form = AddInterfaceForm(request.POST or None, user=request.user)
domain_form = DomainForm(request.POST or None, user=request.user)
domain_form = DomainForm(request.POST or None, user=request.user, initial={'name': machine.user.get_next_domain_name()})
if interface_form.is_valid():
new_interface_obj = interface_form.save(commit=False)
domain_form.instance.interface_parent = new_interface_obj
......@@ -817,9 +817,9 @@ def edit_ns(request, ns_instance, **_kwargs):
@can_delete_set(Ns)
def del_ns(request, instances):
""" View used to delete a NS object """
ns = DelNsForm(request.POST or None, instances=instances)
if ns.is_valid():
ns_dels = ns.cleaned_data["ns"]
nss = DelNsForm(request.POST or None, instances=instances)
if nss.is_valid():
ns_dels = nss.cleaned_data["nss"]
for ns_del in ns_dels:
try:
ns_del.delete()
......@@ -830,7 +830,7 @@ def del_ns(request, instances):
)
return redirect(reverse("machines:index-extension"))
return form(
{"nsform": ns, "action_name": _("Delete")}, "machines/machine.html", request
{"nsform": nss, "action_name": _("Delete")}, "machines/machine.html", request
)
......