8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-22 03:13:12 +00:00

Gestion de l'historique dans topologie

This commit is contained in:
chirac 2016-07-21 02:30:36 +02:00
parent 13d4e2e795
commit 7bd2e31842
9 changed files with 99 additions and 13 deletions

View file

@ -0,0 +1,16 @@
<table class="table table-striped">
<thead>
<tr>
<th>Date</th>
<th>Cableur</th>
<th>Commentaire</th>
</tr>
</thead>
{% for rev in reversions %}
<tr>
<td>{{ rev.revision.date_created }}</td>
<td>{{ rev.revision.user }}</td>
<td>{{ rev.revision.comment }}</td>
</tr>
{% endfor %}
</table>

View file

@ -0,0 +1,12 @@
{% extends "re2o/sidebar.html" %}
{% load bootstrap3 %}
{% block title %}Historique{% endblock %}
{% block content %}
<h2>Historique de {{ object }}</h2>
{% include "re2o/aff_history.html" with reversions=reversions %}
<br />
<br />
<br />
{% endblock %}

View file

@ -1,15 +1,16 @@
from django.contrib import admin
from reversion.admin import VersionAdmin
from .models import Port, Room, Switch
class SwitchAdmin(admin.ModelAdmin):
class SwitchAdmin(VersionAdmin):
list_display = ('building','number','details')
class PortAdmin(admin.ModelAdmin):
class PortAdmin(VersionAdmin):
list_display = ('switch', 'port','room','machine_interface','details')
class RoomAdmin(admin.ModelAdmin):
class RoomAdmin(VersionAdmin):
list_display = ('name','details')
admin.site.register(Port, PortAdmin)

View file

@ -3,6 +3,7 @@ from django.forms import ModelForm, Form
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes.fields import GenericForeignKey
from django.core.exceptions import ValidationError
import reversion
def make_port_related(port):
related_port = port.related

View file

@ -11,7 +11,8 @@
<td>{{room.name}}</td>
<td>{{room.details}}</td>
<td>{% if is_infra %}<a class="btn btn-primary btn-sm" role="button" href="{% url 'topologie:edit-room' room.id %}"><i class="glyphicon glyphicon-random"></i> Editer</a>
<a class="btn btn-danger btn-sm" role="button" href="{% url 'topologie:del-room' room.id %}"><i class="glyphicon glyphicon-trash"></i> Supprimer</a>{% endif %}</td>
<a class="btn btn-danger btn-sm" role="button" href="{% url 'topologie:del-room' room.id %}"><i class="glyphicon glyphicon-trash"></i> Supprimer</a>{% endif %}
<a class="btn btn-info btn-sm" role="button" href="{% url 'topologie:history' 'room' room.pk %}"><i class="glyphicon glyphicon-repeat"></i> Historique</a></td>
</tr>
{% endfor %}
</table>

View file

@ -16,7 +16,8 @@
<td>{{ port.machine_interface }}</td>
<td>{{ port.related }}</td>
<td>{{ port.details }}</td>
<td>{% if is_infra %}<a class="btn btn-primary btn-sm" role="button" href="{% url 'topologie:edit-port' port.id %}"><i class="glyphicon glyphicon-random"></i> Editer</a>{% endif %}</td>
<td>{% if is_infra %}<a class="btn btn-primary btn-sm" role="button" href="{% url 'topologie:edit-port' port.id %}"><i class="glyphicon glyphicon-random"></i> Editer</a>{% endif %}
<a class="btn btn-info btn-sm" role="button" href="{% url 'topologie:history' 'port' port.pk %}"><i class="glyphicon glyphicon-repeat"></i> Historique</a></td>
</tr>
{% endfor %}
</table>

View file

@ -12,7 +12,8 @@
<td>{{switch.building}}</td>
<td>{{switch.number}}</td>
<td>{{switch.details}}</td>
<td><a class="btn btn-primary btn-sm" role="button" href="{% url 'topologie:index-port' switch.pk %}"><i class="glyphicon glyphicon-cog"></i> Configurer</a></td>
<td><a class="btn btn-primary btn-sm" role="button" href="{% url 'topologie:index-port' switch.pk %}"><i class="glyphicon glyphicon-cog"></i> Configurer</a>
<a class="btn btn-info btn-sm" role="button" href="{% url 'topologie:history' 'switch' switch.pk %}"><i class="glyphicon glyphicon-repeat"></i> Historique</a></td>
</tr>
{% endfor %}
</table>

View file

@ -10,6 +10,9 @@ urlpatterns = [
url(r'^edit_room/(?P<room_id>[0-9]+)$', views.edit_room, name='edit-room'),
url(r'^del_room/(?P<room_id>[0-9]+)$', views.del_room, name='del-room'),
url(r'^switch/(?P<switch_id>[0-9]+)$', views.index_port, name='index-port'),
url(r'^history/(?P<object>switch)/(?P<id>[0-9]+)$', views.history, name='history'),
url(r'^history/(?P<object>port)/(?P<id>[0-9]+)$', views.history, name='history'),
url(r'^history/(?P<object>room)/(?P<id>[0-9]+)$', views.history, name='history'),
url(r'^edit_port/(?P<port_id>[0-9]+)$', views.edit_port, name='edit-port'),
url(r'^new_port/(?P<switch_id>[0-9]+)$', views.new_port, name='new-port'),
url(r'^edit_switch/(?P<switch_id>[0-9]+)$', views.edit_switch, name='edit-switch'),

View file

@ -2,6 +2,8 @@ from django.shortcuts import render, redirect
from django.contrib import messages
from django.contrib.auth.decorators import login_required, permission_required
from django.db import IntegrityError
from django.db import transaction
from reversion import revisions as reversion
from topologie.models import Switch, Port, Room
from topologie.forms import EditPortForm, EditSwitchForm, AddPortForm, EditRoomForm
@ -13,6 +15,33 @@ def index(request):
switch_list = Switch.objects.order_by('building', 'number')
return render(request, 'topologie/index.html', {'switch_list': switch_list})
@login_required
@permission_required('cableur')
def history(request, object, id):
if object == 'switch':
try:
object_instance = Switch.objects.get(pk=id)
except Switch.DoesNotExist:
messages.error(request, "Switch inexistant")
return redirect("/topologie/")
elif object == 'port':
try:
object_instance = Port.objects.get(pk=id)
except Port.DoesNotExist:
messages.error(request, "Port inexistant")
return redirect("/topologie/")
elif object == 'room':
try:
object_instance = Room.objects.get(pk=id)
except Room.DoesNotExist:
messages.error(request, "Chambre inexistante")
return redirect("/topologie/")
else:
messages.error(request, "Objet inconnu")
return redirect("/topologie/")
reversions = reversion.get_for_object(object_instance)
return render(request, 're2o/history.html', {'reversions': reversions, 'object': object_instance})
@login_required
@permission_required('cableur')
def index_port(request, switch_id):
@ -43,7 +72,10 @@ def new_port(request, switch_id):
port = port.save(commit=False)
port.switch = switch
try:
port.save()
with transaction.atomic(), reversion.create_revision():
port.save()
reversion.set_user(request.user)
reversion.set_comment("Création")
messages.success(request, "Port ajouté")
except IntegrityError:
messages.error(request,"Ce port existe déjà" )
@ -60,7 +92,10 @@ def edit_port(request, port_id):
return redirect("/topologie/")
port = EditPortForm(request.POST or None, instance=port)
if port.is_valid():
port.save()
with transaction.atomic(), reversion.create_revision():
port.save()
reversion.set_user(request.user)
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in port.changed_data))
messages.success(request, "Le port a bien été modifié")
return redirect("/topologie/")
return form({'topoform':port}, 'topologie/topo.html', request)
@ -70,7 +105,10 @@ def edit_port(request, port_id):
def new_switch(request):
switch = EditSwitchForm(request.POST or None)
if switch.is_valid():
switch.save()
with transaction.atomic(), reversion.create_revision():
switch.save()
reversion.set_user(request.user)
reversion.set_comment("Création")
messages.success(request, "Le switch a été créé")
return redirect("/topologie/")
return form({'topoform':switch}, 'topologie/topo.html', request)
@ -85,7 +123,10 @@ def edit_switch(request, switch_id):
return redirect("/topologie/")
switch = EditSwitchForm(request.POST or None, instance=switch)
if switch.is_valid():
switch.save()
with transaction.atomic(), reversion.create_revision():
switch.save()
reversion.set_user(request.user)
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in switch.changed_data))
messages.success(request, "Le switch a bien été modifié")
return redirect("/topologie/")
return form({'topoform':switch}, 'topologie/topo.html', request)
@ -95,7 +136,10 @@ def edit_switch(request, switch_id):
def new_room(request):
room = EditRoomForm(request.POST or None)
if room.is_valid():
room.save()
with transaction.atomic(), reversion.create_revision():
room.save()
reversion.set_user(request.user)
reversion.set_comment("Création")
messages.success(request, "La chambre a été créé")
return redirect("/topologie/index_room/")
return form({'topoform':room}, 'topologie/topo.html', request)
@ -110,7 +154,10 @@ def edit_room(request, room_id):
return redirect("/topologie/index_room/")
room = EditRoomForm(request.POST or None, instance=room)
if room.is_valid():
room.save()
with transaction.atomic(), reversion.create_revision():
room.save()
reversion.set_user(request.user)
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in room.changed_data))
messages.success(request, "La chambre a bien été modifiée")
return redirect("/topologie/index_room/")
return form({'topoform':room}, 'topologie/topo.html', request)
@ -124,7 +171,10 @@ def del_room(request, room_id):
messages.error(request, u"Chambre inexistante" )
return redirect("/topologie/index_room/")
if request.method == "POST":
room.delete()
with transaction.atomic(), reversion.create_revision():
room.delete()
reversion.set_user(request.user)
reversion.set_comment("Destruction")
messages.success(request, "La chambre/prise a été détruite")
return redirect("/topologie/index_room/")
return form({'objet': room, 'objet_name': 'Chambre'}, 'topologie/delete.html', request)