From ff2b4cb0d2a37a8ae83edcb223bbaf8cf6894a23 Mon Sep 17 00:00:00 2001 From: chirac Date: Sun, 3 Jul 2016 02:15:17 +0200 Subject: [PATCH] =?UTF-8?q?Validateur=20nazi=20pour=20emp=C3=A9cher=20de?= =?UTF-8?q?=20mettre=20des=20dates=20de=20fins=20de=20ban=20dans=20le=20pa?= =?UTF-8?q?ss=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cotisations/__pycache__/views.cpython-34.pyc | Bin 3433 -> 3669 bytes cotisations/views.py | 10 +++++++++ users/models.py | 8 +++++++ users/views.py | 22 +++++++++++++++++++ 4 files changed, 40 insertions(+) diff --git a/cotisations/__pycache__/views.cpython-34.pyc b/cotisations/__pycache__/views.cpython-34.pyc index 7fe542ba7d44811efeaf6fec4484035de465afcb..4fbbb82e5c1b2390d67e8cc0adf8048d716acd88 100644 GIT binary patch delta 625 zcmY+BJ#Q015Qb;Yhwa=42nbPZEN4yRkb@|W316l_i9;-uB0_NlQb4kdZxI)yJ8Ab! zKr*CA8Y+ryDJW&f6DNCtrOIP1<4_g(*BEEnb0gj9hL5F^ zamt4F2w-`bMH^3{ZK+_mV&BE%e_N{abiuqkcE_ob*vW<6RGO3aq~BALWQV4Sbk)pc z3s@gEvTqP;=3DMHR?MS(6Bo_|eT6;54cTw^$l>x>M8o)J`oaf88YR5#6cN0`s!#w*p)j}oQqJ*QZ_4xk0NN#c%K!iX delta 407 zcmcaA^HNIr9S<*;zgR{15*`MI#|%h-3CMN;;$oSN%5sd%!I~1A0~qU=7^5biXRcvX z-K@$Q#>l4%R8S-gByKV1<(E(HWD8(anS6^)Q(79NQvgUXF!3`=FbXm9GjcMjGjcH& z>1~!{pTo$gGkG^hKcm8AZ%!vh?a6(da%{Rl#YK9PH*va2>VTM1Z~|mlksXjwn=Hts z&uBNmfTv5Mw3&xRgD!u%8WsT35ehV5vCx58AR}c2s0324kENc zg!SY-+zO1glkWmao5}yU zfCK~3e??9}+D}t)^AjFkMp1CM=mAB*&MvYCv79Dz^QkGx0hwZqVvGWeGC(ZAqyfYr Nnuiq#xp~BRcmcyIMHv79 diff --git a/cotisations/views.py b/cotisations/views.py index d4ee4a32..4aa8aa17 100644 --- a/cotisations/views.py +++ b/cotisations/views.py @@ -24,6 +24,16 @@ def end_adhesion(user): date_max = Cotisation.objects.all().filter(facture=Facture.objects.all().filter(user=user)).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, article): """ 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) diff --git a/users/models.py b/users/models.py index aeea40c3..50931404 100644 --- a/users/models.py +++ b/users/models.py @@ -2,6 +2,8 @@ from django.db import models from django.forms import ModelForm from django import forms +from django.utils import timezone + class User(models.Model): STATE_ACTIVE = 0 STATE_DEACTIVATED = 1 @@ -119,3 +121,9 @@ class BanForm(ModelForm): class Meta: model = Ban exclude = ['user'] + + def clean_date_end(self): + date_end = self.cleaned_data['date_end'] + if date_end < timezone.now(): + raise forms.ValidationError("Triple buse, la date de fin ne peut pas être avant maintenant... Re2o ne voyage pas dans le temps") + return date_end diff --git a/users/views.py b/users/views.py index 5fb9c650..7b63fae3 100644 --- a/users/views.py +++ b/users/views.py @@ -6,9 +6,12 @@ from django.shortcuts import render_to_response, get_object_or_404 from django.core.context_processors import csrf from django.template import Context, RequestContext, loader from django.contrib import messages +from django.db.models import Max +from django.utils import timezone from users.models import User, Right, Ban, DelRightForm, UserForm, InfoForm, PasswordForm, StateForm, RightForm, BanForm from users.forms import PassForm +from cotisations.views import is_adherent from re2o.login import makeSecret, hashNT @@ -17,6 +20,23 @@ def end_ban(user): date_max = Ban.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 has_access(user): + """ Renvoie si un utilisateur a accès à internet""" + if user.state == 0 and not is_ban(user) and is_adherent(user): + return True + else: + return False + def form(ctx, template, request): c = ctx c.update(csrf(request)) @@ -103,6 +123,8 @@ def add_ban(request, userid): ban.save() messages.success(request, "Bannissement ajouté") return redirect("/users/") + if is_ban(user): + messages.error(request, u"Attention, cet utilisateur a deja un bannissement actif" ) return form({'userform': ban}, 'users/user.html', request) def edit_ban(request, banid):