8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-16 00:13:12 +00:00

Add or translate some docstrings in machines/

This commit is contained in:
Laouen Fernet 2020-04-30 00:17:01 +02:00 committed by chirac
parent 3b697f9795
commit fb9ae20f37
3 changed files with 802 additions and 447 deletions

View file

@ -22,15 +22,15 @@
# with this program; if not, write to the Free Software Foundation, Inc., # with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
""" """
Formulaires d'ajout, edition et suppressions de : Forms to create, edit and delete:
- machines * machines
- interfaces * interfaces
- domain (noms de machine) * domains (machine names)
- alias (cname) * aliases (CNAME)
- service (dhcp, dns..) * services (DHCP, DNS...)
- ns (serveur dns) * NS records (DNS server)
- mx (serveur mail) * MX records (mail serveur)
- ports ouverts et profils d'ouverture par interface * open ports and ports opening for interfaces
""" """
from __future__ import unicode_literals from __future__ import unicode_literals
@ -66,7 +66,7 @@ from .models import (
class EditMachineForm(FormRevMixin, FieldPermissionFormMixin, ModelForm): class EditMachineForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
"""Formulaire d'édition d'une machine""" """Form used to edit a machine."""
class Meta: class Meta:
model = Machine model = Machine
@ -79,14 +79,14 @@ class EditMachineForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
class NewMachineForm(EditMachineForm): class NewMachineForm(EditMachineForm):
"""Creation d'une machine, ne renseigne que le nom""" """Form used to create a machine."""
class Meta(EditMachineForm.Meta): class Meta(EditMachineForm.Meta):
fields = ["name"] fields = ["name"]
class EditInterfaceForm(FormRevMixin, FieldPermissionFormMixin, ModelForm): class EditInterfaceForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
"""Edition d'une interface. Edition complète""" """Form used to edit an interface."""
class Meta: class Meta:
model = Interface model = Interface
@ -127,15 +127,14 @@ class EditInterfaceForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
class AddInterfaceForm(EditInterfaceForm): class AddInterfaceForm(EditInterfaceForm):
"""Ajout d'une interface à une machine. En fonction des droits, """Form used to add an interface to a machine."""
affiche ou non l'ensemble des ip disponibles"""
class Meta(EditInterfaceForm.Meta): class Meta(EditInterfaceForm.Meta):
fields = ["machine_type", "ipv4", "mac_address", "details"] fields = ["machine_type", "ipv4", "mac_address", "details"]
class AliasForm(FormRevMixin, FieldPermissionFormMixin, ModelForm): class AliasForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
"""Ajout d'un alias (et edition), CNAME, contenant nom et extension""" """Form used to add and edit an alias (CNAME)."""
class Meta: class Meta:
model = Domain model = Domain
@ -153,7 +152,9 @@ class AliasForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
class DomainForm(FormRevMixin, FieldPermissionFormMixin, ModelForm): class DomainForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
"""Ajout et edition d'un enregistrement de nom, relié à interface""" """Form used to add and edit a domain record, related to an
interface.
"""
class Meta: class Meta:
model = Domain model = Domain
@ -165,7 +166,7 @@ class DomainForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
class DelAliasForm(FormRevMixin, Form): class DelAliasForm(FormRevMixin, Form):
"""Suppression d'un ou plusieurs objets alias""" """Form used to delete one or several aliases."""
alias = forms.ModelMultipleChoiceField( alias = forms.ModelMultipleChoiceField(
queryset=Domain.objects.all(), queryset=Domain.objects.all(),
@ -182,7 +183,7 @@ class DelAliasForm(FormRevMixin, Form):
class MachineTypeForm(FormRevMixin, ModelForm): class MachineTypeForm(FormRevMixin, ModelForm):
"""Ajout et edition d'un machinetype, relié à un iptype""" """Form used to add and edit a machine type, related to an IP type."""
class Meta: class Meta:
model = MachineType model = MachineType
@ -196,7 +197,7 @@ class MachineTypeForm(FormRevMixin, ModelForm):
class DelMachineTypeForm(FormRevMixin, Form): class DelMachineTypeForm(FormRevMixin, Form):
"""Suppression d'un ou plusieurs machinetype""" """Form used to delete one or several machines types."""
machinetypes = forms.ModelMultipleChoiceField( machinetypes = forms.ModelMultipleChoiceField(
queryset=MachineType.objects.none(), queryset=MachineType.objects.none(),
@ -214,8 +215,9 @@ class DelMachineTypeForm(FormRevMixin, Form):
class IpTypeForm(FormRevMixin, ModelForm): class IpTypeForm(FormRevMixin, ModelForm):
"""Formulaire d'ajout d'un iptype. Pas d'edition de l'ip de start et de """Form used to add an IP type. The start and stop IP addresses cannot
stop après creation""" be changed afterwards.
"""
class Meta: class Meta:
model = IpType model = IpType
@ -228,8 +230,9 @@ class IpTypeForm(FormRevMixin, ModelForm):
class EditIpTypeForm(IpTypeForm): class EditIpTypeForm(IpTypeForm):
"""Edition d'un iptype. Pas d'edition du rangev4 possible, car il faudrait """Form used to edit an IP type. The start and stop IP addresses cannot
synchroniser les objets iplist""" be changed.
"""
class Meta(IpTypeForm.Meta): class Meta(IpTypeForm.Meta):
fields = [ fields = [
@ -248,7 +251,7 @@ class EditIpTypeForm(IpTypeForm):
class DelIpTypeForm(FormRevMixin, Form): class DelIpTypeForm(FormRevMixin, Form):
"""Suppression d'un ou plusieurs iptype""" """Form used to delete one or several IP types."""
iptypes = forms.ModelMultipleChoiceField( iptypes = forms.ModelMultipleChoiceField(
queryset=IpType.objects.none(), queryset=IpType.objects.none(),
@ -266,7 +269,7 @@ class DelIpTypeForm(FormRevMixin, Form):
class ExtensionForm(FormRevMixin, ModelForm): class ExtensionForm(FormRevMixin, ModelForm):
"""Formulaire d'ajout et edition d'une extension""" """Form used to add and edit extensions."""
class Meta: class Meta:
model = Extension model = Extension
@ -283,7 +286,7 @@ class ExtensionForm(FormRevMixin, ModelForm):
class DelExtensionForm(FormRevMixin, Form): class DelExtensionForm(FormRevMixin, Form):
"""Suppression d'une ou plusieurs extensions""" """Form used to delete one or several extensions."""
extensions = forms.ModelMultipleChoiceField( extensions = forms.ModelMultipleChoiceField(
queryset=Extension.objects.none(), queryset=Extension.objects.none(),
@ -301,7 +304,7 @@ class DelExtensionForm(FormRevMixin, Form):
class Ipv6ListForm(FormRevMixin, FieldPermissionFormMixin, ModelForm): class Ipv6ListForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
"""Gestion des ipv6 d'une machine""" """Form used to manage lists of IPv6 addresses."""
class Meta: class Meta:
model = Ipv6List model = Ipv6List
@ -313,7 +316,7 @@ class Ipv6ListForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
class SOAForm(FormRevMixin, ModelForm): class SOAForm(FormRevMixin, ModelForm):
"""Ajout et edition d'un SOA""" """Form used to add and edit SOA records."""
class Meta: class Meta:
model = SOA model = SOA
@ -325,7 +328,7 @@ class SOAForm(FormRevMixin, ModelForm):
class DelSOAForm(FormRevMixin, Form): class DelSOAForm(FormRevMixin, Form):
"""Suppression d'un ou plusieurs SOA""" """Form used to delete one or several SOA records."""
soa = forms.ModelMultipleChoiceField( soa = forms.ModelMultipleChoiceField(
queryset=SOA.objects.none(), queryset=SOA.objects.none(),
@ -343,7 +346,7 @@ class DelSOAForm(FormRevMixin, Form):
class MxForm(FormRevMixin, ModelForm): class MxForm(FormRevMixin, ModelForm):
"""Ajout et edition d'un MX""" """Form used to add and edit MX records."""
class Meta: class Meta:
model = Mx model = Mx
@ -358,7 +361,7 @@ class MxForm(FormRevMixin, ModelForm):
class DelMxForm(FormRevMixin, Form): class DelMxForm(FormRevMixin, Form):
"""Suppression d'un ou plusieurs MX""" """Form used to delete one or several MX records."""
mx = forms.ModelMultipleChoiceField( mx = forms.ModelMultipleChoiceField(
queryset=Mx.objects.none(), queryset=Mx.objects.none(),
@ -376,9 +379,9 @@ class DelMxForm(FormRevMixin, Form):
class NsForm(FormRevMixin, ModelForm): class NsForm(FormRevMixin, ModelForm):
"""Ajout d'un NS pour une zone """Form used to add and edit NS records. Only interface names are
On exclue les CNAME dans les objets domain (interdit par la rfc) available because CNAME aliases should not be used in the records.
donc on prend uniquemet """ """
class Meta: class Meta:
model = Ns model = Ns
@ -393,7 +396,7 @@ class NsForm(FormRevMixin, ModelForm):
class DelNsForm(FormRevMixin, Form): class DelNsForm(FormRevMixin, Form):
"""Suppresion d'un ou plusieurs NS""" """Form used to delete one or several NS records."""
nss = forms.ModelMultipleChoiceField( nss = forms.ModelMultipleChoiceField(
queryset=Ns.objects.none(), queryset=Ns.objects.none(),
@ -411,7 +414,7 @@ class DelNsForm(FormRevMixin, Form):
class TxtForm(FormRevMixin, ModelForm): class TxtForm(FormRevMixin, ModelForm):
"""Ajout d'un txt pour une zone""" """Form used to add and edit TXT records."""
class Meta: class Meta:
model = Txt model = Txt
@ -423,7 +426,7 @@ class TxtForm(FormRevMixin, ModelForm):
class DelTxtForm(FormRevMixin, Form): class DelTxtForm(FormRevMixin, Form):
"""Suppression d'un ou plusieurs TXT""" """Form used to delete one or several TXT records."""
txt = forms.ModelMultipleChoiceField( txt = forms.ModelMultipleChoiceField(
queryset=Txt.objects.none(), queryset=Txt.objects.none(),
@ -441,7 +444,7 @@ class DelTxtForm(FormRevMixin, Form):
class DNameForm(FormRevMixin, ModelForm): class DNameForm(FormRevMixin, ModelForm):
"""Add a DNAME entry for a zone""" """Form used to add and edit DNAME records."""
class Meta: class Meta:
model = DName model = DName
@ -453,7 +456,7 @@ class DNameForm(FormRevMixin, ModelForm):
class DelDNameForm(FormRevMixin, Form): class DelDNameForm(FormRevMixin, Form):
"""Delete a set of DNAME entries""" """Form used to delete one or several DNAME records."""
dnames = forms.ModelMultipleChoiceField( dnames = forms.ModelMultipleChoiceField(
queryset=Txt.objects.none(), queryset=Txt.objects.none(),
@ -471,7 +474,7 @@ class DelDNameForm(FormRevMixin, Form):
class SrvForm(FormRevMixin, ModelForm): class SrvForm(FormRevMixin, ModelForm):
"""Ajout d'un srv pour une zone""" """Form used to add and edit SRV records."""
class Meta: class Meta:
model = Srv model = Srv
@ -483,7 +486,7 @@ class SrvForm(FormRevMixin, ModelForm):
class DelSrvForm(FormRevMixin, Form): class DelSrvForm(FormRevMixin, Form):
"""Suppression d'un ou plusieurs Srv""" """Form used to delete one or several SRV records."""
srv = forms.ModelMultipleChoiceField( srv = forms.ModelMultipleChoiceField(
queryset=Srv.objects.none(), queryset=Srv.objects.none(),
@ -501,8 +504,7 @@ class DelSrvForm(FormRevMixin, Form):
class NasForm(FormRevMixin, ModelForm): class NasForm(FormRevMixin, ModelForm):
"""Ajout d'un type de nas (machine d'authentification, """Form used to create and edit NAS devices."""
swicths, bornes...)"""
class Meta: class Meta:
model = Nas model = Nas
@ -514,7 +516,7 @@ class NasForm(FormRevMixin, ModelForm):
class DelNasForm(FormRevMixin, Form): class DelNasForm(FormRevMixin, Form):
"""Suppression d'un ou plusieurs nas""" """Form used to delete one or several NAS devices."""
nas = forms.ModelMultipleChoiceField( nas = forms.ModelMultipleChoiceField(
queryset=Nas.objects.none(), queryset=Nas.objects.none(),
@ -532,7 +534,7 @@ class DelNasForm(FormRevMixin, Form):
class RoleForm(FormRevMixin, ModelForm): class RoleForm(FormRevMixin, ModelForm):
"""Add and edit role.""" """Form used to add and edit roles."""
class Meta: class Meta:
model = Role model = Role
@ -547,7 +549,7 @@ class RoleForm(FormRevMixin, ModelForm):
class DelRoleForm(FormRevMixin, Form): class DelRoleForm(FormRevMixin, Form):
"""Deletion of one or several roles.""" """Form used to delete one or several roles."""
role = forms.ModelMultipleChoiceField( role = forms.ModelMultipleChoiceField(
queryset=Role.objects.none(), queryset=Role.objects.none(),
@ -565,7 +567,7 @@ class DelRoleForm(FormRevMixin, Form):
class ServiceForm(FormRevMixin, ModelForm): class ServiceForm(FormRevMixin, ModelForm):
"""Ajout et edition d'une classe de service : dns, dhcp, etc""" """Form to add and edit services (DHCP, DNS etc.)."""
class Meta: class Meta:
model = Service model = Service
@ -589,7 +591,7 @@ class ServiceForm(FormRevMixin, ModelForm):
class DelServiceForm(FormRevMixin, Form): class DelServiceForm(FormRevMixin, Form):
"""Suppression d'un ou plusieurs service""" """Form used to delete one or several services."""
service = forms.ModelMultipleChoiceField( service = forms.ModelMultipleChoiceField(
queryset=Service.objects.none(), queryset=Service.objects.none(),
@ -607,7 +609,7 @@ class DelServiceForm(FormRevMixin, Form):
class VlanForm(FormRevMixin, ModelForm): class VlanForm(FormRevMixin, ModelForm):
"""Ajout d'un vlan : id, nom""" """Form used to add and edit VLANs."""
class Meta: class Meta:
model = Vlan model = Vlan
@ -619,7 +621,7 @@ class VlanForm(FormRevMixin, ModelForm):
class EditOptionVlanForm(FormRevMixin, ModelForm): class EditOptionVlanForm(FormRevMixin, ModelForm):
"""Ajout d'un vlan : id, nom""" """Form used to edit the options of a VLAN."""
class Meta: class Meta:
model = Vlan model = Vlan
@ -631,7 +633,7 @@ class EditOptionVlanForm(FormRevMixin, ModelForm):
class DelVlanForm(FormRevMixin, Form): class DelVlanForm(FormRevMixin, Form):
"""Suppression d'un ou plusieurs vlans""" """Form used to delete one or several VLANs."""
vlan = forms.ModelMultipleChoiceField( vlan = forms.ModelMultipleChoiceField(
queryset=Vlan.objects.none(), queryset=Vlan.objects.none(),
@ -649,8 +651,7 @@ class DelVlanForm(FormRevMixin, Form):
class EditOuverturePortConfigForm(FormRevMixin, ModelForm): class EditOuverturePortConfigForm(FormRevMixin, ModelForm):
"""Edition de la liste des profils d'ouverture de ports """Form to edit the ports opening list of an interface."""
pour l'interface"""
class Meta: class Meta:
model = Interface model = Interface
@ -664,8 +665,7 @@ class EditOuverturePortConfigForm(FormRevMixin, ModelForm):
class EditOuverturePortListForm(FormRevMixin, ModelForm): class EditOuverturePortListForm(FormRevMixin, ModelForm):
"""Edition de la liste des ports et profils d'ouverture """Form used to add and edit ports opening lists."""
des ports"""
class Meta: class Meta:
model = OuverturePortList model = OuverturePortList
@ -677,7 +677,7 @@ class EditOuverturePortListForm(FormRevMixin, ModelForm):
class SshFpForm(FormRevMixin, ModelForm): class SshFpForm(FormRevMixin, ModelForm):
"""Edits a SSHFP record.""" """Form used to add and edit SSHFP records."""
class Meta: class Meta:
model = SshFp model = SshFp

File diff suppressed because it is too large Load diff

View file

@ -211,10 +211,11 @@ def generate_ipv4_mbf_param(form_obj, is_type_tt):
@can_create(Machine) @can_create(Machine)
@can_edit(User) @can_edit(User)
def new_machine(request, user, **_kwargs): def new_machine(request, user, **_kwargs):
""" Fonction de creation d'une machine. Cree l'objet machine, """View used to create machines.
le sous objet interface et l'objet domain à partir de model forms.
Trop complexe, devrait être simplifié"""
Creates the object, the underlying interface and domain objects from model
forms. Too complex, should be simplified.
"""
machine = NewMachineForm(request.POST or None, user=request.user) machine = NewMachineForm(request.POST or None, user=request.user)
interface = AddInterfaceForm(request.POST or None, user=request.user) interface = AddInterfaceForm(request.POST or None, user=request.user)
domain = DomainForm(request.POST or None, user=user, initial={'name': user.get_next_domain_name()}) domain = DomainForm(request.POST or None, user=user, initial={'name': user.get_next_domain_name()})
@ -249,10 +250,10 @@ def new_machine(request, user, **_kwargs):
@login_required @login_required
@can_edit(Interface) @can_edit(Interface)
def edit_interface(request, interface_instance, **_kwargs): def edit_interface(request, interface_instance, **_kwargs):
""" Edition d'une interface. Distingue suivant les droits les valeurs """View used to edit interfaces.
de interfaces et machines que l'user peut modifier infra permet de
modifier le propriétaire"""
The values a user can change depends on their rights.
"""
machine_form = EditMachineForm( machine_form = EditMachineForm(
request.POST or None, instance=interface_instance.machine, user=request.user request.POST or None, instance=interface_instance.machine, user=request.user
) )
@ -295,7 +296,7 @@ def edit_interface(request, interface_instance, **_kwargs):
@login_required @login_required
@can_delete(Machine) @can_delete(Machine)
def del_machine(request, machine, **_kwargs): def del_machine(request, machine, **_kwargs):
""" Supprime une machine, interfaces en mode cascade""" """View used to delete machines, and the interfaces in cascade."""
if request.method == "POST": if request.method == "POST":
machine.delete() machine.delete()
messages.success(request, _("The machine was deleted.")) messages.success(request, _("The machine was deleted."))
@ -311,8 +312,9 @@ def del_machine(request, machine, **_kwargs):
@can_create(Interface) @can_create(Interface)
@can_edit(Machine) @can_edit(Machine)
def new_interface(request, machine, **_kwargs): def new_interface(request, machine, **_kwargs):
""" Ajoute une interface et son domain associé à une machine existante""" """View used to create interfaces and the associated domains related to a
machine.
"""
interface_form = AddInterfaceForm(request.POST or None, user=request.user) interface_form = AddInterfaceForm(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()}) domain_form = DomainForm(request.POST or None, user=request.user, initial={'name': machine.user.get_next_domain_name()})
if interface_form.is_valid(): if interface_form.is_valid():
@ -344,7 +346,7 @@ def new_interface(request, machine, **_kwargs):
@login_required @login_required
@can_delete(Interface) @can_delete(Interface)
def del_interface(request, interface, **_kwargs): def del_interface(request, interface, **_kwargs):
""" Supprime une interface. Domain objet en mode cascade""" """View used to delete interfaces, and the domains in cascade."""
if request.method == "POST": if request.method == "POST":
machine = interface.machine machine = interface.machine
interface.delete() interface.delete()
@ -363,7 +365,7 @@ def del_interface(request, interface, **_kwargs):
@can_create(Ipv6List) @can_create(Ipv6List)
@can_edit(Interface) @can_edit(Interface)
def new_ipv6list(request, interface, **_kwargs): def new_ipv6list(request, interface, **_kwargs):
"""Nouvelle ipv6""" """View used to create IPv6 addresses lists."""
ipv6list_instance = Ipv6List(interface=interface) ipv6list_instance = Ipv6List(interface=interface)
ipv6 = Ipv6ListForm( ipv6 = Ipv6ListForm(
request.POST or None, instance=ipv6list_instance, user=request.user request.POST or None, instance=ipv6list_instance, user=request.user
@ -384,7 +386,7 @@ def new_ipv6list(request, interface, **_kwargs):
@login_required @login_required
@can_edit(Ipv6List) @can_edit(Ipv6List)
def edit_ipv6list(request, ipv6list_instance, **_kwargs): def edit_ipv6list(request, ipv6list_instance, **_kwargs):
"""Edition d'une ipv6""" """View used to edit IPv6 addresses lists."""
ipv6 = Ipv6ListForm( ipv6 = Ipv6ListForm(
request.POST or None, instance=ipv6list_instance, user=request.user request.POST or None, instance=ipv6list_instance, user=request.user
) )
@ -406,7 +408,7 @@ def edit_ipv6list(request, ipv6list_instance, **_kwargs):
@login_required @login_required
@can_delete(Ipv6List) @can_delete(Ipv6List)
def del_ipv6list(request, ipv6list, **_kwargs): def del_ipv6list(request, ipv6list, **_kwargs):
""" Supprime une ipv6""" """View used to delete IPv6 addresses lists."""
if request.method == "POST": if request.method == "POST":
interfaceid = ipv6list.interface.id interfaceid = ipv6list.interface.id
ipv6list.delete() ipv6list.delete()
@ -423,7 +425,7 @@ def del_ipv6list(request, ipv6list, **_kwargs):
@can_create(SshFp) @can_create(SshFp)
@can_edit(Machine) @can_edit(Machine)
def new_sshfp(request, machine, **_kwargs): def new_sshfp(request, machine, **_kwargs):
"""Creates an SSHFP record associated with a machine""" """View used to create SSHFP records associated with machines."""
sshfp_instance = SshFp(machine=machine) sshfp_instance = SshFp(machine=machine)
sshfp = SshFpForm(request.POST or None, instance=sshfp_instance) sshfp = SshFpForm(request.POST or None, instance=sshfp_instance)
if sshfp.is_valid(): if sshfp.is_valid():
@ -442,7 +444,7 @@ def new_sshfp(request, machine, **_kwargs):
@login_required @login_required
@can_edit(SshFp) @can_edit(SshFp)
def edit_sshfp(request, sshfp_instance, **_kwargs): def edit_sshfp(request, sshfp_instance, **_kwargs):
"""Edits an SSHFP record""" """View used to edit SSHFP records."""
sshfp = SshFpForm(request.POST or None, instance=sshfp_instance) sshfp = SshFpForm(request.POST or None, instance=sshfp_instance)
if sshfp.is_valid(): if sshfp.is_valid():
if sshfp.changed_data: if sshfp.changed_data:
@ -462,7 +464,7 @@ def edit_sshfp(request, sshfp_instance, **_kwargs):
@login_required @login_required
@can_delete(SshFp) @can_delete(SshFp)
def del_sshfp(request, sshfp, **_kwargs): def del_sshfp(request, sshfp, **_kwargs):
"""Deletes an SSHFP record""" """View used to delete SSHFP records."""
if request.method == "POST": if request.method == "POST":
machineid = sshfp.machine.id machineid = sshfp.machine.id
sshfp.delete() sshfp.delete()
@ -478,9 +480,10 @@ def del_sshfp(request, sshfp, **_kwargs):
@login_required @login_required
@can_create(IpType) @can_create(IpType)
def add_iptype(request): def add_iptype(request):
""" Ajoute un range d'ip. Intelligence dans le models, fonction views """View used to create IP ranges.
minimaliste"""
The view function is simple, the intelligence is in the model.
"""
iptype = IpTypeForm(request.POST or None) iptype = IpTypeForm(request.POST or None)
if iptype.is_valid(): if iptype.is_valid():
iptype.save() iptype.save()
@ -496,9 +499,10 @@ def add_iptype(request):
@login_required @login_required
@can_edit(IpType) @can_edit(IpType)
def edit_iptype(request, iptype_instance, **_kwargs): def edit_iptype(request, iptype_instance, **_kwargs):
""" Edition d'un range. Ne permet pas de le redimensionner pour éviter """View used to edit IP ranges.
l'incohérence"""
Changing the size of the range is not possible to prevent inconsistency.
"""
iptype = EditIpTypeForm(request.POST or None, instance=iptype_instance) iptype = EditIpTypeForm(request.POST or None, instance=iptype_instance)
if iptype.is_valid(): if iptype.is_valid():
if iptype.changed_data: if iptype.changed_data:
@ -515,7 +519,10 @@ def edit_iptype(request, iptype_instance, **_kwargs):
@login_required @login_required
@can_delete_set(IpType) @can_delete_set(IpType)
def del_iptype(request, instances): def del_iptype(request, instances):
""" Suppression d'un range ip. Supprime les objets ip associés""" """View used to delete IP ranges.
Deletes the related IP objects.
"""
iptype = DelIpTypeForm(request.POST or None, instances=instances) iptype = DelIpTypeForm(request.POST or None, instances=instances)
if iptype.is_valid(): if iptype.is_valid():
iptype_dels = iptype.cleaned_data["iptypes"] iptype_dels = iptype.cleaned_data["iptypes"]
@ -545,7 +552,7 @@ def del_iptype(request, instances):
@login_required @login_required
@can_create(MachineType) @can_create(MachineType)
def add_machinetype(request): def add_machinetype(request):
""" View used to add a Machinetype object """ """View used to create machine types."""
machinetype = MachineTypeForm(request.POST or None) machinetype = MachineTypeForm(request.POST or None)
if machinetype.is_valid(): if machinetype.is_valid():
machinetype.save() machinetype.save()
@ -561,7 +568,7 @@ def add_machinetype(request):
@login_required @login_required
@can_edit(MachineType) @can_edit(MachineType)
def edit_machinetype(request, machinetype_instance, **_kwargs): def edit_machinetype(request, machinetype_instance, **_kwargs):
""" View used to edit a MachineType object """ """View used to edit machine types."""
machinetype = MachineTypeForm(request.POST or None, instance=machinetype_instance) machinetype = MachineTypeForm(request.POST or None, instance=machinetype_instance)
if machinetype.is_valid(): if machinetype.is_valid():
if machinetype.changed_data: if machinetype.changed_data:
@ -578,7 +585,7 @@ def edit_machinetype(request, machinetype_instance, **_kwargs):
@login_required @login_required
@can_delete_set(MachineType) @can_delete_set(MachineType)
def del_machinetype(request, instances): def del_machinetype(request, instances):
""" View used to delete a MachineType object """ """View used to delete machines types."""
machinetype = DelMachineTypeForm(request.POST or None, instances=instances) machinetype = DelMachineTypeForm(request.POST or None, instances=instances)
if machinetype.is_valid(): if machinetype.is_valid():
machinetype_dels = machinetype.cleaned_data["machinetypes"] machinetype_dels = machinetype.cleaned_data["machinetypes"]
@ -608,7 +615,7 @@ def del_machinetype(request, instances):
@login_required @login_required
@can_create(Extension) @can_create(Extension)
def add_extension(request): def add_extension(request):
""" View used to add an Extension object """ """View used to create extensions."""
extension = ExtensionForm(request.POST or None) extension = ExtensionForm(request.POST or None)
if extension.is_valid(): if extension.is_valid():
extension.save() extension.save()
@ -624,7 +631,7 @@ def add_extension(request):
@login_required @login_required
@can_edit(Extension) @can_edit(Extension)
def edit_extension(request, extension_instance, **_kwargs): def edit_extension(request, extension_instance, **_kwargs):
""" View used to edit an Extension object """ """View used to edit extensions."""
extension = ExtensionForm(request.POST or None, instance=extension_instance) extension = ExtensionForm(request.POST or None, instance=extension_instance)
if extension.is_valid(): if extension.is_valid():
if extension.changed_data: if extension.changed_data:
@ -641,7 +648,7 @@ def edit_extension(request, extension_instance, **_kwargs):
@login_required @login_required
@can_delete_set(Extension) @can_delete_set(Extension)
def del_extension(request, instances): def del_extension(request, instances):
""" View used to delete an Extension object """ """View used to delete extensions."""
extension = DelExtensionForm(request.POST or None, instances=instances) extension = DelExtensionForm(request.POST or None, instances=instances)
if extension.is_valid(): if extension.is_valid():
extension_dels = extension.cleaned_data["extensions"] extension_dels = extension.cleaned_data["extensions"]
@ -670,7 +677,7 @@ def del_extension(request, instances):
@login_required @login_required
@can_create(SOA) @can_create(SOA)
def add_soa(request): def add_soa(request):
""" View used to add a SOA object """ """View used to create SOA records."""
soa = SOAForm(request.POST or None) soa = SOAForm(request.POST or None)
if soa.is_valid(): if soa.is_valid():
soa.save() soa.save()
@ -686,7 +693,7 @@ def add_soa(request):
@login_required @login_required
@can_edit(SOA) @can_edit(SOA)
def edit_soa(request, soa_instance, **_kwargs): def edit_soa(request, soa_instance, **_kwargs):
""" View used to edit a SOA object """ """View used to edit SOA records."""
soa = SOAForm(request.POST or None, instance=soa_instance) soa = SOAForm(request.POST or None, instance=soa_instance)
if soa.is_valid(): if soa.is_valid():
if soa.changed_data: if soa.changed_data:
@ -701,7 +708,7 @@ def edit_soa(request, soa_instance, **_kwargs):
@login_required @login_required
@can_delete_set(SOA) @can_delete_set(SOA)
def del_soa(request, instances): def del_soa(request, instances):
""" View used to delete a SOA object """ """View used to delete SOA records."""
soa = DelSOAForm(request.POST or None, instances=instances) soa = DelSOAForm(request.POST or None, instances=instances)
if soa.is_valid(): if soa.is_valid():
soa_dels = soa.cleaned_data["soa"] soa_dels = soa.cleaned_data["soa"]
@ -722,7 +729,7 @@ def del_soa(request, instances):
@login_required @login_required
@can_create(Mx) @can_create(Mx)
def add_mx(request): def add_mx(request):
""" View used to add a MX object """ """View used to create MX records."""
mx = MxForm(request.POST or None) mx = MxForm(request.POST or None)
if mx.is_valid(): if mx.is_valid():
mx.save() mx.save()
@ -738,7 +745,7 @@ def add_mx(request):
@login_required @login_required
@can_edit(Mx) @can_edit(Mx)
def edit_mx(request, mx_instance, **_kwargs): def edit_mx(request, mx_instance, **_kwargs):
""" View used to edit a MX object """ """View used to edit MX records."""
mx = MxForm(request.POST or None, instance=mx_instance) mx = MxForm(request.POST or None, instance=mx_instance)
if mx.is_valid(): if mx.is_valid():
if mx.changed_data: if mx.changed_data:
@ -753,7 +760,7 @@ def edit_mx(request, mx_instance, **_kwargs):
@login_required @login_required
@can_delete_set(Mx) @can_delete_set(Mx)
def del_mx(request, instances): def del_mx(request, instances):
""" View used to delete a MX object """ """View used to delete MX records."""
mx = DelMxForm(request.POST or None, instances=instances) mx = DelMxForm(request.POST or None, instances=instances)
if mx.is_valid(): if mx.is_valid():
mx_dels = mx.cleaned_data["mx"] mx_dels = mx.cleaned_data["mx"]
@ -774,7 +781,7 @@ def del_mx(request, instances):
@login_required @login_required
@can_create(Ns) @can_create(Ns)
def add_ns(request): def add_ns(request):
""" View used to add a NS object """ """View used to create NS records."""
ns = NsForm(request.POST or None) ns = NsForm(request.POST or None)
if ns.is_valid(): if ns.is_valid():
ns.save() ns.save()
@ -790,7 +797,7 @@ def add_ns(request):
@login_required @login_required
@can_edit(Ns) @can_edit(Ns)
def edit_ns(request, ns_instance, **_kwargs): def edit_ns(request, ns_instance, **_kwargs):
""" View used to edit a NS object """ """View used to edit NS records."""
ns = NsForm(request.POST or None, instance=ns_instance) ns = NsForm(request.POST or None, instance=ns_instance)
if ns.is_valid(): if ns.is_valid():
if ns.changed_data: if ns.changed_data:
@ -805,7 +812,7 @@ def edit_ns(request, ns_instance, **_kwargs):
@login_required @login_required
@can_delete_set(Ns) @can_delete_set(Ns)
def del_ns(request, instances): def del_ns(request, instances):
""" View used to delete a NS object """ """View used to delete NS records."""
nss = DelNsForm(request.POST or None, instances=instances) nss = DelNsForm(request.POST or None, instances=instances)
if nss.is_valid(): if nss.is_valid():
ns_dels = nss.cleaned_data["nss"] ns_dels = nss.cleaned_data["nss"]
@ -826,7 +833,7 @@ def del_ns(request, instances):
@login_required @login_required
@can_create(DName) @can_create(DName)
def add_dname(request): def add_dname(request):
""" View used to add a DName object """ """View used to create DNAME records."""
dname = DNameForm(request.POST or None) dname = DNameForm(request.POST or None)
if dname.is_valid(): if dname.is_valid():
dname.save() dname.save()
@ -842,7 +849,7 @@ def add_dname(request):
@login_required @login_required
@can_edit(DName) @can_edit(DName)
def edit_dname(request, dname_instance, **_kwargs): def edit_dname(request, dname_instance, **_kwargs):
""" View used to edit a DName object """ """View used to edit DNAME records."""
dname = DNameForm(request.POST or None, instance=dname_instance) dname = DNameForm(request.POST or None, instance=dname_instance)
if dname.is_valid(): if dname.is_valid():
if dname.changed_data: if dname.changed_data:
@ -857,7 +864,7 @@ def edit_dname(request, dname_instance, **_kwargs):
@login_required @login_required
@can_delete_set(DName) @can_delete_set(DName)
def del_dname(request, instances): def del_dname(request, instances):
""" View used to delete a DName object """ """View used to delete DNAME records."""
dname = DelDNameForm(request.POST or None, instances=instances) dname = DelDNameForm(request.POST or None, instances=instances)
if dname.is_valid(): if dname.is_valid():
dname_dels = dname.cleaned_data["dname"] dname_dels = dname.cleaned_data["dname"]
@ -881,7 +888,7 @@ def del_dname(request, instances):
@login_required @login_required
@can_create(Txt) @can_create(Txt)
def add_txt(request): def add_txt(request):
""" View used to add a TXT object """ """View used to create TXT records."""
txt = TxtForm(request.POST or None) txt = TxtForm(request.POST or None)
if txt.is_valid(): if txt.is_valid():
txt.save() txt.save()
@ -897,7 +904,7 @@ def add_txt(request):
@login_required @login_required
@can_edit(Txt) @can_edit(Txt)
def edit_txt(request, txt_instance, **_kwargs): def edit_txt(request, txt_instance, **_kwargs):
""" View used to edit a TXT object """ """View used to edit TXT records."""
txt = TxtForm(request.POST or None, instance=txt_instance) txt = TxtForm(request.POST or None, instance=txt_instance)
if txt.is_valid(): if txt.is_valid():
if txt.changed_data: if txt.changed_data:
@ -912,7 +919,7 @@ def edit_txt(request, txt_instance, **_kwargs):
@login_required @login_required
@can_delete_set(Txt) @can_delete_set(Txt)
def del_txt(request, instances): def del_txt(request, instances):
""" View used to delete a TXT object """ """View used to delete TXT records."""
txt = DelTxtForm(request.POST or None, instances=instances) txt = DelTxtForm(request.POST or None, instances=instances)
if txt.is_valid(): if txt.is_valid():
txt_dels = txt.cleaned_data["txt"] txt_dels = txt.cleaned_data["txt"]
@ -933,7 +940,7 @@ def del_txt(request, instances):
@login_required @login_required
@can_create(Srv) @can_create(Srv)
def add_srv(request): def add_srv(request):
""" View used to add a SRV object """ """View used to create SRV records."""
srv = SrvForm(request.POST or None) srv = SrvForm(request.POST or None)
if srv.is_valid(): if srv.is_valid():
srv.save() srv.save()
@ -949,7 +956,7 @@ def add_srv(request):
@login_required @login_required
@can_edit(Srv) @can_edit(Srv)
def edit_srv(request, srv_instance, **_kwargs): def edit_srv(request, srv_instance, **_kwargs):
""" View used to edit a SRV object """ """View used to edit SRV records."""
srv = SrvForm(request.POST or None, instance=srv_instance) srv = SrvForm(request.POST or None, instance=srv_instance)
if srv.is_valid(): if srv.is_valid():
if srv.changed_data: if srv.changed_data:
@ -964,7 +971,7 @@ def edit_srv(request, srv_instance, **_kwargs):
@login_required @login_required
@can_delete_set(Srv) @can_delete_set(Srv)
def del_srv(request, instances): def del_srv(request, instances):
""" View used to delete a SRV object """ """View used to delete SRV records."""
srv = DelSrvForm(request.POST or None, instances=instances) srv = DelSrvForm(request.POST or None, instances=instances)
if srv.is_valid(): if srv.is_valid():
srv_dels = srv.cleaned_data["srv"] srv_dels = srv.cleaned_data["srv"]
@ -986,7 +993,7 @@ def del_srv(request, instances):
@can_create(Domain) @can_create(Domain)
@can_edit(Interface) @can_edit(Interface)
def add_alias(request, interface, interfaceid): def add_alias(request, interface, interfaceid):
""" View used to add an Alias object """ """View used to create aliases."""
alias = AliasForm(request.POST or None, user=request.user) alias = AliasForm(request.POST or None, user=request.user)
if alias.is_valid(): if alias.is_valid():
alias = alias.save(commit=False) alias = alias.save(commit=False)
@ -1006,7 +1013,7 @@ def add_alias(request, interface, interfaceid):
@login_required @login_required
@can_edit(Domain) @can_edit(Domain)
def edit_alias(request, domain_instance, **_kwargs): def edit_alias(request, domain_instance, **_kwargs):
""" View used to edit an Alias object """ """View used to edit aliases records."""
alias = AliasForm(request.POST or None, instance=domain_instance, user=request.user) alias = AliasForm(request.POST or None, instance=domain_instance, user=request.user)
if alias.is_valid(): if alias.is_valid():
if alias.changed_data: if alias.changed_data:
@ -1026,7 +1033,7 @@ def edit_alias(request, domain_instance, **_kwargs):
@login_required @login_required
@can_edit(Interface) @can_edit(Interface)
def del_alias(request, interface, interfaceid): def del_alias(request, interface, interfaceid):
""" View used to delete an Alias object """ """View used to delete aliases records."""
alias = DelAliasForm(request.POST or None, interface=interface) alias = DelAliasForm(request.POST or None, interface=interface)
if alias.is_valid(): if alias.is_valid():
alias_dels = alias.cleaned_data["alias"] alias_dels = alias.cleaned_data["alias"]
@ -1051,7 +1058,7 @@ def del_alias(request, interface, interfaceid):
@login_required @login_required
@can_create(Role) @can_create(Role)
def add_role(request): def add_role(request):
""" View used to add a Role object """ """View used to create roles."""
role = RoleForm(request.POST or None) role = RoleForm(request.POST or None)
if role.is_valid(): if role.is_valid():
role.save() role.save()
@ -1067,7 +1074,7 @@ def add_role(request):
@login_required @login_required
@can_edit(Role) @can_edit(Role)
def edit_role(request, role_instance, **_kwargs): def edit_role(request, role_instance, **_kwargs):
""" View used to edit a Role object """ """View used to edit roles."""
role = RoleForm(request.POST or None, instance=role_instance) role = RoleForm(request.POST or None, instance=role_instance)
if role.is_valid(): if role.is_valid():
if role.changed_data: if role.changed_data:
@ -1082,7 +1089,7 @@ def edit_role(request, role_instance, **_kwargs):
@login_required @login_required
@can_delete_set(Role) @can_delete_set(Role)
def del_role(request, instances): def del_role(request, instances):
""" View used to delete a Service object """ """View used to delete roles."""
role = DelRoleForm(request.POST or None, instances=instances) role = DelRoleForm(request.POST or None, instances=instances)
if role.is_valid(): if role.is_valid():
role_dels = role.cleaned_data["role"] role_dels = role.cleaned_data["role"]
@ -1103,7 +1110,7 @@ def del_role(request, instances):
@login_required @login_required
@can_create(Service) @can_create(Service)
def add_service(request): def add_service(request):
""" View used to add a Service object """ """View used to create services."""
service = ServiceForm(request.POST or None) service = ServiceForm(request.POST or None)
if service.is_valid(): if service.is_valid():
service.save() service.save()
@ -1119,7 +1126,7 @@ def add_service(request):
@login_required @login_required
@can_edit(Service) @can_edit(Service)
def edit_service(request, service_instance, **_kwargs): def edit_service(request, service_instance, **_kwargs):
""" View used to edit a Service object """ """View used to edit services."""
service = ServiceForm(request.POST or None, instance=service_instance) service = ServiceForm(request.POST or None, instance=service_instance)
if service.is_valid(): if service.is_valid():
if service.changed_data: if service.changed_data:
@ -1136,7 +1143,7 @@ def edit_service(request, service_instance, **_kwargs):
@login_required @login_required
@can_delete_set(Service) @can_delete_set(Service)
def del_service(request, instances): def del_service(request, instances):
""" View used to delete a Service object """ """View used to delete services."""
service = DelServiceForm(request.POST or None, instances=instances) service = DelServiceForm(request.POST or None, instances=instances)
if service.is_valid(): if service.is_valid():
service_dels = service.cleaned_data["service"] service_dels = service.cleaned_data["service"]
@ -1169,7 +1176,7 @@ def regen_service(request, service, **_kwargs):
@login_required @login_required
@can_create(Vlan) @can_create(Vlan)
def add_vlan(request): def add_vlan(request):
""" View used to add a VLAN object """ """View used to create VLANs."""
vlan = VlanForm(request.POST or None) vlan = VlanForm(request.POST or None)
if vlan.is_valid(): if vlan.is_valid():
vlan.save() vlan.save()
@ -1185,7 +1192,7 @@ def add_vlan(request):
@login_required @login_required
@can_edit(Vlan) @can_edit(Vlan)
def edit_vlan(request, vlan_instance, **_kwargs): def edit_vlan(request, vlan_instance, **_kwargs):
""" View used to edit a VLAN object """ """View used to edit VLANs."""
vlan = VlanForm(request.POST or None, instance=vlan_instance) vlan = VlanForm(request.POST or None, instance=vlan_instance)
if vlan.is_valid(): if vlan.is_valid():
if vlan.changed_data: if vlan.changed_data:
@ -1200,7 +1207,7 @@ def edit_vlan(request, vlan_instance, **_kwargs):
@login_required @login_required
@can_delete_set(Vlan) @can_delete_set(Vlan)
def del_vlan(request, instances): def del_vlan(request, instances):
""" View used to delete a VLAN object """ """View used to delete VLANs."""
vlan = DelVlanForm(request.POST or None, instances=instances) vlan = DelVlanForm(request.POST or None, instances=instances)
if vlan.is_valid(): if vlan.is_valid():
vlan_dels = vlan.cleaned_data["vlan"] vlan_dels = vlan.cleaned_data["vlan"]
@ -1221,7 +1228,7 @@ def del_vlan(request, instances):
@login_required @login_required
@can_create(Nas) @can_create(Nas)
def add_nas(request): def add_nas(request):
""" View used to add a NAS object """ """View used to create NAS devices."""
nas = NasForm(request.POST or None) nas = NasForm(request.POST or None)
if nas.is_valid(): if nas.is_valid():
nas.save() nas.save()
@ -1237,7 +1244,7 @@ def add_nas(request):
@login_required @login_required
@can_edit(Nas) @can_edit(Nas)
def edit_nas(request, nas_instance, **_kwargs): def edit_nas(request, nas_instance, **_kwargs):
""" View used to edit a NAS object """ """View used to edit NAS devices."""
nas = NasForm(request.POST or None, instance=nas_instance) nas = NasForm(request.POST or None, instance=nas_instance)
if nas.is_valid(): if nas.is_valid():
if nas.changed_data: if nas.changed_data:
@ -1252,7 +1259,7 @@ def edit_nas(request, nas_instance, **_kwargs):
@login_required @login_required
@can_delete_set(Nas) @can_delete_set(Nas)
def del_nas(request, instances): def del_nas(request, instances):
""" View used to delete a NAS object """ """View used to delete NAS devices."""
nas = DelNasForm(request.POST or None, instances=instances) nas = DelNasForm(request.POST or None, instances=instances)
if nas.is_valid(): if nas.is_valid():
nas_dels = nas.cleaned_data["nas"] nas_dels = nas.cleaned_data["nas"]
@ -1273,8 +1280,8 @@ def del_nas(request, instances):
@login_required @login_required
@can_view_all(Machine) @can_view_all(Machine)
def index(request): def index(request):
""" The home view for this app. Displays the list of registered """The home view for this app. Displays the list of registered
machines in Re2o """ machines in Re2o."""
pagination_large_number = GeneralOption.get_cached_value("pagination_large_number") pagination_large_number = GeneralOption.get_cached_value("pagination_large_number")
machines_list = ( machines_list = (
Machine.objects.select_related("user") Machine.objects.select_related("user")
@ -1297,7 +1304,7 @@ def index(request):
@login_required @login_required
@can_view_all(IpType) @can_view_all(IpType)
def index_iptype(request): def index_iptype(request):
""" View displaying the list of existing types of IP """ """View used to display the list of existing types of IP."""
iptype_list = ( iptype_list = (
IpType.objects.select_related("extension") IpType.objects.select_related("extension")
.select_related("vlan") .select_related("vlan")
@ -1309,7 +1316,7 @@ def index_iptype(request):
@login_required @login_required
@can_view_all(Vlan) @can_view_all(Vlan)
def index_vlan(request): def index_vlan(request):
""" View displaying the list of existing VLANs """ """View used to display the list of existing VLANs."""
vlan_list = Vlan.objects.prefetch_related("iptype_set").order_by("vlan_id") vlan_list = Vlan.objects.prefetch_related("iptype_set").order_by("vlan_id")
return render(request, "machines/index_vlan.html", {"vlan_list": vlan_list}) return render(request, "machines/index_vlan.html", {"vlan_list": vlan_list})
@ -1317,7 +1324,7 @@ def index_vlan(request):
@login_required @login_required
@can_view_all(MachineType) @can_view_all(MachineType)
def index_machinetype(request): def index_machinetype(request):
""" View displaying the list of existing types of machines """ """View used to display the list of existing types of machines."""
machinetype_list = MachineType.objects.select_related("ip_type").order_by("name") machinetype_list = MachineType.objects.select_related("ip_type").order_by("name")
return render( return render(
request, request,
@ -1329,7 +1336,7 @@ def index_machinetype(request):
@login_required @login_required
@can_view_all(Nas) @can_view_all(Nas)
def index_nas(request): def index_nas(request):
""" View displaying the list of existing NAS """ """View used to display the list of existing NAS devices."""
nas_list = ( nas_list = (
Nas.objects.select_related("machine_type") Nas.objects.select_related("machine_type")
.select_related("nas_type") .select_related("nas_type")
@ -1341,10 +1348,11 @@ def index_nas(request):
@login_required @login_required
@can_view_all(SOA, Mx, Ns, Txt, DName, Srv, Extension) @can_view_all(SOA, Mx, Ns, Txt, DName, Srv, Extension)
def index_extension(request): def index_extension(request):
""" View displaying the list of existing extensions, the list of """View used to display the list of existing extensions, the list of
existing SOA records, the list of existing MX records , the list of existing SOA records, the list of existing MX records , the list of
existing NS records, the list of existing TXT records and the list of existing NS records, the list of existing TXT records and the list of
existing SRV records """ existing SRV records.
"""
extension_list = ( extension_list = (
Extension.objects.select_related("origin") Extension.objects.select_related("origin")
.select_related("soa") .select_related("soa")
@ -1386,7 +1394,7 @@ def index_extension(request):
@login_required @login_required
@can_edit(Interface) @can_edit(Interface)
def index_alias(request, interface, interfaceid): def index_alias(request, interface, interfaceid):
""" View used to display the list of existing alias of an interface """ """View used to display the list of existing aliases of an interface."""
alias_list = Domain.objects.filter( alias_list = Domain.objects.filter(
cname=Domain.objects.filter(interface_parent=interface) cname=Domain.objects.filter(interface_parent=interface)
).order_by("name") ).order_by("name")
@ -1401,7 +1409,7 @@ def index_alias(request, interface, interfaceid):
@can_view(Machine) @can_view(Machine)
def index_sshfp(request, machine, machineid): def index_sshfp(request, machine, machineid):
"""View used to display the list of existing SSHFP records associated """View used to display the list of existing SSHFP records associated
with a machine""" with a machine."""
sshfp_list = SshFp.objects.filter(machine=machine) sshfp_list = SshFp.objects.filter(machine=machine)
return render( return render(
request, request,
@ -1413,7 +1421,7 @@ def index_sshfp(request, machine, machineid):
@login_required @login_required
@can_view(Interface) @can_view(Interface)
def index_ipv6(request, interface, interfaceid): def index_ipv6(request, interface, interfaceid):
""" View used to display the list of existing IPv6 of an interface """ """View used to display the list of existing IPv6 of an interface."""
ipv6_list = Ipv6List.objects.filter(interface=interface) ipv6_list = Ipv6List.objects.filter(interface=interface)
return render( return render(
request, request,
@ -1425,7 +1433,7 @@ def index_ipv6(request, interface, interfaceid):
@login_required @login_required
@can_view_all(Role) @can_view_all(Role)
def index_role(request): def index_role(request):
""" View used to display the list of existing roles """ """View used to display the list of existing roles."""
role_list = Role.objects.prefetch_related("servers__domain__extension").all() role_list = Role.objects.prefetch_related("servers__domain__extension").all()
return render(request, "machines/index_role.html", {"role_list": role_list}) return render(request, "machines/index_role.html", {"role_list": role_list})
@ -1433,7 +1441,7 @@ def index_role(request):
@login_required @login_required
@can_view_all(Service) @can_view_all(Service)
def index_service(request): def index_service(request):
""" View used to display the list of existing services """ """View used to display the list of existing services."""
service_list = Service.objects.prefetch_related( service_list = Service.objects.prefetch_related(
"service_link_set__server__domain__extension" "service_link_set__server__domain__extension"
).all() ).all()
@ -1452,7 +1460,7 @@ def index_service(request):
@login_required @login_required
@can_view_all(OuverturePortList) @can_view_all(OuverturePortList)
def index_portlist(request): def index_portlist(request):
""" View used to display the list of existing port policies """ """View used to display the list of existing port policies."""
port_list = ( port_list = (
OuverturePortList.objects.prefetch_related("ouvertureport_set") OuverturePortList.objects.prefetch_related("ouvertureport_set")
.prefetch_related("interface_set__domain__extension") .prefetch_related("interface_set__domain__extension")
@ -1465,7 +1473,7 @@ def index_portlist(request):
@login_required @login_required
@can_edit(OuverturePortList) @can_edit(OuverturePortList)
def edit_portlist(request, ouvertureportlist_instance, **_kwargs): def edit_portlist(request, ouvertureportlist_instance, **_kwargs):
""" View used to edit a port policy """ """View used to edit port policies."""
port_list = EditOuverturePortListForm( port_list = EditOuverturePortListForm(
request.POST or None, instance=ouvertureportlist_instance request.POST or None, instance=ouvertureportlist_instance
) )
@ -1500,7 +1508,7 @@ def edit_portlist(request, ouvertureportlist_instance, **_kwargs):
@login_required @login_required
@can_delete(OuverturePortList) @can_delete(OuverturePortList)
def del_portlist(request, port_list_instance, **_kwargs): def del_portlist(request, port_list_instance, **_kwargs):
""" View used to delete a port policy """ """View used to delete port policies."""
port_list_instance.delete() port_list_instance.delete()
messages.success(request, _("The ports list was deleted.")) messages.success(request, _("The ports list was deleted."))
return redirect(reverse("machines:index-portlist")) return redirect(reverse("machines:index-portlist"))
@ -1509,7 +1517,7 @@ def del_portlist(request, port_list_instance, **_kwargs):
@login_required @login_required
@can_create(OuverturePortList) @can_create(OuverturePortList)
def add_portlist(request): def add_portlist(request):
""" View used to add a port policy """ """View used to create port policies."""
port_list = EditOuverturePortListForm(request.POST or None) port_list = EditOuverturePortListForm(request.POST or None)
port_formset = modelformset_factory( port_formset = modelformset_factory(
OuverturePort, OuverturePort,
@ -1540,8 +1548,9 @@ def add_portlist(request):
@can_create(OuverturePort) @can_create(OuverturePort)
@can_edit(Interface) @can_edit(Interface)
def configure_ports(request, interface_instance, **_kwargs): def configure_ports(request, interface_instance, **_kwargs):
""" View to display the list of configured port policy for an """View to display the list of configured port policies for an
interface """ interface.
"""
if not interface_instance.may_have_port_open(): if not interface_instance.may_have_port_open():
messages.error( messages.error(
request, request,