diff --git a/cotisations/__pycache__/views.cpython-34.pyc b/cotisations/__pycache__/views.cpython-34.pyc index 7fe542ba..4fbbb82e 100644 Binary files a/cotisations/__pycache__/views.cpython-34.pyc and b/cotisations/__pycache__/views.cpython-34.pyc differ 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):