Commit 4716d7f3 authored by LEVY-FALK Hugo's avatar LEVY-FALK Hugo Committed by root
Browse files

Affichage de la page d'édition d'une liste de ports.

parent 80ac47b4
......@@ -24,7 +24,7 @@ from __future__ import unicode_literals
from django.forms import ModelForm, Form, ValidationError
from django import forms
from .models import Domain, Machine, Interface, IpList, MachineType, Extension, Mx, Text, Ns, Service, Vlan, Nas, IpType
from .models import Domain, Machine, Interface, IpList, MachineType, Extension, Mx, Text, Ns, Service, Vlan, Nas, IpType, PortList
from django.db.models import Q
from django.core.validators import validate_email
......@@ -229,5 +229,12 @@ class VlanForm(ModelForm):
class DelVlanForm(Form):
vlan = forms.ModelMultipleChoiceField(queryset=Vlan.objects.all(), label="Vlan actuels", widget=forms.CheckboxSelectMultiple)
class EditPortListForm(ModelForm):
tcp_ports = forms.CharField(required=False, label="Ports TCP")
udp_ports = forms.CharField(required=False, label="Ports UDP")
# interfaces = forms.ModelMultipleChoiceField(queryset=Interface.objects.filter(Q(has_public_ip=True)), label="Interface", widget=forms.CheckboxSelectMultiple)
class Meta:
model = PortList
fields = ['name']
......@@ -223,6 +223,7 @@ class Interface(models.Model):
machine = models.ForeignKey('Machine', on_delete=models.CASCADE)
type = models.ForeignKey('MachineType', on_delete=models.PROTECT)
details = models.CharField(max_length=255, blank=True)
has_public_ip = False
def is_active(self):
......@@ -278,6 +279,7 @@ class Interface(models.Model):
domain = None
return str(domain)
class Domain(models.Model):
PRETTY_NAME = "Domaine dns"
......@@ -447,6 +449,9 @@ class Port(models.Model):
return str(self.begin)
return '-'.join([str(self.begin), str(self.end)])
def show_port(self):
return str(self)
@receiver(post_save, sender=Machine)
def machine_post_save(sender, **kwargs):
......@@ -19,13 +19,13 @@
{% for pl in port_list %}
<td>{% for p in pl.tcp_ports%}{{p.show_port}}, {%endfor%}</td>
<td>{% for p in pl.udp_ports%}{{p.show_port}}, {%endfor%}</td>
<td class="text-right">
{% include 'buttons/suppr.html' href='machines:del-portlist' %}
{% include 'buttons/edit.html' href='machines:edit-portlist' %}
{% include 'buttons/edit.html' with href='machines:edit-portlist' %}
......@@ -93,4 +93,5 @@ urlpatterns = [
url(r'^rest/zones/$', views.zones, name='zones'),
url(r'^rest/service_servers/$', views.service_servers, name='service-servers'),
url(r'index_portlist/$', views.index_portlist, name='index-portlist'),
url(r'^edit_portlist/(?P<pk>[0-9]+)$', views.edit_portlist, name='edit-portlist'),
......@@ -48,6 +48,7 @@ from reversion.models import Version
import re
from .forms import NewMachineForm, EditMachineForm, EditInterfaceForm, AddInterfaceForm, MachineTypeForm, DelMachineTypeForm, ExtensionForm, DelExtensionForm, BaseEditInterfaceForm, BaseEditMachineForm
from .forms import EditIpTypeForm, IpTypeForm, DelIpTypeForm, DomainForm, AliasForm, DelAliasForm, NsForm, DelNsForm, TextForm, DelTextForm, MxForm, DelMxForm, VlanForm, DelVlanForm, ServiceForm, DelServiceForm, NasForm, DelNasForm
from .forms import EditPortListForm
from .models import IpType, Machine, Interface, IpList, MachineType, Extension, Mx, Ns, Domain, Service, Service_link, Vlan, Nas, Text, PortList
from users.models import User
from users.models import all_has_access
......@@ -913,11 +914,20 @@ def history(request, object, id):
def index_portlist(request):
port_list = PortList.objects.all().order_by('name')
return render(request, "machines/index_portlist.html", {'port_list':port_list})
def edit_portlist(request, pk):
port_list_instance = get_object_or_404(PortList, pk=pk)
port_list = EditPortListForm(request.POST or None, instance=port_list_instance)
if port_list.is_valid():
return redirect("/machines/index_portlist/")
return form({'machineform' : port_list}, 'machines/machine.html', request)
""" Framework Rest """
class JSONResponse(HttpResponse):
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment