8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-12-23 07:23:46 +00:00

Implementation des mixins pour revisions par l'app Machine

This commit is contained in:
Charlie Jacomme 2017-10-30 20:02:31 +01:00 committed by root
parent 7c5f81f034
commit 9028760366
3 changed files with 91 additions and 205 deletions

View file

@ -56,8 +56,9 @@ from .models import (
OuverturePortList,
)
from re2o.mixins import FormRevMixin
class EditMachineForm(ModelForm):
class EditMachineForm(FormRevMixin, ModelForm):
"""Formulaire d'édition d'une machine"""
class Meta:
model = Machine
@ -82,7 +83,7 @@ class BaseEditMachineForm(EditMachineForm):
fields = ['name', 'active']
class EditInterfaceForm(ModelForm):
class EditInterfaceForm(FormRevMixin, ModelForm):
"""Edition d'une interface. Edition complète"""
class Meta:
model = Interface
@ -168,7 +169,7 @@ class BaseEditInterfaceForm(EditInterfaceForm):
)
class AliasForm(ModelForm):
class AliasForm(FormRevMixin, ModelForm):
"""Ajout d'un alias (et edition), CNAME, contenant nom et extension"""
class Meta:
model = Domain
@ -184,7 +185,7 @@ class AliasForm(ModelForm):
)
class DomainForm(ModelForm):
class DomainForm(FormRevMixin, ModelForm):
"""Ajout et edition d'un enregistrement de nom, relié à interface"""
class Meta:
model = Domain
@ -200,7 +201,7 @@ class DomainForm(ModelForm):
super(DomainForm, self).__init__(*args, prefix=prefix, **kwargs)
class DelAliasForm(Form):
class DelAliasForm(FormRevMixin, Form):
"""Suppression d'un ou plusieurs objets alias"""
alias = forms.ModelMultipleChoiceField(
queryset=Domain.objects.all(),
@ -216,7 +217,7 @@ class DelAliasForm(Form):
)
class MachineTypeForm(ModelForm):
class MachineTypeForm(FormRevMixin, ModelForm):
"""Ajout et edition d'un machinetype, relié à un iptype"""
class Meta:
model = MachineType
@ -229,7 +230,7 @@ class MachineTypeForm(ModelForm):
self.fields['ip_type'].label = "Type d'ip relié"
class DelMachineTypeForm(Form):
class DelMachineTypeForm(FormRevMixin, Form):
"""Suppression d'un ou plusieurs machinetype"""
machinetypes = forms.ModelMultipleChoiceField(
queryset=MachineType.objects.all(),
@ -238,7 +239,7 @@ class DelMachineTypeForm(Form):
)
class IpTypeForm(ModelForm):
class IpTypeForm(FormRevMixin, ModelForm):
"""Formulaire d'ajout d'un iptype. Pas d'edition de l'ip de start et de
stop après creation"""
class Meta:
@ -260,7 +261,7 @@ class EditIpTypeForm(IpTypeForm):
'ouverture_ports']
class DelIpTypeForm(Form):
class DelIpTypeForm(FormRevMixin, Form):
"""Suppression d'un ou plusieurs iptype"""
iptypes = forms.ModelMultipleChoiceField(
queryset=IpType.objects.all(),
@ -269,7 +270,7 @@ class DelIpTypeForm(Form):
)
class ExtensionForm(ModelForm):
class ExtensionForm(FormRevMixin, ModelForm):
"""Formulaire d'ajout et edition d'une extension"""
class Meta:
model = Extension
@ -284,7 +285,7 @@ class ExtensionForm(ModelForm):
self.fields['soa'].label = 'En-tête SOA à utiliser'
class DelExtensionForm(Form):
class DelExtensionForm(FormRevMixin, Form):
"""Suppression d'une ou plusieurs extensions"""
extensions = forms.ModelMultipleChoiceField(
queryset=Extension.objects.all(),
@ -293,7 +294,7 @@ class DelExtensionForm(Form):
)
class SOAForm(ModelForm):
class SOAForm(FormRevMixin, ModelForm):
"""Ajout et edition d'un SOA"""
class Meta:
model = SOA
@ -304,7 +305,7 @@ class SOAForm(ModelForm):
super(SOAForm, self).__init__(*args, prefix=prefix, **kwargs)
class DelSOAForm(Form):
class DelSOAForm(FormRevMixin, Form):
"""Suppression d'un ou plusieurs SOA"""
soa = forms.ModelMultipleChoiceField(
queryset=SOA.objects.all(),
@ -313,7 +314,7 @@ class DelSOAForm(Form):
)
class MxForm(ModelForm):
class MxForm(FormRevMixin, ModelForm):
"""Ajout et edition d'un MX"""
class Meta:
model = Mx
@ -327,7 +328,7 @@ class MxForm(ModelForm):
).select_related('extension')
class DelMxForm(Form):
class DelMxForm(FormRevMixin, Form):
"""Suppression d'un ou plusieurs MX"""
mx = forms.ModelMultipleChoiceField(
queryset=Mx.objects.all(),
@ -336,7 +337,7 @@ class DelMxForm(Form):
)
class NsForm(ModelForm):
class NsForm(FormRevMixin, ModelForm):
"""Ajout d'un NS pour une zone
On exclue les CNAME dans les objets domain (interdit par la rfc)
donc on prend uniquemet """
@ -352,7 +353,7 @@ class NsForm(ModelForm):
).select_related('extension')
class DelNsForm(Form):
class DelNsForm(FormRevMixin, Form):
"""Suppresion d'un ou plusieurs NS"""
ns = forms.ModelMultipleChoiceField(
queryset=Ns.objects.all(),
@ -361,7 +362,7 @@ class DelNsForm(Form):
)
class TxtForm(ModelForm):
class TxtForm(FormRevMixin, ModelForm):
"""Ajout d'un txt pour une zone"""
class Meta:
model = Text
@ -372,7 +373,7 @@ class TxtForm(ModelForm):
super(TxtForm, self).__init__(*args, prefix=prefix, **kwargs)
class DelTxtForm(Form):
class DelTxtForm(FormRevMixin, Form):
"""Suppression d'un ou plusieurs TXT"""
txt = forms.ModelMultipleChoiceField(
queryset=Text.objects.all(),
@ -381,7 +382,7 @@ class DelTxtForm(Form):
)
class NasForm(ModelForm):
class NasForm(FormRevMixin, ModelForm):
"""Ajout d'un type de nas (machine d'authentification,
swicths, bornes...)"""
class Meta:
@ -393,7 +394,7 @@ class NasForm(ModelForm):
super(NasForm, self).__init__(*args, prefix=prefix, **kwargs)
class DelNasForm(Form):
class DelNasForm(FormRevMixin, Form):
"""Suppression d'un ou plusieurs nas"""
nas = forms.ModelMultipleChoiceField(
queryset=Nas.objects.all(),
@ -402,7 +403,7 @@ class DelNasForm(Form):
)
class ServiceForm(ModelForm):
class ServiceForm(FormRevMixin, ModelForm):
"""Ajout et edition d'une classe de service : dns, dhcp, etc"""
class Meta:
model = Service
@ -422,7 +423,7 @@ class ServiceForm(ModelForm):
return instance
class DelServiceForm(Form):
class DelServiceForm(FormRevMixin, Form):
"""Suppression d'un ou plusieurs service"""
service = forms.ModelMultipleChoiceField(
queryset=Service.objects.all(),
@ -431,7 +432,7 @@ class DelServiceForm(Form):
)
class VlanForm(ModelForm):
class VlanForm(FormRevMixin, ModelForm):
"""Ajout d'un vlan : id, nom"""
class Meta:
model = Vlan
@ -442,7 +443,7 @@ class VlanForm(ModelForm):
super(VlanForm, self).__init__(*args, prefix=prefix, **kwargs)
class DelVlanForm(Form):
class DelVlanForm(FormRevMixin, Form):
"""Suppression d'un ou plusieurs vlans"""
vlan = forms.ModelMultipleChoiceField(
queryset=Vlan.objects.all(),
@ -451,7 +452,7 @@ class DelVlanForm(Form):
)
class EditOuverturePortConfigForm(ModelForm):
class EditOuverturePortConfigForm(FormRevMixin, ModelForm):
"""Edition de la liste des profils d'ouverture de ports
pour l'interface"""
class Meta:
@ -467,7 +468,7 @@ class EditOuverturePortConfigForm(ModelForm):
)
class EditOuverturePortListForm(ModelForm):
class EditOuverturePortListForm(FormRevMixin, ModelForm):
"""Edition de la liste des ports et profils d'ouverture
des ports"""
class Meta:

View file

@ -37,8 +37,9 @@ from django.core.validators import MaxValueValidator
from macaddress.fields import MACAddressField
from re2o.mixins import RevMixin
class Machine(models.Model):
class Machine(RevMixin, models.Model):
""" Class définissant une machine, object parent user, objets fils
interfaces"""
PRETTY_NAME = "Machine"
@ -56,7 +57,7 @@ class Machine(models.Model):
return str(self.user) + ' - ' + str(self.id) + ' - ' + str(self.name)
class MachineType(models.Model):
class MachineType(RevMixin, models.Model):
""" Type de machine, relié à un type d'ip, affecté aux interfaces"""
PRETTY_NAME = "Type de machine"
@ -77,7 +78,7 @@ class MachineType(models.Model):
return self.type
class IpType(models.Model):
class IpType(RevMixin, models.Model):
""" Type d'ip, définissant un range d'ip, affecté aux machine types"""
PRETTY_NAME = "Type d'ip"
@ -187,7 +188,7 @@ class IpType(models.Model):
return self.type
class Vlan(models.Model):
class Vlan(RevMixin, models.Model):
""" Un vlan : vlan_id et nom
On limite le vlan id entre 0 et 4096, comme défini par la norme"""
PRETTY_NAME = "Vlans"
@ -200,7 +201,7 @@ class Vlan(models.Model):
return self.name
class Nas(models.Model):
class Nas(RevMixin, models.Model):
""" Les nas. Associé à un machine_type.
Permet aussi de régler le port_access_mode (802.1X ou mac-address) pour
le radius. Champ autocapture de la mac à true ou false"""
@ -234,7 +235,7 @@ class Nas(models.Model):
return self.name
class SOA(models.Model):
class SOA(RevMixin, models.Model):
"""
Un enregistrement SOA associé à une extension
Les valeurs par défault viennent des recommandations RIPE :
@ -306,7 +307,7 @@ class SOA(models.Model):
class Extension(models.Model):
class Extension(RevMixin, models.Model):
""" Extension dns type example.org. Précise si tout le monde peut
l'utiliser, associé à un origin (ip d'origine)"""
PRETTY_NAME = "Extensions dns"
@ -346,7 +347,7 @@ class Extension(models.Model):
return self.name
class Mx(models.Model):
class Mx(RevMixin, models.Model):
""" Entrées des MX. Enregistre la zone (extension) associée et la
priorité
Todo : pouvoir associer un MX à une interface """
@ -366,7 +367,7 @@ class Mx(models.Model):
return str(self.zone) + ' ' + str(self.priority) + ' ' + str(self.name)
class Ns(models.Model):
class Ns(RevMixin, models.Model):
"""Liste des enregistrements name servers par zone considéérée"""
PRETTY_NAME = "Enregistrements NS"
@ -382,7 +383,7 @@ class Ns(models.Model):
return str(self.zone) + ' ' + str(self.ns)
class Text(models.Model):
class Text(RevMixin, models.Model):
""" Un enregistrement TXT associé à une extension"""
PRETTY_NAME = "Enregistrement TXT"
@ -400,7 +401,7 @@ class Text(models.Model):
return str(self.field1).ljust(15) + " IN TXT " + str(self.field2)
class Interface(models.Model):
class Interface(RevMixin, models.Model):
""" Une interface. Objet clef de l'application machine :
- une address mac unique. Possibilité de la rendre unique avec le
typemachine
@ -524,7 +525,7 @@ class Interface(models.Model):
return self.ipv4 and not self.has_private_ip()
class Domain(models.Model):
class Domain(RevMixin, models.Model):
""" Objet domain. Enregistrement A et CNAME en même temps : permet de
stocker les alias et les nom de machines, suivant si interface_parent
ou cname sont remplis"""
@ -606,7 +607,7 @@ class Domain(models.Model):
return str(self.name) + str(self.extension)
class IpList(models.Model):
class IpList(RevMixin, models.Model):
PRETTY_NAME = "Addresses ipv4"
ipv4 = models.GenericIPAddressField(protocol='IPv4', unique=True)
@ -633,7 +634,7 @@ class IpList(models.Model):
return self.ipv4
class Service(models.Model):
class Service(RevMixin, models.Model):
""" Definition d'un service (dhcp, dns, etc)"""
PRETTY_NAME = "Services à générer (dhcp, dns, etc)"
@ -682,7 +683,7 @@ def regen(service):
return
class Service_link(models.Model):
class Service_link(RevMixin, models.Model):
""" Definition du lien entre serveurs et services"""
PRETTY_NAME = "Relation entre service et serveur"
@ -713,7 +714,7 @@ class Service_link(models.Model):
return str(self.server) + " " + str(self.service)
class OuverturePortList(models.Model):
class OuverturePortList(RevMixin, models.Model):
"""Liste des ports ouverts sur une interface."""
PRETTY_NAME = "Profil d'ouverture de ports"
@ -754,7 +755,7 @@ class OuverturePortList(models.Model):
)
class OuverturePort(models.Model):
class OuverturePort(RevMixin, models.Model):
"""
Représente un simple port ou une plage de ports.

View file

@ -235,20 +235,11 @@ def new_machine(request, userid):
domain.instance.interface_parent = new_interface
if domain.is_valid():
new_domain = domain.save(commit=False)
with transaction.atomic(), reversion.create_revision():
new_machine.save()
reversion.set_user(request.user)
reversion.set_comment("Création")
new_machine.save()
new_interface.machine = new_machine
with transaction.atomic(), reversion.create_revision():
new_interface.save()
reversion.set_user(request.user)
reversion.set_comment("Création")
new_interface.save()
new_domain.interface_parent = new_interface
with transaction.atomic(), reversion.create_revision():
new_domain.save()
reversion.set_user(request.user)
reversion.set_comment("Création")
new_domain.save()
messages.success(request, "La machine a été créée")
return redirect("/users/profil/" + str(user.id))
i_mbf_param = generate_ipv4_mbf_param( interface, False )
@ -277,18 +268,9 @@ def edit_interface(request, interfaceid):
new_machine = machine_form.save(commit=False)
new_interface = interface_form.save(commit=False)
new_domain = domain_form.save(commit=False)
with transaction.atomic(), reversion.create_revision():
new_machine.save()
reversion.set_user(request.user)
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in machine_form.changed_data))
with transaction.atomic(), reversion.create_revision():
new_interface.save()
reversion.set_user(request.user)
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in interface_form.changed_data))
with transaction.atomic(), reversion.create_revision():
new_domain.save()
reversion.set_user(request.user)
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in domain_form.changed_data))
new_machine.save()
new_interface.save()
new_domain.save()
messages.success(request, "La machine a été modifiée")
return redirect("/users/profil/" + str(interface.machine.user.id))
i_mbf_param = generate_ipv4_mbf_param( interface_form, False )
@ -307,9 +289,7 @@ def del_machine(request, machineid):
messages.error(request, "Vous ne pouvez pas éditer une machine d'un autre user que vous sans droit")
return redirect("/users/profil/" + str(machine.user.id))
if request.method == "POST":
with transaction.atomic(), reversion.create_revision():
machine.delete()
reversion.set_user(request.user)
machine.delete()
messages.success(request, "La machine a été détruite")
return redirect("/users/profil/" + str(machine.user.id))
return form({'objet': machine, 'objet_name': 'machine'}, 'machines/delete.html', request)
@ -339,15 +319,9 @@ def new_interface(request, machineid):
new_interface.machine = machine
if domain_form.is_valid():
new_domain = domain_form.save(commit=False)
with transaction.atomic(), reversion.create_revision():
new_interface.save()
reversion.set_user(request.user)
reversion.set_comment("Création")
new_interface.save()
new_domain.interface_parent = new_interface
with transaction.atomic(), reversion.create_revision():
new_domain.save()
reversion.set_user(request.user)
reversion.set_comment("Création")
new_domain.save()
messages.success(request, "L'interface a été ajoutée")
return redirect("/users/profil/" + str(machine.user.id))
i_mbf_param = generate_ipv4_mbf_param( interface_form, False )
@ -367,11 +341,9 @@ def del_interface(request, interfaceid):
return redirect("/users/profil/" + str(request.user.id))
if request.method == "POST":
machine = interface.machine
with transaction.atomic(), reversion.create_revision():
interface.delete()
if not machine.interface_set.all():
machine.delete()
reversion.set_user(request.user)
interface.delete()
if not machine.interface_set.all():
machine.delete()
messages.success(request, "L'interface a été détruite")
return redirect("/users/profil/" + str(request.user.id))
return form({'objet': interface, 'objet_name': 'interface'}, 'machines/delete.html', request)
@ -382,10 +354,7 @@ def add_iptype(request):
""" Ajoute un range d'ip. Intelligence dans le models, fonction views minimaliste"""
iptype = IpTypeForm(request.POST or None)
if iptype.is_valid():
with transaction.atomic(), reversion.create_revision():
iptype.save()
reversion.set_user(request.user)
reversion.set_comment("Création")
iptype.save()
messages.success(request, "Ce type d'ip a été ajouté")
return redirect("/machines/index_iptype")
return form({'iptypeform': iptype}, 'machines/machine.html', request)
@ -401,10 +370,7 @@ def edit_iptype(request, iptypeid):
return redirect("/machines/index_iptype/")
iptype = EditIpTypeForm(request.POST or None, instance=iptype_instance)
if iptype.is_valid():
with transaction.atomic(), reversion.create_revision():
iptype.save()
reversion.set_user(request.user)
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in iptype.changed_data))
iptype.save()
messages.success(request, "Type d'ip modifié")
return redirect("/machines/index_iptype/")
return form({'iptypeform': iptype}, 'machines/machine.html', request)
@ -418,9 +384,7 @@ def del_iptype(request):
iptype_dels = iptype.cleaned_data['iptypes']
for iptype_del in iptype_dels:
try:
with transaction.atomic(), reversion.create_revision():
iptype_del.delete()
reversion.set_user(request.user)
iptype_del.delete()
messages.success(request, "Le type d'ip a été supprimé")
except ProtectedError:
messages.error(request, "Le type d'ip %s est affectée à au moins une machine, vous ne pouvez pas le supprimer" % iptype_del)
@ -432,10 +396,7 @@ def del_iptype(request):
def add_machinetype(request):
machinetype = MachineTypeForm(request.POST or None)
if machinetype.is_valid():
with transaction.atomic(), reversion.create_revision():
machinetype.save()
reversion.set_user(request.user)
reversion.set_comment("Création")
machinetype.save()
messages.success(request, "Ce type de machine a été ajouté")
return redirect("/machines/index_machinetype")
return form({'machinetypeform': machinetype}, 'machines/machine.html', request)
@ -450,10 +411,7 @@ def edit_machinetype(request, machinetypeid):
return redirect("/machines/index_machinetype/")
machinetype = MachineTypeForm(request.POST or None, instance=machinetype_instance)
if machinetype.is_valid():
with transaction.atomic(), reversion.create_revision():
machinetype.save()
reversion.set_user(request.user)
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in machinetype.changed_data))
machinetype.save()
messages.success(request, "Type de machine modifié")
return redirect("/machines/index_machinetype/")
return form({'machinetypeform': machinetype}, 'machines/machine.html', request)
@ -466,9 +424,7 @@ def del_machinetype(request):
machinetype_dels = machinetype.cleaned_data['machinetypes']
for machinetype_del in machinetype_dels:
try:
with transaction.atomic(), reversion.create_revision():
machinetype_del.delete()
reversion.set_user(request.user)
machinetype_del.delete()
messages.success(request, "Le type de machine a été supprimé")
except ProtectedError:
messages.error(request, "Le type de machine %s est affectée à au moins une machine, vous ne pouvez pas le supprimer" % machinetype_del)
@ -480,10 +436,7 @@ def del_machinetype(request):
def add_extension(request):
extension = ExtensionForm(request.POST or None)
if extension.is_valid():
with transaction.atomic(), reversion.create_revision():
extension.save()
reversion.set_user(request.user)
reversion.set_comment("Création")
extension.save()
messages.success(request, "Cette extension a été ajoutée")
return redirect("/machines/index_extension")
return form({'extensionform': extension}, 'machines/machine.html', request)
@ -498,10 +451,7 @@ def edit_extension(request, extensionid):
return redirect("/machines/index_extension/")
extension = ExtensionForm(request.POST or None, instance=extension_instance)
if extension.is_valid():
with transaction.atomic(), reversion.create_revision():
extension.save()
reversion.set_user(request.user)
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in extension.changed_data))
extension.save()
messages.success(request, "Extension modifiée")
return redirect("/machines/index_extension/")
return form({'extensionform': extension}, 'machines/machine.html', request)
@ -514,9 +464,7 @@ def del_extension(request):
extension_dels = extension.cleaned_data['extensions']
for extension_del in extension_dels:
try:
with transaction.atomic(), reversion.create_revision():
extension_del.delete()
reversion.set_user(request.user)
extension_del.delete()
messages.success(request, "L'extension a été supprimée")
except ProtectedError:
messages.error(request, "L'extension %s est affectée à au moins un type de machine, vous ne pouvez pas la supprimer" % extension_del)
@ -528,10 +476,7 @@ def del_extension(request):
def add_soa(request):
soa = SOAForm(request.POST or None)
if soa.is_valid():
with transaction.atomic(), reversion.create_revision():
soa.save()
reversion.set_user(request.user)
reversion.set_comment("Création")
soa.save()
messages.success(request, "Cet enregistrement SOA a été ajouté")
return redirect("/machines/index_extension")
return form({'soaform': soa}, 'machines/machine.html', request)
@ -546,10 +491,7 @@ def edit_soa(request, soaid):
return redirect("/machines/index_extension/")
soa = SOAForm(request.POST or None, instance=soa_instance)
if soa.is_valid():
with transaction.atomic(), reversion.create_revision():
soa.save()
reversion.set_user(request.user)
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in soa.changed_data))
soa.save()
messages.success(request, "SOA modifié")
return redirect("/machines/index_extension/")
return form({'soaform': soa}, 'machines/machine.html', request)
@ -562,9 +504,7 @@ def del_soa(request):
soa_dels = soa.cleaned_data['soa']
for soa_del in soa_dels:
try:
with transaction.atomic(), reversion.create_revision():
soa_del.delete()
reversion.set_user(request.user)
soa_del.delete()
messages.success(request, "Le SOA a été supprimée")
except ProtectedError:
messages.error(request, "Erreur le SOA suivant %s ne peut être supprimé" % soa_del)
@ -576,10 +516,7 @@ def del_soa(request):
def add_mx(request):
mx = MxForm(request.POST or None)
if mx.is_valid():
with transaction.atomic(), reversion.create_revision():
mx.save()
reversion.set_user(request.user)
reversion.set_comment("Création")
mx.save()
messages.success(request, "Cet enregistrement mx a été ajouté")
return redirect("/machines/index_extension")
return form({'mxform': mx}, 'machines/machine.html', request)
@ -594,10 +531,7 @@ def edit_mx(request, mxid):
return redirect("/machines/index_extension/")
mx = MxForm(request.POST or None, instance=mx_instance)
if mx.is_valid():
with transaction.atomic(), reversion.create_revision():
mx.save()
reversion.set_user(request.user)
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in mx.changed_data))
mx.save()
messages.success(request, "Mx modifié")
return redirect("/machines/index_extension/")
return form({'mxform': mx}, 'machines/machine.html', request)
@ -610,9 +544,7 @@ def del_mx(request):
mx_dels = mx.cleaned_data['mx']
for mx_del in mx_dels:
try:
with transaction.atomic(), reversion.create_revision():
mx_del.delete()
reversion.set_user(request.user)
mx_del.delete()
messages.success(request, "L'mx a été supprimée")
except ProtectedError:
messages.error(request, "Erreur le Mx suivant %s ne peut être supprimé" % mx_del)
@ -624,10 +556,7 @@ def del_mx(request):
def add_ns(request):
ns = NsForm(request.POST or None)
if ns.is_valid():
with transaction.atomic(), reversion.create_revision():
ns.save()
reversion.set_user(request.user)
reversion.set_comment("Création")
ns.save()
messages.success(request, "Cet enregistrement ns a été ajouté")
return redirect("/machines/index_extension")
return form({'nsform': ns}, 'machines/machine.html', request)
@ -642,10 +571,7 @@ def edit_ns(request, nsid):
return redirect("/machines/index_extension/")
ns = NsForm(request.POST or None, instance=ns_instance)
if ns.is_valid():
with transaction.atomic(), reversion.create_revision():
ns.save()
reversion.set_user(request.user)
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in ns.changed_data))
ns.save()
messages.success(request, "Ns modifié")
return redirect("/machines/index_extension/")
return form({'nsform': ns}, 'machines/machine.html', request)
@ -658,9 +584,7 @@ def del_ns(request):
ns_dels = ns.cleaned_data['ns']
for ns_del in ns_dels:
try:
with transaction.atomic(), reversion.create_revision():
ns_del.delete()
reversion.set_user(request.user)
ns_del.delete()
messages.success(request, "Le ns a été supprimée")
except ProtectedError:
messages.error(request, "Erreur le Ns suivant %s ne peut être supprimé" % ns_del)
@ -672,10 +596,7 @@ def del_ns(request):
def add_txt(request):
txt = TxtForm(request.POST or None)
if txt.is_valid():
with transaction.atomic(), reversion.create_revision():
txt.save()
reversion.set_user(request.user)
reversion.set_comment("Création")
txt.save()
messages.success(request, "Cet enregistrement text a été ajouté")
return redirect("/machines/index_extension")
return form({'txtform': txt}, 'machines/machine.html', request)
@ -690,10 +611,7 @@ def edit_txt(request, txtid):
return redirect("/machines/index_extension/")
txt = TxtForm(request.POST or None, instance=txt_instance)
if txt.is_valid():
with transaction.atomic(), reversion.create_revision():
txt.save()
reversion.set_user(request.user)
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in txt.changed_data))
txt.save()
messages.success(request, "Txt modifié")
return redirect("/machines/index_extension/")
return form({'txtform': txt}, 'machines/machine.html', request)
@ -706,9 +624,7 @@ def del_txt(request):
txt_dels = txt.cleaned_data['txt']
for txt_del in txt_dels:
try:
with transaction.atomic(), reversion.create_revision():
txt_del.delete()
reversion.set_user(request.user)
txt_del.delete()
messages.success(request, "Le txt a été supprimé")
except ProtectedError:
messages.error(request, "Erreur le Txt suivant %s ne peut être supprimé" % txt_del)
@ -735,10 +651,7 @@ def add_alias(request, interfaceid):
if alias.is_valid():
alias = alias.save(commit=False)
alias.cname = interface.domain
with transaction.atomic(), reversion.create_revision():
alias.save()
reversion.set_user(request.user)
reversion.set_comment("Création")
alias.save()
messages.success(request, "Cet alias a été ajouté")
return redirect("/machines/index_alias/" + str(interfaceid))
return form({'aliasform': alias}, 'machines/machine.html', request)
@ -755,10 +668,7 @@ def edit_alias(request, aliasid):
return redirect("/users/profil/" + str(request.user.id))
alias = AliasForm(request.POST or None, instance=alias_instance, infra=request.user.has_perms(('infra',)))
if alias.is_valid():
with transaction.atomic(), reversion.create_revision():
alias_instance = alias.save()
reversion.set_user(request.user)
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in alias.changed_data))
alias_instance = alias.save()
messages.success(request, "Alias modifié")
return redirect("/machines/index_alias/" + str(alias_instance.cname.interface_parent.id))
return form({'aliasform': alias}, 'machines/machine.html', request)
@ -778,9 +688,7 @@ def del_alias(request, interfaceid):
alias_dels = alias.cleaned_data['alias']
for alias_del in alias_dels:
try:
with transaction.atomic(), reversion.create_revision():
alias_del.delete()
reversion.set_user(request.user)
alias_del.delete()
messages.success(request, "L'alias %s a été supprimé" % alias_del)
except ProtectedError:
messages.error(request, "Erreur l'alias suivant %s ne peut être supprimé" % alias_del)
@ -793,10 +701,7 @@ def del_alias(request, interfaceid):
def add_service(request):
service = ServiceForm(request.POST or None)
if service.is_valid():
with transaction.atomic(), reversion.create_revision():
service.save()
reversion.set_user(request.user)
reversion.set_comment("Création")
service.save()
messages.success(request, "Cet enregistrement service a été ajouté")
return redirect("/machines/index_service")
return form({'serviceform': service}, 'machines/machine.html', request)
@ -811,10 +716,7 @@ def edit_service(request, serviceid):
return redirect("/machines/index_extension/")
service = ServiceForm(request.POST or None, instance=service_instance)
if service.is_valid():
with transaction.atomic(), reversion.create_revision():
service.save()
reversion.set_user(request.user)
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in service.changed_data))
service.save()
messages.success(request, "Service modifié")
return redirect("/machines/index_service/")
return form({'serviceform': service}, 'machines/machine.html', request)
@ -827,9 +729,7 @@ def del_service(request):
service_dels = service.cleaned_data['service']
for service_del in service_dels:
try:
with transaction.atomic(), reversion.create_revision():
service_del.delete()
reversion.set_user(request.user)
service_del.delete()
messages.success(request, "Le service a été supprimée")
except ProtectedError:
messages.error(request, "Erreur le service suivant %s ne peut être supprimé" % service_del)
@ -841,10 +741,7 @@ def del_service(request):
def add_vlan(request):
vlan = VlanForm(request.POST or None)
if vlan.is_valid():
with transaction.atomic(), reversion.create_revision():
vlan.save()
reversion.set_user(request.user)
reversion.set_comment("Création")
vlan.save()
messages.success(request, "Cet enregistrement vlan a été ajouté")
return redirect("/machines/index_vlan")
return form({'vlanform': vlan}, 'machines/machine.html', request)
@ -859,10 +756,7 @@ def edit_vlan(request, vlanid):
return redirect("/machines/index_vlan/")
vlan = VlanForm(request.POST or None, instance=vlan_instance)
if vlan.is_valid():
with transaction.atomic(), reversion.create_revision():
vlan.save()
reversion.set_user(request.user)
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in vlan.changed_data))
vlan.save()
messages.success(request, "Vlan modifié")
return redirect("/machines/index_vlan/")
return form({'vlanform': vlan}, 'machines/machine.html', request)
@ -875,9 +769,7 @@ def del_vlan(request):
vlan_dels = vlan.cleaned_data['vlan']
for vlan_del in vlan_dels:
try:
with transaction.atomic(), reversion.create_revision():
vlan_del.delete()
reversion.set_user(request.user)
vlan_del.delete()
messages.success(request, "Le vlan a été supprimée")
except ProtectedError:
messages.error(request, "Erreur le Vlan suivant %s ne peut être supprimé" % vlan_del)
@ -889,10 +781,7 @@ def del_vlan(request):
def add_nas(request):
nas = NasForm(request.POST or None)
if nas.is_valid():
with transaction.atomic(), reversion.create_revision():
nas.save()
reversion.set_user(request.user)
reversion.set_comment("Création")
nas.save()
messages.success(request, "Cet enregistrement nas a été ajouté")
return redirect("/machines/index_nas")
return form({'nasform': nas}, 'machines/machine.html', request)
@ -907,10 +796,7 @@ def edit_nas(request, nasid):
return redirect("/machines/index_nas/")
nas = NasForm(request.POST or None, instance=nas_instance)
if nas.is_valid():
with transaction.atomic(), reversion.create_revision():
nas.save()
reversion.set_user(request.user)
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in nas.changed_data))
nas.save()
messages.success(request, "Nas modifié")
return redirect("/machines/index_nas/")
return form({'nasform': nas}, 'machines/machine.html', request)
@ -923,9 +809,7 @@ def del_nas(request):
nas_dels = nas.cleaned_data['nas']
for nas_del in nas_dels:
try:
with transaction.atomic(), reversion.create_revision():
nas_del.delete()
reversion.set_user(request.user)
nas_del.delete()
messages.success(request, "Le nas a été supprimé")
except ProtectedError:
messages.error(request, "Erreur le Nas suivant %s ne peut être supprimé" % nas_del)