mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-05 09:26:27 +00:00
Ajout de la suppression d'une stack
This commit is contained in:
parent
f47f4cb292
commit
c302bc6cb7
5 changed files with 52 additions and 2 deletions
21
topologie/migrations/0024_auto_20170818_1021.py
Normal file
21
topologie/migrations/0024_auto_20170818_1021.py
Normal file
|
@ -0,0 +1,21 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.10.7 on 2017-08-18 08:21
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('topologie', '0023_auto_20170817_1654'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='switch',
|
||||
name='stack',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='topologie.Stack'),
|
||||
),
|
||||
]
|
|
@ -21,6 +21,8 @@
|
|||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
from django.db import models
|
||||
from django.db.models.signals import post_delete
|
||||
from django.dispatch import receiver
|
||||
from django.forms import ModelForm, Form
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.contrib.contenttypes.fields import GenericForeignKey
|
||||
|
@ -69,7 +71,7 @@ class Switch(models.Model):
|
|||
location = models.CharField(max_length=255)
|
||||
number = models.IntegerField()
|
||||
details = models.CharField(max_length=255, blank=True)
|
||||
stack = models.ForeignKey(Stack, blank=True, null=True)
|
||||
stack = models.ForeignKey(Stack, blank=True, null=True, on_delete=models.SET_NULL)
|
||||
stack_member_id = models.IntegerField(blank=True, null=True)
|
||||
|
||||
class Meta:
|
||||
|
@ -138,3 +140,6 @@ class Room(models.Model):
|
|||
def __str__(self):
|
||||
return str(self.name)
|
||||
|
||||
@receiver(post_delete, sender=Stack)
|
||||
def stack_post_delete(sender, **kwargs):
|
||||
Switch.objects.filter(stack=None).update(stack_member_id = None)
|
||||
|
|
|
@ -43,6 +43,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
<a class="btn btn-primary btn-sm" role="button" title="Éditer" href="{% url 'topologie:edit-stack' stack.id %}">
|
||||
<i class="glyphicon glyphicon-edit"></i>
|
||||
</a>
|
||||
<a class="btn btn-danger btn-sm" role="button" title="Supprimer" href="{% url 'topologie:del-stack' stack.pk %}">
|
||||
<i class="glyphicon glyphicon-trash"></i>
|
||||
</a>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
|
|
|
@ -42,5 +42,6 @@ urlpatterns = [
|
|||
url(r'^new_stack/$', views.new_stack, name='new-stack'),
|
||||
url(r'^index_stack/$', views.index_stack, name='index-stack'),
|
||||
url(r'^edit_stack/(?P<stack_id>[0-9]+)$', views.edit_stack, name='edit-stack'),
|
||||
url(r'^del_stack/(?P<stack_id>[0-9]+)$', views.del_stack, name='del-stack'),
|
||||
]
|
||||
|
||||
|
|
|
@ -179,7 +179,7 @@ def edit_stack(request,stack_id):
|
|||
stack = Stack.objects.get(pk=stack_id)
|
||||
except Stack.DoesNotExist:
|
||||
messages.error(request, u"Stack inexistante")
|
||||
return redirect("/topologie/index_stack/")
|
||||
return redirect('/topologie/index_stack/')
|
||||
stack = StackForm(request.POST or None, instance=stack)
|
||||
if stack.is_valid():
|
||||
with transaction.atomic(), reversion.create_revision():
|
||||
|
@ -189,6 +189,26 @@ def edit_stack(request,stack_id):
|
|||
return redirect('/topologie/index_stack')
|
||||
return form({'topoform':stack}, 'topologie/topo.html', request)
|
||||
|
||||
@login_required
|
||||
@permission_required('infra')
|
||||
def del_stack(request,stack_id):
|
||||
try:
|
||||
stack = Stack.objects.get(pk=stack_id)
|
||||
except Stack.DoesNotExist:
|
||||
messages.error(request, u"Stack inexistante")
|
||||
return redirect('/topologie/index_stack')
|
||||
if request.method == "POST":
|
||||
try:
|
||||
with transaction.atomic(), reversion.create_revision():
|
||||
stack.delete()
|
||||
reversion.set_user(request.user)
|
||||
reversion.set_comment("Destruction")
|
||||
messages.success(request, "La stack a eté détruite")
|
||||
except ProtectedError:
|
||||
messages.error(request, "La stack %s est affectée à un autre objet, impossible de la supprimer" % stack)
|
||||
return redirect('/topologie/index_stack')
|
||||
return form({'objet':stack}, 'topologie/delete.html', request)
|
||||
|
||||
@login_required
|
||||
@permission_required('infra')
|
||||
def new_switch(request):
|
||||
|
|
Loading…
Reference in a new issue