From 9053a752b12a89e4f0c60567a0b22e6c0c740bc7 Mon Sep 17 00:00:00 2001 From: detraz Date: Sun, 17 Mar 2019 15:23:51 +0100 Subject: [PATCH] New argument on all_adh and all_access including asso --- logs/views.py | 4 ++-- re2o/utils.py | 22 ++++++++++++++-------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/logs/views.py b/logs/views.py index 9d047f07..28205063 100644 --- a/logs/views.py +++ b/logs/views.py @@ -217,8 +217,8 @@ def stats_general(request): ).count() ip_dict[ip_range] = [ip_range, ip_range.vlan, all_ip.count(), used_ip, active_ip, all_ip.count()-used_ip] - _all_adherent = all_adherent() - _all_has_access = all_has_access() + _all_adherent = all_adherent(including_asso=False) + _all_has_access = all_has_access(including_asso=False) _all_baned = all_baned() _all_whitelisted = all_whitelisted() _all_active_interfaces_count = all_active_interfaces_count() diff --git a/re2o/utils.py b/re2o/utils.py index ca8bce43..2470cf50 100644 --- a/re2o/utils.py +++ b/re2o/utils.py @@ -44,15 +44,15 @@ from machines.models import Interface, Machine from users.models import Adherent, User, Ban, Whitelist from preferences.models import AssoOption -def all_adherent(search_time=None): +def all_adherent(search_time=None, including_asso=True): """ 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( + filter_user = ( + Q(facture__in=Facture.objects.filter( vente__in=Vente.objects.filter( Q(type_cotisation='All') | Q(type_cotisation='Adhesion'), cotisation__in=Cotisation.objects.filter( @@ -62,7 +62,12 @@ def all_adherent(search_time=None): ).filter(Q(date_start__lt=search_time) & Q(date_end__gt=search_time)) ) ) - ).distinct() + )) + if including_asso: + asso_user = AssoOption.get_cached_value('utilisateur_asso') + if asso_user: + filter_user |= Q(id=asso_user.id) + return User.objects.filter(filter_user).distinct() def all_baned(search_time=None): @@ -87,7 +92,7 @@ def all_whitelisted(search_time=None): ).distinct() -def all_has_access(search_time=None): +def all_has_access(search_time=None, including_asso=True): """ Return all connected users : active users and whitelisted + asso_user defined in AssoOption pannel ---- @@ -111,9 +116,10 @@ def all_has_access(search_time=None): ) ))) ) - asso_user = AssoOption.get_cached_value('utilisateur_asso') - if asso_user: - filter_user |= Q(id=asso_user.id) + if including_asso: + asso_user = AssoOption.get_cached_value('utilisateur_asso') + if asso_user: + filter_user |= Q(id=asso_user.id) return User.objects.filter(filter_user).distinct()