From f7a74d35767f37a5f1d31b2660f9eedfa700a686 Mon Sep 17 00:00:00 2001 From: grisel-davy Date: Tue, 1 May 2018 12:09:59 +0200 Subject: [PATCH] =?UTF-8?q?d=C3=A9tection=20de=20la=20modification=20des?= =?UTF-8?q?=20objects=20du=20graph?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- topologie/models.py | 28 ++++++++++++++++++- .../templates/topologie/graph_switch.dot | 16 +++++++---- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/topologie/models.py b/topologie/models.py index 57f66901..8640e6fc 100644 --- a/topologie/models.py +++ b/topologie/models.py @@ -40,7 +40,7 @@ from __future__ import unicode_literals import itertools from django.db import models -from django.db.models.signals import post_save, post_delete +from django.db.models.signals import pre_save, post_save, post_delete from django.utils.functional import cached_property from django.dispatch import receiver from django.core.exceptions import ValidationError @@ -51,6 +51,9 @@ from reversion import revisions as reversion from machines.models import Machine, regen from re2o.mixins import AclMixin, RevMixin +from os.path import isfile +from os import remove + @@ -106,6 +109,12 @@ class AccessPoint(AclMixin, Machine): ("view_accesspoint", "Peut voir une borne"), ) + def port(self): + """Return the queryset of ports for this device""" + return Port.objects.filter( + machine_interface__machine=self + ) + def switch(self): """Return the switch where this is plugged""" return Switch.objects.filter( @@ -137,6 +146,12 @@ class Server(Machine): class Meta: proxy = True + def port(self): + """Return the queryset of ports for this device""" + return Port.objects.filter( + machine_interface__machine=self + ) + def switch(self): """Return the switch where this is plugged""" return Switch.objects.filter( @@ -489,3 +504,14 @@ def ap_post_delete(**_kwargs): def stack_post_delete(**_kwargs): """Vide les id des switches membres d'une stack supprimée""" Switch.objects.filter(stack=None).update(stack_member_id=None) + +#@receiver(post_save, sender=Port) +#@receiver(post_save, sender=AccessPoint) +#@receiver(post_save, sender=ModelSwitch) +#@receiver(post_save, sender=Building) +#@receiver(post_save, sender=Building) +#@receiver(post_save, sender=Server) +@receiver(pre_save, sender=Switch) +def delete_graph(**_kwargs): + if isfile("media/images/switchs.png"): + remove("media/images/switchs.png") diff --git a/topologie/templates/topologie/graph_switch.dot b/topologie/templates/topologie/graph_switch.dot index 2529e739..bf638d70 100644 --- a/topologie/templates/topologie/graph_switch.dot +++ b/topologie/templates/topologie/graph_switch.dot @@ -12,8 +12,9 @@ fontsize=15; label="Batiment {{ sub.bat_name }}"; {% if sub.bornes %} +{% block bornes %} node [label=< - +
@@ -22,8 +23,6 @@ node [label=< - -{% block bornes %} {% for borne in sub.bornes %} {% endfor %} +
Borne Port
@@ -37,9 +36,15 @@ node [label=<
+>] {{sub.bat_name}}bornes; {% endblock %} +{% endif %} {% if sub.machines %} +{% block machines %} +node [label=< + @@ -62,10 +67,9 @@ node [label=< {% endfor %} -{% endif %} -
Machine
->] {{sub.bat_name}}bornes; +>] {{sub.bat_name}}machines; +{% endblock %} {% endif %}