8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-12-26 08:53:46 +00:00

Refomre de l'affichage des machines partie1

This commit is contained in:
Gabriel Detraz 2016-07-18 05:30:35 +02:00
parent 0441ef0b9d
commit 9bb7539879
8 changed files with 65 additions and 22 deletions

View file

@ -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)

View file

@ -1,23 +1,36 @@
<table class="table table-striped">
<thead>
<tr>
<th>Nom dns</th>
<th>Proprietaire</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>Ipv4</th>
<th></th>
</tr>
</thead>
{% for interface in interfaces_list %}
<tr>
</thead>
{% for interface in machine.interface_set.all %}
<tr>
<td>{{ interface.dns }}</td>
<td>{{ interface.machine.user }}</td>
<td>{{ interface.machine.type }}</td>
<td>{{ interface.mac_address }}</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>
<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>
<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-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>
{% endfor %}
</table>

View file

@ -5,7 +5,7 @@
{% block content %}
<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 />

View file

@ -4,8 +4,10 @@ from . import views
urlpatterns = [
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'^del_interface/(?P<interfaceid>[0-9]+)$', views.del_interface, name='del-interface'),
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'^del_machinetype/$', views.del_machinetype, name='del-machinetype'),

View file

@ -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')

View file

@ -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):

View file

@ -81,8 +81,8 @@
</table>
<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>
{% 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 %}
<p>Aucune machine</p>
{% endif %}

View file

@ -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,