Commit 42593b58 authored by chirac's avatar chirac

Liste et edition des types de machines

parent 23246b84
<table class="table table-striped">
<thead>
<tr>
<th>Type de machine</th>
<th></th>
</tr>
</thead>
{% for type in machinetype_list %}
<tr>
<td>{{ type.type }}</td>
<td><a class="btn btn-primary btn-sm" role="button" href="{% url 'machines:edit-machinetype' type.id %}"><i class="glyphicon glyphicon-pushpin"></i> Editer</a></td>
</tr>
{% endfor %}
</table>
{% extends "machines/sidebar.html" %}
{% load bootstrap3 %}
{% block title %}Machines{% endblock %}
{% block content %}
<h2>Liste des types de machines</h2>
<a class="btn btn-primary btn-sm" role="button" href="{% url 'machines:add-machinetype' %}"><i class="glyphicon glyphicon-plus"></i> Ajouter un type de machine</a>
<a class="btn btn-primary btn-sm" role="button" href="{% url 'machines:del-machinetype' %}"><i class="glyphicon glyphicon-trash"></i> Supprimer un ou plusieurs types de machines</a>
{% include "machines/aff_machinetype.html" with machinetype_list=machinetype_list %}
<br />
<br />
<br />
{% endblock %}
{% extends "base.html" %}
{% block sidebar %}
<p><a href="{% url "machines:add-machinetype" %}">Ajouter un type de machine</a></p>
<p><a href="{% url "machines:del-machinetype" %}">Retirer un type de machine</a></p>
<p><a href="{% url "machines:index-machinetype" %}">Liste des types de machine</a></p>
{% endblock %}
......@@ -7,6 +7,8 @@ urlpatterns = [
url(r'^edit_machine/(?P<interfaceid>[0-9]+)$', views.edit_machine, name='edit-machine'),
url(r'^new_interface/(?P<machineid>[0-9]+)$', views.new_interface, name='new-interface'),
url(r'^add_machinetype/$', views.add_machinetype, name='add-machinetype'),
url(r'^edit_machinetype/(?P<machinetypeid>[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'),
]
......@@ -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})
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