mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-22 11:23:10 +00:00
Simplifie le code, déplace les tests dans models, affiche un encart user à droite
This commit is contained in:
parent
cc0e1cb3ab
commit
adefbd8af3
15 changed files with 137 additions and 143 deletions
|
@ -23,25 +23,10 @@ def form(ctx, template, request):
|
||||||
c.update(csrf(request))
|
c.update(csrf(request))
|
||||||
return render_to_response(template, c, context_instance=RequestContext(request))
|
return render_to_response(template, c, context_instance=RequestContext(request))
|
||||||
|
|
||||||
def end_adhesion(user):
|
|
||||||
""" Renvoie la date de fin d'adhésion d'un user, False sinon """
|
|
||||||
date_max = Cotisation.objects.all().filter(facture=Facture.objects.all().filter(user=user).exclude(valid=False)).aggregate(Max('date_end'))['date_end__max']
|
|
||||||
return date_max
|
|
||||||
|
|
||||||
def is_adherent(user):
|
|
||||||
""" Renvoie si un user est à jour de cotisation """
|
|
||||||
end = end_adhesion(user)
|
|
||||||
if not end:
|
|
||||||
return False
|
|
||||||
elif end < timezone.now():
|
|
||||||
return False
|
|
||||||
else:
|
|
||||||
return True
|
|
||||||
|
|
||||||
def create_cotis(facture, user, duration):
|
def create_cotis(facture, user, duration):
|
||||||
""" Update et crée l'objet cotisation associé à une facture, prend en argument l'user, la facture pour la quantitéi, et l'article pour la durée"""
|
""" Update et crée l'objet cotisation associé à une facture, prend en argument l'user, la facture pour la quantitéi, et l'article pour la durée"""
|
||||||
cotisation=Cotisation(facture=facture)
|
cotisation=Cotisation(facture=facture)
|
||||||
date_max = end_adhesion(user) or timezone.now()
|
date_max = user.end_adhesion() or timezone.now()
|
||||||
if date_max < timezone.now():
|
if date_max < timezone.now():
|
||||||
datemax = timezone.now()
|
datemax = timezone.now()
|
||||||
cotisation.date_start=date_max
|
cotisation.date_start=date_max
|
||||||
|
@ -225,27 +210,23 @@ def del_banque(request):
|
||||||
@login_required
|
@login_required
|
||||||
@permission_required('cableur')
|
@permission_required('cableur')
|
||||||
def index_article(request):
|
def index_article(request):
|
||||||
is_trez = request.user.has_perms(('trésorier',))
|
|
||||||
article_list = Article.objects.order_by('name')
|
article_list = Article.objects.order_by('name')
|
||||||
return render(request, 'cotisations/index_article.html', {'article_list':article_list, 'is_trez':is_trez})
|
return render(request, 'cotisations/index_article.html', {'article_list':article_list})
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@permission_required('cableur')
|
@permission_required('cableur')
|
||||||
def index_paiement(request):
|
def index_paiement(request):
|
||||||
is_trez = request.user.has_perms(('trésorier',))
|
|
||||||
paiement_list = Paiement.objects.order_by('moyen')
|
paiement_list = Paiement.objects.order_by('moyen')
|
||||||
return render(request, 'cotisations/index_paiement.html', {'paiement_list':paiement_list, 'is_trez':is_trez})
|
return render(request, 'cotisations/index_paiement.html', {'paiement_list':paiement_list})
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@permission_required('cableur')
|
@permission_required('cableur')
|
||||||
def index_banque(request):
|
def index_banque(request):
|
||||||
is_trez = request.user.has_perms(('trésorier',))
|
|
||||||
banque_list = Banque.objects.order_by('name')
|
banque_list = Banque.objects.order_by('name')
|
||||||
return render(request, 'cotisations/index_banque.html', {'banque_list':banque_list, 'is_trez':is_trez})
|
return render(request, 'cotisations/index_banque.html', {'banque_list':banque_list})
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@permission_required('cableur')
|
@permission_required('cableur')
|
||||||
def index(request):
|
def index(request):
|
||||||
is_cableur = request.user.has_perms(('cableur',))
|
|
||||||
facture_list = Facture.objects.order_by('date').reverse()
|
facture_list = Facture.objects.order_by('date').reverse()
|
||||||
return render(request, 'cotisations/index.html', {'facture_list': facture_list, 'is_cableur': is_cableur})
|
return render(request, 'cotisations/index.html', {'facture_list': facture_list})
|
||||||
|
|
|
@ -33,6 +33,12 @@ class Machine(models.Model):
|
||||||
name = models.CharField(max_length=255, help_text="Optionnel", blank=True, null=True)
|
name = models.CharField(max_length=255, help_text="Optionnel", blank=True, null=True)
|
||||||
active = models.BooleanField(default=True)
|
active = models.BooleanField(default=True)
|
||||||
|
|
||||||
|
def is_active(self):
|
||||||
|
""" Renvoie si une interface doit avoir accès ou non """
|
||||||
|
machine = self.machine
|
||||||
|
user = machine.user
|
||||||
|
return machine.active and user.has_access()
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return str(self.user) + ' - ' + str(self.id) + ' - ' + str(self.name)
|
return str(self.user) + ' - ' + str(self.id) + ' - ' + str(self.name)
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
|
|
||||||
{% block sidebar %}
|
{% block sidebar %}
|
||||||
|
{% if is_cableur %}
|
||||||
<p><a href="{% url "machines:index-machinetype" %}">Liste des types de machine</a></p>
|
<p><a href="{% url "machines:index-machinetype" %}">Liste des types de machine</a></p>
|
||||||
<p><a href="{% url "machines:index-extension" %}">Liste des types des extensions</a></p>
|
<p><a href="{% url "machines:index-extension" %}">Liste des types des extensions</a></p>
|
||||||
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -215,13 +215,11 @@ def index(request):
|
||||||
@login_required
|
@login_required
|
||||||
@permission_required('cableur')
|
@permission_required('cableur')
|
||||||
def index_machinetype(request):
|
def index_machinetype(request):
|
||||||
is_infra = request.user.has_perms(('infra',))
|
|
||||||
machinetype_list = MachineType.objects.order_by('type')
|
machinetype_list = MachineType.objects.order_by('type')
|
||||||
return render(request, 'machines/index_machinetype.html', {'machinetype_list':machinetype_list, 'is_infra':is_infra})
|
return render(request, 'machines/index_machinetype.html', {'machinetype_list':machinetype_list})
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@permission_required('cableur')
|
@permission_required('cableur')
|
||||||
def index_extension(request):
|
def index_extension(request):
|
||||||
is_infra = request.user.has_perms(('infra',))
|
|
||||||
extension_list = Extension.objects.order_by('name')
|
extension_list = Extension.objects.order_by('name')
|
||||||
return render(request, 'machines/index_extension.html', {'extension_list':extension_list, 'is_infra':is_infra})
|
return render(request, 'machines/index_extension.html', {'extension_list':extension_list})
|
||||||
|
|
|
@ -85,6 +85,7 @@ TEMPLATES = [
|
||||||
'django.template.context_processors.request',
|
'django.template.context_processors.request',
|
||||||
'django.contrib.auth.context_processors.auth',
|
'django.contrib.auth.context_processors.auth',
|
||||||
'django.contrib.messages.context_processors.messages',
|
'django.contrib.messages.context_processors.messages',
|
||||||
|
're2o.context_processors.context_user',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -13,8 +13,6 @@ from machines.models import Machine, Interface
|
||||||
from topologie.models import Port, Switch
|
from topologie.models import Port, Switch
|
||||||
from cotisations.models import Facture
|
from cotisations.models import Facture
|
||||||
from search.models import SearchForm, SearchFormPlus
|
from search.models import SearchForm, SearchFormPlus
|
||||||
from users.views import has_access
|
|
||||||
from cotisations.views import end_adhesion
|
|
||||||
|
|
||||||
def form(ctx, template, request):
|
def form(ctx, template, request):
|
||||||
c = ctx
|
c = ctx
|
||||||
|
@ -53,21 +51,10 @@ def search_result(search, type, request):
|
||||||
switchlist = None
|
switchlist = None
|
||||||
portlist = None
|
portlist = None
|
||||||
connexion = []
|
connexion = []
|
||||||
is_cableur = request.user.has_perms(('cableur',))
|
|
||||||
is_bofh = request.user.has_perms(('bofh',))
|
|
||||||
|
|
||||||
for i in aff:
|
for i in aff:
|
||||||
if i == '0':
|
if i == '0':
|
||||||
users = User.objects.filter((Q(pseudo__icontains = search) | Q(name__icontains = search) | Q(surname__icontains = search)) & query)
|
users = User.objects.filter((Q(pseudo__icontains = search) | Q(name__icontains = search) | Q(surname__icontains = search)) & query)
|
||||||
connexion = []
|
|
||||||
for user in users:
|
|
||||||
end=end_adhesion(user)
|
|
||||||
access=has_access(user)
|
|
||||||
if(len(co)==0 or (len(co)==1 and bool(co[0])==access) or (len(co)==2 and (bool(co[0])==access or bool(co[1])==access))):
|
|
||||||
if(end!=None):
|
|
||||||
connexion.append([user, access, end])
|
|
||||||
else:
|
|
||||||
connexion.append([user, access, "Non adhérent"])
|
|
||||||
query = Q(user__pseudo__icontains = search) | Q(user__name__icontains = search) | Q(user__surname__icontains = search)
|
query = Q(user__pseudo__icontains = search) | Q(user__name__icontains = search) | Q(user__surname__icontains = search)
|
||||||
if i == '1':
|
if i == '1':
|
||||||
machines = Interface.objects.filter(machine=Machine.objects.filter(query)) | Interface.objects.filter(Q(dns__icontains = search))
|
machines = Interface.objects.filter(machine=Machine.objects.filter(query)) | Interface.objects.filter(Q(dns__icontains = search))
|
||||||
|
@ -81,7 +68,7 @@ def search_result(search, type, request):
|
||||||
portlist = Port.objects.filter(details__icontains = search)
|
portlist = Port.objects.filter(details__icontains = search)
|
||||||
if i == '6':
|
if i == '6':
|
||||||
switchlist = Switch.objects.filter(details__icontains = search)
|
switchlist = Switch.objects.filter(details__icontains = search)
|
||||||
return {'users_list': connexion, 'interfaces_list' : machines, 'facture_list' : factures, 'ban_list' : bans, 'white_list': whitelists, 'port_list':portlist, 'switch_list':switchlist, 'is_cableur':is_cableur, 'is_bofh':is_bofh}
|
return {'users_list': users, 'interfaces_list' : machines, 'facture_list' : factures, 'ban_list' : bans, 'white_list': whitelists, 'port_list':portlist, 'switch_list':switchlist}
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def search(request):
|
def search(request):
|
||||||
|
|
|
@ -1,3 +1,25 @@
|
||||||
|
/* Sticky footer hacks */
|
||||||
|
html, body {
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
#wrap {
|
||||||
|
min-height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
#main {
|
||||||
|
overflow:auto;
|
||||||
|
padding-bottom:60px; /* this needs to be bigger than footer height*/
|
||||||
|
}
|
||||||
|
|
||||||
|
footer {
|
||||||
|
position: relative;
|
||||||
|
margin-top: -50px; /* negative value of footer height */
|
||||||
|
height: 50px;
|
||||||
|
clear:both;
|
||||||
|
padding-top:20px;
|
||||||
|
}
|
||||||
|
|
||||||
/* Remove the navbar's default margin-bottom and rounded borders */
|
/* Remove the navbar's default margin-bottom and rounded borders */
|
||||||
.navbar {
|
.navbar {
|
||||||
margin-bottom: 0;
|
margin-bottom: 0;
|
||||||
|
@ -5,13 +27,17 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set height of the grid so .sidenav can be 100% (adjust as needed) */
|
/* Set height of the grid so .sidenav can be 100% (adjust as needed) */
|
||||||
.row.content {height: 450px}
|
.row.content {
|
||||||
|
height: 100%;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
/* Set gray background color and 100% height */
|
/* Set gray background color and 100% height */
|
||||||
.sidenav {
|
.sidenav {
|
||||||
padding-top: 20px;
|
padding-top: 20px;
|
||||||
background-color: #f1f1f1;
|
background-color: #f1f1f1;
|
||||||
height: 100%;
|
margin-bottom: -9999px;
|
||||||
|
padding-bottom: 9999px;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set black background color, white text and some padding */
|
/* Set black background color, white text and some padding */
|
||||||
|
|
|
@ -28,11 +28,14 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="collapse navbar-collapse" id="myNavbar">
|
<div class="collapse navbar-collapse" id="myNavbar">
|
||||||
<ul class="nav navbar-nav">
|
<ul class="nav navbar-nav">
|
||||||
|
<li><a href="{% url "users:mon-profil" %}">Mon profil</a></li>
|
||||||
|
{% if is_cableur %}
|
||||||
<li><a href="{% url "users:index" %}">Adhérents</a></li>
|
<li><a href="{% url "users:index" %}">Adhérents</a></li>
|
||||||
<li><a href="{% url "machines:index" %}">Machines</a></li>
|
<li><a href="{% url "machines:index" %}">Machines</a></li>
|
||||||
<li><a href="{% url "cotisations:index" %}">Cotisations</a></li>
|
<li><a href="{% url "cotisations:index" %}">Cotisations</a></li>
|
||||||
<li><a href="{% url "topologie:index" %}">Topologie</a></li>
|
<li><a href="{% url "topologie:index" %}">Topologie</a></li>
|
||||||
<li><a href="#">Statistiques</a></li>
|
<li><a href="#">Statistiques</a></li>
|
||||||
|
{% endif %}
|
||||||
</ul>
|
</ul>
|
||||||
<div class="col-sm-3 col-md-3 navbar-right">
|
<div class="col-sm-3 col-md-3 navbar-right">
|
||||||
<form action="{% url "search:search"%}" method="POST" class="navbar-form" role="search">
|
<form action="{% url "search:search"%}" method="POST" class="navbar-form" role="search">
|
||||||
|
@ -82,7 +85,16 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-2 sidenav">
|
<div class="col-sm-2 sidenav">
|
||||||
<div class="well">
|
<div class="well">
|
||||||
<p>ADS</p>
|
{% if user.is_authenticated %}
|
||||||
|
<li>{{ user.name }} {{ user.surname }}</li>
|
||||||
|
<li>Pseudo : {{ user.pseudo }}</li>
|
||||||
|
<li>Chambre : {{ user.room }}</li>
|
||||||
|
<li>Connexion : {% if user.actif == True %}<font color="green">Active</font>{% else %}<font color="red">Désactivée</font>{% endif %}</li>
|
||||||
|
<li>Fin d'adhésion : {% if user.end_adhesion != None %}<font color="green">{{ user.end_adhesion }}</font>{% else %}<font color="red">Non adhérent</font>{% endif %}</li>
|
||||||
|
<p><a href="{% url "users:mon-profil" %}">Voir mon profil</a></p>
|
||||||
|
{% else %}
|
||||||
|
<p>Vous n'êtes pas authentifié</p>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
<div class="well">
|
<div class="well">
|
||||||
<p>ADS</p>
|
<p>ADS</p>
|
||||||
|
|
|
@ -10,21 +10,19 @@ from users.views import form
|
||||||
@login_required
|
@login_required
|
||||||
@permission_required('cableur')
|
@permission_required('cableur')
|
||||||
def index(request):
|
def index(request):
|
||||||
is_infra = request.user.has_perms(('infra',))
|
|
||||||
switch_list = Switch.objects.order_by('building', 'number')
|
switch_list = Switch.objects.order_by('building', 'number')
|
||||||
return render(request, 'topologie/index.html', {'switch_list': switch_list, 'is_infra':is_infra})
|
return render(request, 'topologie/index.html', {'switch_list': switch_list})
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@permission_required('cableur')
|
@permission_required('cableur')
|
||||||
def index_port(request, switch_id):
|
def index_port(request, switch_id):
|
||||||
is_infra = request.user.has_perms(('infra',))
|
|
||||||
try:
|
try:
|
||||||
switch = Switch.objects.get(pk=switch_id)
|
switch = Switch.objects.get(pk=switch_id)
|
||||||
except Switch.DoesNotExist:
|
except Switch.DoesNotExist:
|
||||||
messages.error(request, u"Switch inexistant")
|
messages.error(request, u"Switch inexistant")
|
||||||
return redirect("/topologie/")
|
return redirect("/topologie/")
|
||||||
port_list = Port.objects.filter(switch = switch).order_by('port')
|
port_list = Port.objects.filter(switch = switch).order_by('port')
|
||||||
return render(request, 'topologie/index_p.html', {'port_list':port_list, 'id_switch':switch_id, 'nom_switch':switch, 'is_infra':is_infra})
|
return render(request, 'topologie/index_p.html', {'port_list':port_list, 'id_switch':switch_id, 'nom_switch':switch})
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@permission_required('infra')
|
@permission_required('infra')
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.forms import ModelForm, Form
|
from django.forms import ModelForm, Form
|
||||||
from django import forms
|
from django import forms
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from django.utils import timezone
|
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
|
||||||
|
|
||||||
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 """
|
||||||
|
@ -143,6 +145,54 @@ class User(AbstractBaseUser):
|
||||||
def has_perm(self, perm, obj=None):
|
def has_perm(self, perm, obj=None):
|
||||||
return True
|
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']
|
||||||
|
return date_max
|
||||||
|
|
||||||
|
def is_adherent(self):
|
||||||
|
end = self.end_adhesion()
|
||||||
|
if not end:
|
||||||
|
return False
|
||||||
|
elif end < timezone.now():
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return True
|
||||||
|
|
||||||
|
def end_ban(self):
|
||||||
|
""" Renvoie la date de fin de ban d'un user, False sinon """
|
||||||
|
date_max = Ban.objects.all().filter(user=self).aggregate(models.Max('date_end'))['date_end__max']
|
||||||
|
return date_max
|
||||||
|
|
||||||
|
def end_whitelist(self):
|
||||||
|
""" Renvoie la date de fin de ban d'un user, False sinon """
|
||||||
|
date_max = Whitelist.objects.all().filter(user=self).aggregate(models.Max('date_end'))['date_end__max']
|
||||||
|
return date_max
|
||||||
|
|
||||||
|
def is_ban(self):
|
||||||
|
""" Renvoie si un user est banni ou non """
|
||||||
|
end = self.end_ban()
|
||||||
|
if not end:
|
||||||
|
return False
|
||||||
|
elif end < timezone.now():
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return True
|
||||||
|
|
||||||
|
def is_whitelisted(self):
|
||||||
|
""" Renvoie si un user est whitelisté ou non """
|
||||||
|
end = self.end_whitelist()
|
||||||
|
if not end:
|
||||||
|
return False
|
||||||
|
elif end < timezone.now():
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return True
|
||||||
|
|
||||||
|
def has_access(self):
|
||||||
|
""" Renvoie si un utilisateur a accès à internet """
|
||||||
|
return self.state == User.STATE_ACTIVE \
|
||||||
|
and not self.is_ban() and (self.is_adherent() or self.is_whitelisted())
|
||||||
|
|
||||||
def has_module_perms(self, app_label):
|
def has_module_perms(self, app_label):
|
||||||
# Simplest version again
|
# Simplest version again
|
||||||
return True
|
return True
|
||||||
|
|
|
@ -9,19 +9,19 @@
|
||||||
<th>Profil</th>
|
<th>Profil</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
{% for donnee in users_list %}
|
{% for user in users_list %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ donnee.0.name }}</td>
|
<td>{{ user.name }}</td>
|
||||||
<td>{{ donnee.0.surname }}</td>
|
<td>{{ user.surname }}</td>
|
||||||
<td>{{ donnee.0.pseudo }}</td>
|
<td>{{ user.pseudo }}</td>
|
||||||
<td>{{ donnee.2 }}</td>
|
<td>{% if user.is_adherent %}{{ user.end_adhesion }}{% else %}Non adhérent{% endif %}</td>
|
||||||
<td>{% if donnee.1 == True %}
|
<td>{% if user.has_access == True %}
|
||||||
<font color="green">Active</font>
|
<font color="green">Active</font>
|
||||||
{% else %}
|
{% else %}
|
||||||
<font color="red">Désactivée</font>
|
<font color="red">Désactivée</font>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
<td><a href="{% url "users:profil" donnee.0.id%}" class="btn btn-primary btn-sm" role="button"><i class="glyphicon glyphicon-user"></i></a>
|
<td><a href="{% url "users:profil" user.id%}" class="btn btn-primary btn-sm" role="button"><i class="glyphicon glyphicon-user"></i></a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
|
@ -38,21 +38,21 @@
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Fin d'adhésion</th>
|
<th>Fin d'adhésion</th>
|
||||||
{% if end_adhesion != None %}
|
{% if user.end_adhesion != None %}
|
||||||
<td><font color="green">{{ end_adhesion }}</font></td>
|
<td><font color="green">{{ user.end_adhesion }}</font></td>
|
||||||
{% else %}
|
{% else %}
|
||||||
<td><font color="red">Non adhérent</font></td>
|
<td><font color="red">Non adhérent</font></td>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<th>Accès gracieux</th>
|
<th>Accès gracieux</th>
|
||||||
{% if end_whitelist != None %}
|
{% if user.end_whitelist != None %}
|
||||||
<td><font color="green">{{ end_whitelist }}</font></td>
|
<td><font color="green">{{ user.end_whitelist }}</font></td>
|
||||||
{% else %}
|
{% else %}
|
||||||
<td><font color="orange">Aucun</font></td>
|
<td><font color="orange">Aucun</font></td>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<tr>
|
<tr>
|
||||||
<th>Bannissement</th>
|
<th>Bannissement</th>
|
||||||
{% if end_ban != None %}
|
{% if user.end_ban != None %}
|
||||||
<td><font color="red">{{ end_ban }}</font></td>
|
<td><font color="red">{{ user.end_ban }}</font></td>
|
||||||
{% else %}
|
{% else %}
|
||||||
<td><font color="green">Non banni</font></td>
|
<td><font color="green">Non banni</font></td>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -67,7 +67,7 @@
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Connexion</th>
|
<th>Connexion</th>
|
||||||
{% if actif == True %}
|
{% if user.actif == True %}
|
||||||
<td><font color="green">Active</font></td>
|
<td><font color="green">Active</font></td>
|
||||||
{% else %}
|
{% else %}
|
||||||
<td><font color="red">Désactivée</font></td>
|
<td><font color="red">Désactivée</font></td>
|
||||||
|
|
|
@ -1,10 +1,14 @@
|
||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
|
|
||||||
{% block sidebar %}
|
{% block sidebar %}
|
||||||
|
{% if is_cableur %}
|
||||||
<p><a href="{% url "users:new-user" %}">Créer un adhérent</a></p>
|
<p><a href="{% url "users:new-user" %}">Créer un adhérent</a></p>
|
||||||
<p><a href="{% url "users:index" %}">Liste des adhérents</a></p>
|
<p><a href="{% url "users:index" %}">Liste des adhérents</a></p>
|
||||||
<p><a href="{% url "users:index-ban" %}">Liste des bannissements</a></p>
|
<p><a href="{% url "users:index-ban" %}">Liste des bannissements</a></p>
|
||||||
<p><a href="{% url "users:index-white" %}">Liste des accès à titre gracieux</a></p>
|
<p><a href="{% url "users:index-white" %}">Liste des accès à titre gracieux</a></p>
|
||||||
<p><a href="{% url "users:index-school" %}">Liste des établissements</a></p>
|
<p><a href="{% url "users:index-school" %}">Liste des établissements</a></p>
|
||||||
|
{% if is_bureau %}
|
||||||
<p><a href="{% url "users:del-right" %}">Retirer un droit</a></p>
|
<p><a href="{% url "users:del-right" %}">Retirer un droit</a></p>
|
||||||
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -20,6 +20,7 @@ urlpatterns = [
|
||||||
url(r'^index_ban/$', views.index_ban, name='index-ban'),
|
url(r'^index_ban/$', views.index_ban, name='index-ban'),
|
||||||
url(r'^index_white/$', views.index_white, name='index-white'),
|
url(r'^index_white/$', views.index_white, name='index-white'),
|
||||||
url(r'^index_school/$', views.index_school, name='index-school'),
|
url(r'^index_school/$', views.index_school, name='index-school'),
|
||||||
|
url(r'^mon_profil/$', views.mon_profil, name='mon-profil'),
|
||||||
url(r'^$', views.index, name='index'),
|
url(r'^$', views.index, name='index'),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,6 @@ from users.models import InfoForm, BaseInfoForm, StateForm, RightForm, SchoolFor
|
||||||
from cotisations.models import Facture
|
from cotisations.models import Facture
|
||||||
from machines.models import Machine, Interface
|
from machines.models import Machine, Interface
|
||||||
from users.forms import PassForm
|
from users.forms import PassForm
|
||||||
from cotisations.views import is_adherent, end_adhesion
|
|
||||||
from machines.views import unassign_ips, assign_ips
|
from machines.views import unassign_ips, assign_ips
|
||||||
|
|
||||||
from re2o.login import hashNT
|
from re2o.login import hashNT
|
||||||
|
@ -33,56 +32,6 @@ def unarchive(user):
|
||||||
assign_ips(user)
|
assign_ips(user)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
def end_ban(user):
|
|
||||||
""" Renvoie la date de fin de ban d'un user, False sinon """
|
|
||||||
date_max = Ban.objects.all().filter(
|
|
||||||
user=user).aggregate(Max('date_end'))['date_end__max']
|
|
||||||
return date_max
|
|
||||||
|
|
||||||
|
|
||||||
def end_whitelist(user):
|
|
||||||
""" Renvoie la date de fin de ban d'un user, False sinon """
|
|
||||||
date_max = Whitelist.objects.all().filter(
|
|
||||||
user=user).aggregate(Max('date_end'))['date_end__max']
|
|
||||||
return date_max
|
|
||||||
|
|
||||||
|
|
||||||
def is_ban(user):
|
|
||||||
""" Renvoie si un user est banni ou non """
|
|
||||||
end = end_ban(user)
|
|
||||||
if not end:
|
|
||||||
return False
|
|
||||||
elif end < timezone.now():
|
|
||||||
return False
|
|
||||||
else:
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
def is_whitelisted(user):
|
|
||||||
""" Renvoie si un user est whitelisté ou non """
|
|
||||||
end = end_whitelist(user)
|
|
||||||
if not end:
|
|
||||||
return False
|
|
||||||
elif end < timezone.now():
|
|
||||||
return False
|
|
||||||
else:
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
def has_access(user):
|
|
||||||
""" Renvoie si un utilisateur a accès à internet """
|
|
||||||
return user.state == User.STATE_ACTIVE \
|
|
||||||
and not is_ban(user) and (is_adherent(user) or is_whitelisted(user))
|
|
||||||
|
|
||||||
|
|
||||||
def is_active(interface):
|
|
||||||
""" Renvoie si une interface doit avoir accès ou non """
|
|
||||||
machine = interface.machine
|
|
||||||
user = machine.user
|
|
||||||
return machine.active and has_access(user)
|
|
||||||
|
|
||||||
|
|
||||||
def form(ctx, template, request):
|
def form(ctx, template, request):
|
||||||
c = ctx
|
c = ctx
|
||||||
c.update(csrf(request))
|
c.update(csrf(request))
|
||||||
|
@ -317,22 +266,13 @@ def del_school(request):
|
||||||
@permission_required('cableur')
|
@permission_required('cableur')
|
||||||
def index(request):
|
def index(request):
|
||||||
users_list = User.objects.order_by('pk')
|
users_list = User.objects.order_by('pk')
|
||||||
connexion = []
|
return render(request, 'users/index.html', {'users_list': users_list})
|
||||||
for user in users_list:
|
|
||||||
end = end_adhesion(user)
|
|
||||||
access = has_access(user)
|
|
||||||
if(end is not None):
|
|
||||||
connexion.append([user, access, end])
|
|
||||||
else:
|
|
||||||
connexion.append([user, access, "Non adhérent"])
|
|
||||||
return render(request, 'users/index.html', {'users_list': connexion})
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@permission_required('cableur')
|
@permission_required('cableur')
|
||||||
def index_ban(request):
|
def index_ban(request):
|
||||||
is_bofh = request.user.has_perms(('bofh',))
|
|
||||||
ban_list = Ban.objects.order_by('date_start')
|
ban_list = Ban.objects.order_by('date_start')
|
||||||
return render(request, 'users/index_ban.html', {'ban_list': ban_list, 'is_bofh':is_bofh})
|
return render(request, 'users/index_ban.html', {'ban_list': ban_list})
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@permission_required('cableur')
|
@permission_required('cableur')
|
||||||
|
@ -350,6 +290,10 @@ def index_school(request):
|
||||||
school_list = School.objects.order_by('name')
|
school_list = School.objects.order_by('name')
|
||||||
return render(request, 'users/index_schools.html', {'school_list':school_list})
|
return render(request, 'users/index_schools.html', {'school_list':school_list})
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
def mon_profil(request):
|
||||||
|
return redirect("/users/profil/" + str(request.user.id))
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def profil(request, userid):
|
def profil(request, userid):
|
||||||
if not request.user.has_perms(('cableur',)) and str(userid)!=str(request.user.id):
|
if not request.user.has_perms(('cableur',)) and str(userid)!=str(request.user.id):
|
||||||
|
@ -366,16 +310,7 @@ def profil(request, userid):
|
||||||
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)
|
||||||
end_bans = None
|
|
||||||
end_whitelists = None
|
|
||||||
if(is_ban(users)):
|
|
||||||
end_bans = end_ban(users)
|
|
||||||
if(is_whitelisted(users)):
|
|
||||||
end_whitelists = end_whitelist(users)
|
|
||||||
list_droits = Right.objects.filter(user=users)
|
list_droits = Right.objects.filter(user=users)
|
||||||
is_bofh = request.user.has_perms(('bofh',))
|
|
||||||
is_bureau = request.user.has_perms(('bureau',))
|
|
||||||
is_cableur = request.user.has_perms(('cableur',))
|
|
||||||
return render(
|
return render(
|
||||||
request,
|
request,
|
||||||
'users/profil.html',
|
'users/profil.html',
|
||||||
|
@ -385,14 +320,7 @@ def profil(request, userid):
|
||||||
'facture_list': factures,
|
'facture_list': factures,
|
||||||
'ban_list': bans,
|
'ban_list': bans,
|
||||||
'white_list': whitelists,
|
'white_list': whitelists,
|
||||||
'end_ban': end_bans,
|
|
||||||
'end_whitelist': end_whitelists,
|
|
||||||
'end_adhesion': end_adhesion(users),
|
|
||||||
'actif':has_access(users),
|
|
||||||
'list_droits': list_droits,
|
'list_droits': list_droits,
|
||||||
'is_bofh': is_bofh,
|
|
||||||
'is_bureau': is_bureau,
|
|
||||||
'is_cableur': is_cableur,
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue