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

Support des enregistrements NS pour chaque zone

This commit is contained in:
Gabriel Detraz 2016-11-19 18:21:05 +01:00
parent 78d32d911c
commit 88f7887cd6
6 changed files with 104 additions and 2 deletions

View file

@ -137,3 +137,14 @@ class DelMxForm(ModelForm):
exclude = ['zone', 'priority', 'name']
model = Mx
class NsForm(ModelForm):
class Meta:
model = Ns
fields = ['zone', 'interface']
class DelNsForm(ModelForm):
ns = forms.ModelMultipleChoiceField(queryset=Ns.objects.all(), label="Enregistrements NS actuels", widget=forms.CheckboxSelectMultiple)
class Meta:
exclude = ['zone', 'interface']
model = Ns

View file

@ -64,6 +64,9 @@ class Ns(models.Model):
zone = models.ForeignKey('Extension', on_delete=models.PROTECT)
interface = models.OneToOneField('Interface', on_delete=models.PROTECT)
def __str__(self):
return str(self.zone) + ' ' + str(self.interface)
class Interface(models.Model):
PRETTY_NAME = "Interface"

View file

@ -0,0 +1,24 @@
<table class="table table-striped">
<thead>
<tr>
<th>Zone concernée</th>
<th>Interface autoritaire de la zone</th>
<th></th>
<th></th>
</tr>
</thead>
{% for ns in ns_list %}
<tr>
<td>{{ ns.zone }}</td>
<td>{{ ns.interface }}</td>
<td class="text-right">
{% if is_infra %}
{% include 'buttons/edit.html' with href='machines:edit-ns' id=ns.id %}
{% endif %}
{% include 'buttons/history.html' with href='machines:history' name='ns' id=ns.id %}
</td>
</tr>
{% endfor %}
</table>

View file

@ -17,7 +17,13 @@
<a class="btn btn-danger btn-sm" role="button" href="{% url 'machines:del-mx' %}"><i class="glyphicon glyphicon-trash"></i> Supprimer un enregistrement MX</a>
{% endif %}
{% include "machines/aff_mx.html" with mx_list=mx_list %}
<br />
<h2>Liste des enregistrements NS</h2>
{% if is_infra %}
<a class="btn btn-primary btn-sm" role="button" href="{% url 'machines:add-ns' %}"><i class="glyphicon glyphicon-plus"></i> Ajouter un enregistrement NS</a>
<a class="btn btn-danger btn-sm" role="button" href="{% url 'machines:del-ns' %}"><i class="glyphicon glyphicon-trash"></i> Supprimer un enregistrement NS</a>
{% endif %}
{% include "machines/aff_ns.html" with ns_list=ns_list %}
<br />
<br />
<br />
{% endblock %}

View file

@ -23,12 +23,16 @@ urlpatterns = [
url(r'^add_mx/$', views.add_mx, name='add-mx'),
url(r'^edit_mx/(?P<mxid>[0-9]+)$', views.edit_mx, name='edit-mx'),
url(r'^del_mx/$', views.del_mx, name='del-mx'),
url(r'^add_ns/$', views.add_ns, name='add-ns'),
url(r'^edit_ns/(?P<nsid>[0-9]+)$', views.edit_ns, name='edit-ns'),
url(r'^del_ns/$', views.del_ns, name='del-ns'),
url(r'^index_extension/$', views.index_extension, name='index-extension'),
url(r'^history/(?P<object>machine)/(?P<id>[0-9]+)$', views.history, name='history'),
url(r'^history/(?P<object>interface)/(?P<id>[0-9]+)$', views.history, name='history'),
url(r'^history/(?P<object>machinetype)/(?P<id>[0-9]+)$', views.history, name='history'),
url(r'^history/(?P<object>extension)/(?P<id>[0-9]+)$', views.history, name='history'),
url(r'^history/(?P<object>mx)/(?P<id>[0-9]+)$', views.history, name='history'),
url(r'^history/(?P<object>ns)/(?P<id>[0-9]+)$', views.history, name='history'),
url(r'^history/(?P<object>iptype)/(?P<id>[0-9]+)$', views.history, name='history'),
url(r'^$', views.index, name='index'),
url(r'^rest/mac-ip/$', views.mac_ip, name='mac-ip'),

View file

@ -22,7 +22,7 @@ from reversion import revisions as reversion
import re
from .forms import NewMachineForm, EditMachineForm, EditInterfaceForm, AddInterfaceForm, MachineTypeForm, DelMachineTypeForm, ExtensionForm, DelExtensionForm, BaseEditInterfaceForm, BaseEditMachineForm, Alias
from .forms import IpTypeForm, DelIpTypeForm, NewAliasForm, EditAliasForm, MxForm, DelMxForm
from .forms import IpTypeForm, DelIpTypeForm, NewAliasForm, EditAliasForm, NsForm, DelNsForm, MxForm, DelMxForm
from .models import IpType, Machine, Interface, IpList, MachineType, Extension, Mx, Ns
from users.models import User
from re2o.settings import PAGINATION_NUMBER, PAGINATION_LARGE_NUMBER
@ -417,6 +417,54 @@ def del_mx(request):
return redirect("/machines/index_extension")
return form({'machineform': mx, 'interfaceform': None}, 'machines/machine.html', request)
@login_required
@permission_required('infra')
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")
messages.success(request, "Cet enregistrement ns a été ajouté")
return redirect("/machines/index_extension")
return form({'machineform': ns, 'interfaceform': None}, 'machines/machine.html', request)
@login_required
@permission_required('infra')
def edit_ns(request, nsid):
try:
ns_instance = Ns.objects.get(pk=nsid)
except Ns.DoesNotExist:
messages.error(request, u"Entrée inexistante" )
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))
messages.success(request, "Ns modifié")
return redirect("/machines/index_extension/")
return form({'machineform': ns}, 'machines/machine.html', request)
@login_required
@permission_required('infra')
def del_ns(request):
ns = DelNsForm(request.POST or None)
if ns.is_valid():
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)
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)
return redirect("/machines/index_extension")
return form({'machineform': ns, 'interfaceform': None}, 'machines/machine.html', request)
@login_required
@permission_required('cableur')
def index(request):
@ -497,6 +545,12 @@ def history(request, object, id):
except Mx.DoesNotExist:
messages.error(request, "Mx inexistant")
return redirect("/machines/")
elif object == 'ns' and request.user.has_perms(('cableur',)):
try:
object_instance = Ns.objects.get(pk=id)
except Ns.DoesNotExist:
messages.error(request, "Ns inexistant")
return redirect("/machines/")
else:
messages.error(request, "Objet inconnu")
return redirect("/machines/")