diff --git a/machines/templates/machines/aff_machinetype.html b/machines/templates/machines/aff_machinetype.html new file mode 100644 index 00000000..981d1b48 --- /dev/null +++ b/machines/templates/machines/aff_machinetype.html @@ -0,0 +1,15 @@ + + + + + + + + {% for type in machinetype_list %} + + + + + {% endfor %} +
Type de machine
{{ type.type }} Editer
+ diff --git a/machines/templates/machines/index_machinetype.html b/machines/templates/machines/index_machinetype.html new file mode 100644 index 00000000..22e8824a --- /dev/null +++ b/machines/templates/machines/index_machinetype.html @@ -0,0 +1,15 @@ +{% extends "machines/sidebar.html" %} +{% load bootstrap3 %} + +{% block title %}Machines{% endblock %} + +{% block content %} +

Liste des types de machines

+ Ajouter un type de machine + Supprimer un ou plusieurs types de machines + {% include "machines/aff_machinetype.html" with machinetype_list=machinetype_list %} +
+
+
+{% endblock %} + diff --git a/machines/templates/machines/sidebar.html b/machines/templates/machines/sidebar.html index 1ab05807..117b8770 100644 --- a/machines/templates/machines/sidebar.html +++ b/machines/templates/machines/sidebar.html @@ -1,6 +1,5 @@ {% extends "base.html" %} {% block sidebar %} -

Ajouter un type de machine

-

Retirer un type de machine

+

Liste des types de machine

{% endblock %} diff --git a/machines/urls.py b/machines/urls.py index 20966c5a..ff4bef8e 100644 --- a/machines/urls.py +++ b/machines/urls.py @@ -7,6 +7,8 @@ urlpatterns = [ url(r'^edit_machine/(?P[0-9]+)$', views.edit_machine, name='edit-machine'), url(r'^new_interface/(?P[0-9]+)$', views.new_interface, name='new-interface'), url(r'^add_machinetype/$', views.add_machinetype, name='add-machinetype'), + url(r'^edit_machinetype/(?P[0-9]+)$', views.edit_machinetype, name='edit-machinetype'), url(r'^del_machinetype/$', views.del_machinetype, name='del-machinetype'), + url(r'^index_machinetype/$', views.index_machinetype, name='index-machinetype'), url(r'^$', views.index, name='index'), ] diff --git a/machines/views.py b/machines/views.py index ffa3a320..eeb7ceb7 100644 --- a/machines/views.py +++ b/machines/views.py @@ -9,7 +9,7 @@ from django.contrib import messages from django.db.models import ProtectedError from .forms import NewMachineForm, EditMachineForm, EditInterfaceForm, AddInterfaceForm, NewInterfaceForm, MachineTypeForm, DelMachineTypeForm -from .models import Machine, Interface, IpList +from .models import Machine, Interface, IpList, MachineType from users.models import User def unassign_ips(user): @@ -111,9 +111,22 @@ def add_machinetype(request): if machinetype.is_valid(): machinetype.save() messages.success(request, "Ce type de machine a été ajouté") - return redirect("/machines/") + return redirect("/machines/index_machinetype") return form({'machineform': machinetype, 'interfaceform': None}, 'machines/machine.html', request) +def edit_machinetype(request, machinetypeid): + try: + machinetype_instance = MachineType.objects.get(pk=machinetypeid) + except MachineType.DoesNotExist: + messages.error(request, u"Entrée inexistante" ) + return redirect("/machines/index_machinetype/") + machinetype = MachineTypeForm(request.POST or None, instance=machinetype_instance) + if machinetype.is_valid(): + machinetype.save() + messages.success(request, "Type de machine modifié") + return redirect("/machines/index_machinetype/") + return form({'machineform': machinetype}, 'machines/machine.html', request) + def del_machinetype(request): machinetype = DelMachineTypeForm(request.POST or None) if machinetype.is_valid(): @@ -124,9 +137,13 @@ def del_machinetype(request): 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) - return redirect("/machines/") + return redirect("/machines/index_machinetype") return form({'machineform': machinetype, 'interfaceform': None}, 'machines/machine.html', request) def index(request): interfaces_list = Interface.objects.order_by('pk') return render(request, 'machines/index.html', {'interfaces_list': interfaces_list}) + +def index_machinetype(request): + machinetype_list = MachineType.objects.order_by('type') + return render(request, 'machines/index_machinetype.html', {'machinetype_list':machinetype_list})