8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-12-24 07:53:47 +00:00

Merge branch 'fix_ban' into 'master'

Fix valeur par défaut du search_time.

See merge request federez/re2o!78
This commit is contained in:
klafyvel 2018-02-21 00:01:41 +01:00
commit aa513f7732

View file

@ -49,11 +49,13 @@ from users.models import Adherent, User, Ban, Whitelist
from preferences.models import Service
def all_adherent(search_time=timezone.now()):
def all_adherent(search_time=None):
""" Fonction renvoyant tous les users adherents. Optimisee pour n'est
qu'une seule requete sql
Inspecte les factures de l'user et ses cotisation, regarde si elles
sont posterieur à now (end_time)"""
if search_time is None:
search_time = timezone.now()
return User.objects.filter(
facture__in=Facture.objects.filter(
vente__in=Vente.objects.filter(
@ -68,8 +70,10 @@ def all_adherent(search_time=timezone.now()):
).distinct()
def all_baned(search_time=timezone.now()):
def all_baned(search_time=None):
""" Fonction renvoyant tous les users bannis """
if search_time is None:
search_time = timezone.now()
return User.objects.filter(
ban__in=Ban.objects.filter(
date_end__gt=search_time
@ -77,8 +81,10 @@ def all_baned(search_time=timezone.now()):
).distinct()
def all_whitelisted(search_time=timezone.now()):
def all_whitelisted(search_time=None):
""" Fonction renvoyant tous les users whitelistes """
if search_time is None:
search_time = timezone.now()
return User.objects.filter(
whitelist__in=Whitelist.objects.filter(
date_end__gt=search_time
@ -86,9 +92,11 @@ def all_whitelisted(search_time=timezone.now()):
).distinct()
def all_has_access(search_time=timezone.now()):
def all_has_access(search_time=None):
""" Renvoie tous les users beneficiant d'une connexion
: user adherent ou whiteliste et non banni """
if search_time is None:
search_time = timezone.now()
return User.objects.filter(
Q(state=User.STATE_ACTIVE) &
~Q(ban__in=Ban.objects.filter(date_end__gt=search_time)) &