diff --git a/cotisations/views.py b/cotisations/views.py
index aa71d918..cce0f090 100644
--- a/cotisations/views.py
+++ b/cotisations/views.py
@@ -23,25 +23,10 @@ def form(ctx, template, request):
c.update(csrf(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):
""" 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)
- date_max = end_adhesion(user) or timezone.now()
+ date_max = user.end_adhesion() or timezone.now()
if date_max < timezone.now():
datemax = timezone.now()
cotisation.date_start=date_max
@@ -225,27 +210,23 @@ def del_banque(request):
@login_required
@permission_required('cableur')
def index_article(request):
- is_trez = request.user.has_perms(('trésorier',))
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
@permission_required('cableur')
def index_paiement(request):
- is_trez = request.user.has_perms(('trésorier',))
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
@permission_required('cableur')
def index_banque(request):
- is_trez = request.user.has_perms(('trésorier',))
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
@permission_required('cableur')
def index(request):
- is_cableur = request.user.has_perms(('cableur',))
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})
diff --git a/machines/models.py b/machines/models.py
index 8475b45a..c3a5e5bb 100644
--- a/machines/models.py
+++ b/machines/models.py
@@ -33,6 +33,12 @@ class Machine(models.Model):
name = models.CharField(max_length=255, help_text="Optionnel", blank=True, null=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):
return str(self.user) + ' - ' + str(self.id) + ' - ' + str(self.name)
diff --git a/machines/templates/machines/sidebar.html b/machines/templates/machines/sidebar.html
index a321147b..9647b75f 100644
--- a/machines/templates/machines/sidebar.html
+++ b/machines/templates/machines/sidebar.html
@@ -1,6 +1,8 @@
{% extends "base.html" %}
{% block sidebar %}
+ {% if is_cableur %}
Liste des types de machine
Liste des types des extensions
+ {% endif %}
{% endblock %}
diff --git a/machines/views.py b/machines/views.py
index 3b1501aa..c7685c95 100644
--- a/machines/views.py
+++ b/machines/views.py
@@ -215,13 +215,11 @@ def index(request):
@login_required
@permission_required('cableur')
def index_machinetype(request):
- is_infra = request.user.has_perms(('infra',))
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
@permission_required('cableur')
def index_extension(request):
- is_infra = request.user.has_perms(('infra',))
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})
diff --git a/re2o/settings.py b/re2o/settings.py
index 805b935c..bdc6eb21 100644
--- a/re2o/settings.py
+++ b/re2o/settings.py
@@ -85,6 +85,7 @@ TEMPLATES = [
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
+ 're2o.context_processors.context_user',
],
},
},
diff --git a/search/views.py b/search/views.py
index cbeadcba..22072e2e 100644
--- a/search/views.py
+++ b/search/views.py
@@ -13,8 +13,6 @@ from machines.models import Machine, Interface
from topologie.models import Port, Switch
from cotisations.models import Facture
from search.models import SearchForm, SearchFormPlus
-from users.views import has_access
-from cotisations.views import end_adhesion
def form(ctx, template, request):
c = ctx
@@ -53,21 +51,10 @@ def search_result(search, type, request):
switchlist = None
portlist = None
connexion = []
- is_cableur = request.user.has_perms(('cableur',))
- is_bofh = request.user.has_perms(('bofh',))
for i in aff:
if i == '0':
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)
if i == '1':
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)
if i == '6':
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
def search(request):
diff --git a/static/css/base.css b/static/css/base.css
index 7ca9b2b5..ed0b9eb9 100644
--- a/static/css/base.css
+++ b/static/css/base.css
@@ -1,17 +1,43 @@
-/* Remove the navbar's default margin-bottom and rounded borders */
+/* 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 */
.navbar {
margin-bottom: 0;
border-radius: 0;
}
/* 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 */
.sidenav {
padding-top: 20px;
background-color: #f1f1f1;
- height: 100%;
+ margin-bottom: -9999px;
+ padding-bottom: 9999px;
}
/* Set black background color, white text and some padding */
@@ -27,5 +53,5 @@ footer {
height: auto;
padding: 15px;
}
- .row.content {height:auto;}
+ .row.content {height:auto;}
}
diff --git a/templates/base.html b/templates/base.html
index ccb25f27..e482c550 100644
--- a/templates/base.html
+++ b/templates/base.html
@@ -28,11 +28,14 @@
-
ADS
+ {% if user.is_authenticated %}
+
{{ user.name }} {{ user.surname }}
+
Pseudo : {{ user.pseudo }}
+
Chambre : {{ user.room }}
+
Connexion : {% if user.actif == True %}Active{% else %}Désactivée{% endif %}
+
Fin d'adhésion : {% if user.end_adhesion != None %}{{ user.end_adhesion }}{% else %}Non adhérent{% endif %}
+
Voir mon profil
+ {% else %}
+
Vous n'êtes pas authentifié
+ {% endif %}
ADS
diff --git a/topologie/views.py b/topologie/views.py
index 1047e85b..0166cfe7 100644
--- a/topologie/views.py
+++ b/topologie/views.py
@@ -10,21 +10,19 @@ from users.views import form
@login_required
@permission_required('cableur')
def index(request):
- is_infra = request.user.has_perms(('infra',))
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
@permission_required('cableur')
def index_port(request, switch_id):
- is_infra = request.user.has_perms(('infra',))
try:
switch = Switch.objects.get(pk=switch_id)
except Switch.DoesNotExist:
messages.error(request, u"Switch inexistant")
return redirect("/topologie/")
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
@permission_required('infra')
diff --git a/users/models.py b/users/models.py
index 297f71d4..bb0bc799 100644
--- a/users/models.py
+++ b/users/models.py
@@ -1,12 +1,14 @@
from django.db import models
from django.forms import ModelForm, Form
from django import forms
+
import re
from django.utils import timezone
from django.contrib.auth.models import AbstractBaseUser, BaseUserManager
from topologie.models import Room
+from cotisations.models import Cotisation, Facture
def remove_user_room(room):
""" 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):
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):
# Simplest version again
return True
diff --git a/users/templates/users/aff_users.html b/users/templates/users/aff_users.html
index 07dd5bef..fb49a8b8 100644
--- a/users/templates/users/aff_users.html
+++ b/users/templates/users/aff_users.html
@@ -9,19 +9,19 @@
Profil |
- {% for donnee in users_list %}
+ {% for user in users_list %}
- {{ donnee.0.name }} |
- {{ donnee.0.surname }} |
- {{ donnee.0.pseudo }} |
- {{ donnee.2 }} |
- {% if donnee.1 == True %}
+ | {{ user.name }} |
+ {{ user.surname }} |
+ {{ user.pseudo }} |
+ {% if user.is_adherent %}{{ user.end_adhesion }}{% else %}Non adhérent{% endif %} |
+ {% if user.has_access == True %}
Active
{% else %}
Désactivée
{% endif %}
|
-
+ |
|
{% endfor %}
diff --git a/users/templates/users/profil.html b/users/templates/users/profil.html
index 5ff2731f..56035c35 100644
--- a/users/templates/users/profil.html
+++ b/users/templates/users/profil.html
@@ -38,21 +38,21 @@
Fin d'adhésion |
- {% if end_adhesion != None %}
- {{ end_adhesion }} |
+ {% if user.end_adhesion != None %}
+ {{ user.end_adhesion }} |
{% else %}
Non adhérent |
{% endif %}
Accès gracieux |
- {% if end_whitelist != None %}
- {{ end_whitelist }} |
+ {% if user.end_whitelist != None %}
+ {{ user.end_whitelist }} |
{% else %}
Aucun |
{% endif %}
Bannissement |
- {% if end_ban != None %}
- {{ end_ban }} |
+ {% if user.end_ban != None %}
+ {{ user.end_ban }} |
{% else %}
Non banni |
{% endif %}
@@ -67,7 +67,7 @@
Connexion |
- {% if actif == True %}
+ {% if user.actif == True %}
Active |
{% else %}
Désactivée |
diff --git a/users/templates/users/sidebar.html b/users/templates/users/sidebar.html
index 97fccf28..5eefa6b2 100644
--- a/users/templates/users/sidebar.html
+++ b/users/templates/users/sidebar.html
@@ -1,10 +1,14 @@
{% extends "base.html" %}
{% block sidebar %}
+ {% if is_cableur %}
Créer un adhérent
Liste des adhérents
Liste des bannissements
Liste des accès à titre gracieux
Liste des établissements
+ {% if is_bureau %}
Retirer un droit
+ {% endif %}
+ {% endif %}
{% endblock %}
diff --git a/users/urls.py b/users/urls.py
index af744278..58c910fb 100644
--- a/users/urls.py
+++ b/users/urls.py
@@ -20,6 +20,7 @@ urlpatterns = [
url(r'^index_ban/$', views.index_ban, name='index-ban'),
url(r'^index_white/$', views.index_white, name='index-white'),
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'),
]
diff --git a/users/views.py b/users/views.py
index 976c4f56..50fac1c0 100644
--- a/users/views.py
+++ b/users/views.py
@@ -16,7 +16,6 @@ from users.models import InfoForm, BaseInfoForm, StateForm, RightForm, SchoolFor
from cotisations.models import Facture
from machines.models import Machine, Interface
from users.forms import PassForm
-from cotisations.views import is_adherent, end_adhesion
from machines.views import unassign_ips, assign_ips
from re2o.login import hashNT
@@ -33,56 +32,6 @@ def unarchive(user):
assign_ips(user)
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):
c = ctx
c.update(csrf(request))
@@ -317,22 +266,13 @@ def del_school(request):
@permission_required('cableur')
def index(request):
users_list = User.objects.order_by('pk')
- connexion = []
- 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})
+ return render(request, 'users/index.html', {'users_list': users_list})
@login_required
@permission_required('cableur')
def index_ban(request):
- is_bofh = request.user.has_perms(('bofh',))
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
@permission_required('cableur')
@@ -350,6 +290,10 @@ def index_school(request):
school_list = School.objects.order_by('name')
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
def profil(request, userid):
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)
bans = Ban.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)
- is_bofh = request.user.has_perms(('bofh',))
- is_bureau = request.user.has_perms(('bureau',))
- is_cableur = request.user.has_perms(('cableur',))
return render(
request,
'users/profil.html',
@@ -385,14 +320,7 @@ def profil(request, userid):
'facture_list': factures,
'ban_list': bans,
'white_list': whitelists,
- 'end_ban': end_bans,
- 'end_whitelist': end_whitelists,
- 'end_adhesion': end_adhesion(users),
- 'actif':has_access(users),
'list_droits': list_droits,
- 'is_bofh': is_bofh,
- 'is_bureau': is_bureau,
- 'is_cableur': is_cableur,
}
)