mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-05 01:16:27 +00:00
Refomre de l'affichage des machines partie1
This commit is contained in:
parent
a4244070b1
commit
2ad16def13
8 changed files with 65 additions and 22 deletions
|
@ -34,7 +34,7 @@ class Interface(models.Model):
|
||||||
ipv4 = models.OneToOneField('IpList', on_delete=models.PROTECT, blank=True, null=True)
|
ipv4 = models.OneToOneField('IpList', on_delete=models.PROTECT, blank=True, null=True)
|
||||||
#ipv6 = models.GenericIPAddressField(protocol='IPv6', null=True)
|
#ipv6 = models.GenericIPAddressField(protocol='IPv6', null=True)
|
||||||
mac_address = MACAddressField(integer=False, unique=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)
|
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)
|
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)
|
||||||
|
|
||||||
|
|
|
@ -1,23 +1,36 @@
|
||||||
<table class="table table-striped">
|
<table class="table table-striped">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Nom dns</th>
|
|
||||||
<th>Proprietaire</th>
|
<th>Proprietaire</th>
|
||||||
<th>Type</th>
|
<th>Type</th>
|
||||||
|
<th>Interfaces</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
{% for machine in machines_list %}
|
||||||
|
<tr>
|
||||||
|
<td>{{ machine.user }}</td>
|
||||||
|
<td>{{ machine.type }}
|
||||||
|
<p><a class="btn btn-primary btn-sm" role="button" href="{% url 'machines:new-interface' machine.id %}"><i class="glyphicon glyphicon-plus"></i> Ajouter une interface</p></a>
|
||||||
|
<p><a class="btn btn-danger btn-sm" role="button" href="{% url 'machines:del-machine' machine.id %}"><i class="glyphicon glyphicon-trash"></i> Supprimer la machine</a></p></td>
|
||||||
|
<td><table class="table table-striped">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Nom dns</th>
|
||||||
<th>Mac</th>
|
<th>Mac</th>
|
||||||
<th>Ipv4</th>
|
<th>Ipv4</th>
|
||||||
<th></th>
|
<th></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
{% for interface in interfaces_list %}
|
{% for interface in machine.interface_set.all %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ interface.dns }}</td>
|
<td>{{ interface.dns }}</td>
|
||||||
<td>{{ interface.machine.user }}</td>
|
|
||||||
<td>{{ interface.machine.type }}</td>
|
|
||||||
<td>{{ interface.mac_address }}</td>
|
<td>{{ interface.mac_address }}</td>
|
||||||
<td>{{ interface.ipv4 }}</td>
|
<td>{{ interface.ipv4 }}</td>
|
||||||
<td><a class="btn btn-primary btn-sm" role="button" href="{% url 'machines:edit-machine' interface.id %}"><i class="glyphicon glyphicon-hdd"></i> Editer</a>
|
<td><a class="btn btn-primary btn-sm" role="button" href="{% url 'machines:edit-interface' interface.id %}"><i class="glyphicon glyphicon-hdd"></i> Editer</a>
|
||||||
<a class="btn btn-primary btn-sm" role="button" href="{% url 'machines:new-interface' interface.machine.id %}"><i class="glyphicon glyphicon-plus"></i> Ajouter une interface</a></td>
|
<a class="btn btn-danger btn-sm" role="button" href="{% url 'machines:del-interface' interface.id %}"><i class="glyphicon glyphicon-trash"></i> Supprimer</a></td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</table>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h2>Machines</h2>
|
<h2>Machines</h2>
|
||||||
{% include "machines/aff_machines.html" with interfaces_list=interfaces_list %}
|
{% include "machines/aff_machines.html" with machines_list=machines_list %}
|
||||||
<br />
|
<br />
|
||||||
<br />
|
<br />
|
||||||
<br />
|
<br />
|
||||||
|
|
|
@ -4,8 +4,10 @@ from . import views
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^new_machine/(?P<userid>[0-9]+)$', views.new_machine, name='new-machine'),
|
url(r'^new_machine/(?P<userid>[0-9]+)$', views.new_machine, name='new-machine'),
|
||||||
url(r'^edit_machine/(?P<interfaceid>[0-9]+)$', views.edit_machine, name='edit-machine'),
|
url(r'^edit_interface/(?P<interfaceid>[0-9]+)$', views.edit_interface, name='edit-interface'),
|
||||||
|
url(r'^del_machine/(?P<machineid>[0-9]+)$', views.del_machine, name='del-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'^del_interface/(?P<interfaceid>[0-9]+)$', views.del_interface, name='del-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'^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'),
|
||||||
|
|
|
@ -99,7 +99,7 @@ def new_machine(request, userid):
|
||||||
return form({'machineform': machine, 'interfaceform': interface}, 'machines/machine.html', request)
|
return form({'machineform': machine, 'interfaceform': interface}, 'machines/machine.html', request)
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def edit_machine(request, interfaceid):
|
def edit_interface(request, interfaceid):
|
||||||
try:
|
try:
|
||||||
interface = Interface.objects.get(pk=interfaceid)
|
interface = Interface.objects.get(pk=interfaceid)
|
||||||
except Interface.DoesNotExist:
|
except Interface.DoesNotExist:
|
||||||
|
@ -124,6 +124,21 @@ def edit_machine(request, interfaceid):
|
||||||
return redirect("/users/profil/" + str(interface.machine.user.id))
|
return redirect("/users/profil/" + str(interface.machine.user.id))
|
||||||
return form({'machineform': machine_form, 'interfaceform': interface_form}, 'machines/machine.html', request)
|
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
|
@login_required
|
||||||
def new_interface(request, machineid):
|
def new_interface(request, machineid):
|
||||||
try:
|
try:
|
||||||
|
@ -153,6 +168,21 @@ def new_interface(request, machineid):
|
||||||
return redirect("/machines/")
|
return redirect("/machines/")
|
||||||
return form({'machineform': machine_form, 'interfaceform': interface_form}, 'machines/machine.html', request)
|
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
|
@login_required
|
||||||
@permission_required('infra')
|
@permission_required('infra')
|
||||||
def add_machinetype(request):
|
def add_machinetype(request):
|
||||||
|
@ -236,8 +266,8 @@ def del_extension(request):
|
||||||
@login_required
|
@login_required
|
||||||
@permission_required('cableur')
|
@permission_required('cableur')
|
||||||
def index(request):
|
def index(request):
|
||||||
interfaces_list = Interface.objects.order_by('pk')
|
machines_list = Machine.objects.order_by('pk')
|
||||||
return render(request, 'machines/index.html', {'interfaces_list': interfaces_list})
|
return render(request, 'machines/index.html', {'machines_list': machines_list})
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@permission_required('cableur')
|
@permission_required('cableur')
|
||||||
|
|
|
@ -10,7 +10,7 @@ from django.utils import timezone
|
||||||
from django.contrib.auth.models import AbstractBaseUser, BaseUserManager
|
from django.contrib.auth.models import AbstractBaseUser, BaseUserManager
|
||||||
|
|
||||||
from topologie.models import Room
|
from topologie.models import Room
|
||||||
from cotisations.models import Cotisation, Facture
|
from cotisations.models import Cotisation, Facture, Vente
|
||||||
|
|
||||||
def remove_user_room(room):
|
def remove_user_room(room):
|
||||||
""" Déménage de force l'ancien locataire de la chambre """
|
""" Déménage de force l'ancien locataire de la chambre """
|
||||||
|
@ -154,7 +154,7 @@ class User(AbstractBaseUser):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def end_adhesion(self):
|
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
|
return date_max
|
||||||
|
|
||||||
def is_adherent(self):
|
def is_adherent(self):
|
||||||
|
|
|
@ -81,8 +81,8 @@
|
||||||
</table>
|
</table>
|
||||||
<h2>Machines :</h2>
|
<h2>Machines :</h2>
|
||||||
<h4><a class="btn btn-primary btn-sm" role="button" href="{% url 'machines:new-machine' user.id %}"><i class="glyphicon glyphicon-phone"></i> Ajouter une machine</a></h4>
|
<h4><a class="btn btn-primary btn-sm" role="button" href="{% url 'machines:new-machine' user.id %}"><i class="glyphicon glyphicon-phone"></i> Ajouter une machine</a></h4>
|
||||||
{% if interfaces_list %}
|
{% if machines_list %}
|
||||||
{% include "machines/aff_machines.html" with interfaces_list=interfaces_list %}
|
{% include "machines/aff_machines.html" with machines_list=machines_list %}
|
||||||
{% else %}
|
{% else %}
|
||||||
<p>Aucune machine</p>
|
<p>Aucune machine</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
@ -304,9 +304,7 @@ def profil(request, userid):
|
||||||
if not request.user.has_perms(('cableur',)) and users != request.user:
|
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")
|
messages.error(request, "Vous ne pouvez pas afficher un autre user que vous sans droit cableur")
|
||||||
return redirect("/users/profil/" + str(request.user.id))
|
return redirect("/users/profil/" + str(request.user.id))
|
||||||
machines = Interface.objects.filter(
|
machines = Machine.objects.filter(user__pseudo=users)
|
||||||
machine=Machine.objects.filter(user__pseudo=users)
|
|
||||||
)
|
|
||||||
factures = Facture.objects.filter(user__pseudo=users)
|
factures = Facture.objects.filter(user__pseudo=users)
|
||||||
bans = Ban.objects.filter(user__pseudo=users)
|
bans = Ban.objects.filter(user__pseudo=users)
|
||||||
whitelists = Whitelist.objects.filter(user__pseudo=users)
|
whitelists = Whitelist.objects.filter(user__pseudo=users)
|
||||||
|
@ -316,7 +314,7 @@ def profil(request, userid):
|
||||||
'users/profil.html',
|
'users/profil.html',
|
||||||
{
|
{
|
||||||
'user': users,
|
'user': users,
|
||||||
'interfaces_list': machines,
|
'machines_list': machines,
|
||||||
'facture_list': factures,
|
'facture_list': factures,
|
||||||
'ban_list': bans,
|
'ban_list': bans,
|
||||||
'white_list': whitelists,
|
'white_list': whitelists,
|
||||||
|
|
Loading…
Reference in a new issue