8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-27 15:12:25 +00:00

Liste et edition des types de machines

This commit is contained in:
chirac 2016-07-08 02:48:44 +02:00
parent 23246b848e
commit 42593b58ed
5 changed files with 53 additions and 5 deletions

View file

@ -0,0 +1,15 @@
<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>

View file

@ -0,0 +1,15 @@
{% 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 %}

View file

@ -1,6 +1,5 @@
{% extends "base.html" %} {% extends "base.html" %}
{% block sidebar %} {% block sidebar %}
<p><a href="{% url "machines:add-machinetype" %}">Ajouter un type de machine</a></p> <p><a href="{% url "machines:index-machinetype" %}">Liste des types de machine</a></p>
<p><a href="{% url "machines:del-machinetype" %}">Retirer un type de machine</a></p>
{% endblock %} {% endblock %}

View file

@ -7,6 +7,8 @@ urlpatterns = [
url(r'^edit_machine/(?P<interfaceid>[0-9]+)$', views.edit_machine, name='edit-machine'), 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'^new_interface/(?P<machineid>[0-9]+)$', views.new_interface, name='new-interface'),
url(r'^add_machinetype/$', views.add_machinetype, name='add-machinetype'), 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'^del_machinetype/$', views.del_machinetype, name='del-machinetype'),
url(r'^index_machinetype/$', views.index_machinetype, name='index-machinetype'),
url(r'^$', views.index, name='index'), url(r'^$', views.index, name='index'),
] ]

View file

@ -9,7 +9,7 @@ from django.contrib import messages
from django.db.models import ProtectedError from django.db.models import ProtectedError
from .forms import NewMachineForm, EditMachineForm, EditInterfaceForm, AddInterfaceForm, NewInterfaceForm, MachineTypeForm, DelMachineTypeForm 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 from users.models import User
def unassign_ips(user): def unassign_ips(user):
@ -111,9 +111,22 @@ def add_machinetype(request):
if machinetype.is_valid(): if machinetype.is_valid():
machinetype.save() machinetype.save()
messages.success(request, "Ce type de machine a été ajouté") 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) 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): def del_machinetype(request):
machinetype = DelMachineTypeForm(request.POST or None) machinetype = DelMachineTypeForm(request.POST or None)
if machinetype.is_valid(): if machinetype.is_valid():
@ -124,9 +137,13 @@ def del_machinetype(request):
messages.success(request, "Le type de machine a été supprimé") messages.success(request, "Le type de machine a été supprimé")
except ProtectedError: 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) 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) return form({'machineform': machinetype, 'interfaceform': None}, 'machines/machine.html', request)
def index(request): def index(request):
interfaces_list = Interface.objects.order_by('pk') interfaces_list = Interface.objects.order_by('pk')
return render(request, 'machines/index.html', {'interfaces_list': interfaces_list}) 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})