From 5f70142c6858dd4d040a2cbb3971ac7236a23a50 Mon Sep 17 00:00:00 2001 From: chirac Date: Thu, 7 Jul 2016 19:15:33 +0200 Subject: [PATCH] =?UTF-8?q?Permet=20d'ajouter=20une=20interface=20=C3=A0?= =?UTF-8?q?=20une=20machine?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- machines/forms.py | 5 ++++- machines/templates/machines/aff_machines.html | 15 ++++++++------- machines/templates/machines/index.html | 2 +- machines/views.py | 8 ++++++-- search/templates/search/index.html | 6 +++--- search/views.py | 2 +- users/templates/users/profil.html | 4 ++-- users/views.py | 2 +- 8 files changed, 26 insertions(+), 18 deletions(-) diff --git a/machines/forms.py b/machines/forms.py index badb3197..57478ad4 100644 --- a/machines/forms.py +++ b/machines/forms.py @@ -31,11 +31,14 @@ class AddInterfaceForm(EditInterfaceForm): class Meta(EditInterfaceForm.Meta): fields = ['ipv4','mac_address','dns','details'] + def __init__(self, *args, **kwargs): + super(AddInterfaceForm, self).__init__(*args, **kwargs) + self.fields['ipv4'].empty_label = "Assignation automatique de l'ipv4" + class NewInterfaceForm(EditInterfaceForm): class Meta(EditInterfaceForm.Meta): fields = ['mac_address','dns','details'] - class MachineTypeForm(ModelForm): class Meta: model = MachineType diff --git a/machines/templates/machines/aff_machines.html b/machines/templates/machines/aff_machines.html index 612c1366..06f589ab 100644 --- a/machines/templates/machines/aff_machines.html +++ b/machines/templates/machines/aff_machines.html @@ -9,14 +9,15 @@ - {% for machine in machine_list %} + {% for interface in interfaces_list %} - {{ machine.dns }} - {{ machine.machine.user }} - {{ machine.machine.type }} - {{ machine.mac_address }} - {{ machine.ipv4 }} - Editer + {{ interface.dns }} + {{ interface.machine.user }} + {{ interface.machine.type }} + {{ interface.mac_address }} + {{ interface.ipv4 }} + Editer + Ajouter une interface {% endfor %} diff --git a/machines/templates/machines/index.html b/machines/templates/machines/index.html index e9039ced..eaebf7af 100644 --- a/machines/templates/machines/index.html +++ b/machines/templates/machines/index.html @@ -4,7 +4,7 @@ {% block title %}Machines{% endblock %} {% block content %} - {% include "machines/aff_machines.html" with machines_list=machines_list %} + {% include "machines/aff_machines.html" with interfaces_list=interfaces_list %}


diff --git a/machines/views.py b/machines/views.py index 4a71606b..5d7ec19c 100644 --- a/machines/views.py +++ b/machines/views.py @@ -97,6 +97,10 @@ def new_interface(request, machineid): machine_form.save() new_interface = interface_form.save(commit=False) new_interface.machine = machine + if free_ip() and not new_interface.ipv4: + new_interface = assign_ipv4(new_interface) + elif not new_interface.ipv4: + messages.error(request, u"Il n'y a plus d'ip disponibles") new_interface.save() messages.success(request, "L'interface a été ajoutée") return redirect("/machines/") @@ -124,5 +128,5 @@ def del_machinetype(request): return form({'machineform': machinetype, 'interfaceform': None}, 'machines/machine.html', request) def index(request): - machine_list = Interface.objects.order_by('pk') - return render(request, 'machines/index.html', {'machine_list': machine_list}) + interfaces_list = Interface.objects.order_by('pk') + return render(request, 'machines/index.html', {'interfaces_list': interfaces_list}) diff --git a/search/templates/search/index.html b/search/templates/search/index.html index ed536bd9..9d60279d 100644 --- a/search/templates/search/index.html +++ b/search/templates/search/index.html @@ -8,9 +8,9 @@

Résultats dans les utilisateurs

{% include "users/aff_users.html" with users_list=users_list %} {% endif%} - {% if machine_list %} + {% if interfaces_list %}

Résultats dans les machines :

- {% include "machines/aff_machines.html" with machine_list=machine_list %} + {% include "machines/aff_machines.html" with interfaces_list=interfaces_list %} {% endif %} {% if facture_list %}

Résultats dans les factures :

@@ -32,7 +32,7 @@

Résultats dans les ports :

{% include "topologie/aff_port.html" with port_list=port_list %} {% endif %} - {% if not ban_list and not machine_list and not users_list and not facture_list and not white_list and not port_list and not switch_list%} + {% if not ban_list and not interfaces_list and not users_list and not facture_list and not white_list and not port_list and not switch_list%}

Aucun résultat

{% endif %}
diff --git a/search/views.py b/search/views.py index 95e19000..61012757 100644 --- a/search/views.py +++ b/search/views.py @@ -78,7 +78,7 @@ def search_result(search, type): portlist = Port.objects.filter(details__icontains = search) if i == '6': switchlist = Switch.objects.filter(details__icontains = search) - return {'users_list': connexion, 'machine_list' : machines, 'facture_list' : factures, 'ban_list' : bans, 'white_list': whitelists, 'port_list':portlist, 'switch_list':switchlist} + return {'users_list': connexion, 'interfaces_list' : machines, 'facture_list' : factures, 'ban_list' : bans, 'white_list': whitelists, 'port_list':portlist, 'switch_list':switchlist} def search(request): if request.method == 'POST': diff --git a/users/templates/users/profil.html b/users/templates/users/profil.html index ea5793fd..2592415b 100644 --- a/users/templates/users/profil.html +++ b/users/templates/users/profil.html @@ -81,8 +81,8 @@

Machines :

Ajouter une machine

- {% if machine_list %} - {% include "machines/aff_machines.html" with machine_list=machine_list %} + {% if interfaces_list %} + {% include "machines/aff_machines.html" with interfaces_list=interfaces_list %} {% else %}

Aucune machine

{% endif %} diff --git a/users/views.py b/users/views.py index 243ad621..bbd431fe 100644 --- a/users/views.py +++ b/users/views.py @@ -275,5 +275,5 @@ def profil(request, userid): if(is_whitelisted(users)): end_whitelists=end_whitelist(users) list_droits = Right.objects.filter(user=users) - return render(request, 'users/profil.html', {'user': users, 'machine_list' :machines, 'facture_list':factures, 'ban_list':bans, 'white_list':whitelists,'end_ban':end_bans,'end_whitelist':end_whitelists, 'end_adhesion':end_adhesion(users), 'actif':has_access(users), 'list_droits': list_droits}) + return render(request, 'users/profil.html', {'user': users, 'interfaces_list' :machines, 'facture_list':factures, 'ban_list':bans, 'white_list':whitelists,'end_ban':end_bans,'end_whitelist':end_whitelists, 'end_adhesion':end_adhesion(users), 'actif':has_access(users), 'list_droits': list_droits})