From ed9ff021ca545169e36523240a02b11c1e5c99ac Mon Sep 17 00:00:00 2001 From: root Date: Sun, 10 Jul 2016 04:02:48 +0200 Subject: [PATCH] =?UTF-8?q?Simplifie=20le=20code,=20d=C3=A9place=20les=20t?= =?UTF-8?q?ests=20dans=20models,=20affiche=20un=20encart=20user=20=C3=A0?= =?UTF-8?q?=20droite?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cotisations/views.py | 29 ++------ machines/models.py | 6 ++ machines/templates/machines/sidebar.html | 2 + machines/views.py | 6 +- re2o/settings.py | 1 + search/views.py | 15 +---- static/css/base.css | 34 ++++++++-- templates/base.html | 14 +++- topologie/views.py | 6 +- users/models.py | 50 ++++++++++++++ users/templates/users/aff_users.html | 14 ++-- users/templates/users/profil.html | 14 ++-- users/templates/users/sidebar.html | 4 ++ users/urls.py | 1 + users/views.py | 84 ++---------------------- 15 files changed, 137 insertions(+), 143 deletions(-) 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 @@