diff --git a/machines/models.py b/machines/models.py
index c4ad724a..3ef39702 100644
--- a/machines/models.py
+++ b/machines/models.py
@@ -34,7 +34,7 @@ class Interface(models.Model):
ipv4 = models.OneToOneField('IpList', on_delete=models.PROTECT, blank=True, null=True)
#ipv6 = models.GenericIPAddressField(protocol='IPv6', null=True)
mac_address = MACAddressField(integer=False, unique=True)
- machine = models.ForeignKey('Machine', on_delete=models.PROTECT)
+ machine = models.ForeignKey('Machine', on_delete=models.CASCADE)
details = models.CharField(max_length=255, blank=True)
dns = models.CharField(help_text="Obligatoire et unique, doit se terminer en %s et ne pas comporter d'autres points" % ", ".join(Extension.objects.values_list('name', flat=True)), max_length=255, unique=True)
diff --git a/machines/templates/machines/aff_machines.html b/machines/templates/machines/aff_machines.html
index 06f589ab..ee601e69 100644
--- a/machines/templates/machines/aff_machines.html
+++ b/machines/templates/machines/aff_machines.html
@@ -1,23 +1,36 @@
- Nom dns |
Proprietaire |
Type |
+ Interfaces |
+
+
+ {% for machine in machines_list %}
+
+ {{ machine.user }} |
+ {{ machine.type }}
+ Ajouter une interface
+ Supprimer la machine |
+
+
+
+ Nom dns |
Mac |
Ipv4 |
|
-
- {% for interface in interfaces_list %}
-
+
+ {% for interface in machine.interface_set.all %}
+
{{ interface.dns }} |
- {{ interface.machine.user }} |
- {{ interface.machine.type }} |
{{ interface.mac_address }} |
{{ interface.ipv4 }} |
- Editer
- Ajouter une interface |
+ Editer
+ Supprimer |
+
+ {% endfor %}
+
|
{% endfor %}
diff --git a/machines/templates/machines/index.html b/machines/templates/machines/index.html
index 4a3bde3d..ef373f0d 100644
--- a/machines/templates/machines/index.html
+++ b/machines/templates/machines/index.html
@@ -5,7 +5,7 @@
{% block content %}
Machines
- {% include "machines/aff_machines.html" with interfaces_list=interfaces_list %}
+ {% include "machines/aff_machines.html" with machines_list=machines_list %}
diff --git a/machines/urls.py b/machines/urls.py
index c80c3da6..f9761b55 100644
--- a/machines/urls.py
+++ b/machines/urls.py
@@ -4,8 +4,10 @@ from . import views
urlpatterns = [
url(r'^new_machine/(?P[0-9]+)$', views.new_machine, name='new-machine'),
- url(r'^edit_machine/(?P[0-9]+)$', views.edit_machine, name='edit-machine'),
+ url(r'^edit_interface/(?P[0-9]+)$', views.edit_interface, name='edit-interface'),
+ url(r'^del_machine/(?P[0-9]+)$', views.del_machine, name='del-machine'),
url(r'^new_interface/(?P[0-9]+)$', views.new_interface, name='new-interface'),
+ url(r'^del_interface/(?P[0-9]+)$', views.del_interface, name='del-interface'),
url(r'^add_machinetype/$', views.add_machinetype, name='add-machinetype'),
url(r'^edit_machinetype/(?P[0-9]+)$', views.edit_machinetype, name='edit-machinetype'),
url(r'^del_machinetype/$', views.del_machinetype, name='del-machinetype'),
diff --git a/machines/views.py b/machines/views.py
index 2050ec16..eec189c8 100644
--- a/machines/views.py
+++ b/machines/views.py
@@ -99,7 +99,7 @@ def new_machine(request, userid):
return form({'machineform': machine, 'interfaceform': interface}, 'machines/machine.html', request)
@login_required
-def edit_machine(request, interfaceid):
+def edit_interface(request, interfaceid):
try:
interface = Interface.objects.get(pk=interfaceid)
except Interface.DoesNotExist:
@@ -124,6 +124,21 @@ def edit_machine(request, interfaceid):
return redirect("/users/profil/" + str(interface.machine.user.id))
return form({'machineform': machine_form, 'interfaceform': interface_form}, 'machines/machine.html', request)
+@login_required
+def del_machine(request, machineid):
+ try:
+ machine = Machine.objects.get(pk=machineid)
+ except Machine.DoesNotExist:
+ messages.error(request, u"Machine inexistante" )
+ return redirect("/machines")
+ if not request.user.has_perms(('cableur',)):
+ if machine.user != request.user:
+ messages.error(request, "Vous ne pouvez pas éditer une machine d'un autre user que vous sans droit")
+ return redirect("/users/profil/" + str(request.user.id))
+ machine.delete()
+ messages.success(request, "La machine a été détruite")
+ return redirect("/users/profil/" + str(request.user.id))
+
@login_required
def new_interface(request, machineid):
try:
@@ -153,6 +168,21 @@ def new_interface(request, machineid):
return redirect("/machines/")
return form({'machineform': machine_form, 'interfaceform': interface_form}, 'machines/machine.html', request)
+@login_required
+def del_interface(request, interfaceid):
+ try:
+ interface = Interface.objects.get(pk=interfaceid)
+ except Interface.DoesNotExist:
+ messages.error(request, u"Interface inexistante" )
+ return redirect("/machines")
+ if not request.user.has_perms(('cableur',)):
+ if interface.machine.user != request.user:
+ messages.error(request, "Vous ne pouvez pas éditer une machine d'un autre user que vous sans droit")
+ return redirect("/users/profil/" + str(request.user.id))
+ interface.delete()
+ messages.success(request, "L'interface a été détruite")
+ return redirect("/users/profil/" + str(request.user.id))
+
@login_required
@permission_required('infra')
def add_machinetype(request):
@@ -236,8 +266,8 @@ def del_extension(request):
@login_required
@permission_required('cableur')
def index(request):
- interfaces_list = Interface.objects.order_by('pk')
- return render(request, 'machines/index.html', {'interfaces_list': interfaces_list})
+ machines_list = Machine.objects.order_by('pk')
+ return render(request, 'machines/index.html', {'machines_list': machines_list})
@login_required
@permission_required('cableur')
diff --git a/users/models.py b/users/models.py
index 34c0da70..e0647d15 100644
--- a/users/models.py
+++ b/users/models.py
@@ -10,7 +10,7 @@ from django.utils import timezone
from django.contrib.auth.models import AbstractBaseUser, BaseUserManager
from topologie.models import Room
-from cotisations.models import Cotisation, Facture
+from cotisations.models import Cotisation, Facture, Vente
def remove_user_room(room):
""" Déménage de force l'ancien locataire de la chambre """
@@ -154,7 +154,7 @@ class User(AbstractBaseUser):
return True
def end_adhesion(self):
- date_max = Cotisation.objects.all().filter(facture=Facture.objects.all().filter(user=self).exclude(valid=False)).aggregate(models.Max('date_end'))['date_end__max']
+ date_max = Cotisation.objects.all().filter(vente=Vente.objects.all().filter(facture=Facture.objects.all().filter(user=self).exclude(valid=False))).aggregate(models.Max('date_end'))['date_end__max']
return date_max
def is_adherent(self):
diff --git a/users/templates/users/profil.html b/users/templates/users/profil.html
index dd0b08d2..9e2d95df 100644
--- a/users/templates/users/profil.html
+++ b/users/templates/users/profil.html
@@ -81,8 +81,8 @@
Machines :
- {% if interfaces_list %}
- {% include "machines/aff_machines.html" with interfaces_list=interfaces_list %}
+ {% if machines_list %}
+ {% include "machines/aff_machines.html" with machines_list=machines_list %}
{% else %}
Aucune machine
{% endif %}
diff --git a/users/views.py b/users/views.py
index 8d0bfac5..4655ca60 100644
--- a/users/views.py
+++ b/users/views.py
@@ -304,9 +304,7 @@ def profil(request, userid):
if not request.user.has_perms(('cableur',)) and users != request.user:
messages.error(request, "Vous ne pouvez pas afficher un autre user que vous sans droit cableur")
return redirect("/users/profil/" + str(request.user.id))
- machines = Interface.objects.filter(
- machine=Machine.objects.filter(user__pseudo=users)
- )
+ machines = Machine.objects.filter(user__pseudo=users)
factures = Facture.objects.filter(user__pseudo=users)
bans = Ban.objects.filter(user__pseudo=users)
whitelists = Whitelist.objects.filter(user__pseudo=users)
@@ -316,7 +314,7 @@ def profil(request, userid):
'users/profil.html',
{
'user': users,
- 'interfaces_list': machines,
+ 'machines_list': machines,
'facture_list': factures,
'ban_list': bans,
'white_list': whitelists,