8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-26 22:52:26 +00:00

New argument on all_adh and all_access including asso

This commit is contained in:
detraz 2019-03-17 15:23:51 +01:00
parent 0d0d09bc9f
commit 9053a752b1
2 changed files with 16 additions and 10 deletions

View file

@ -217,8 +217,8 @@ def stats_general(request):
).count() ).count()
ip_dict[ip_range] = [ip_range, ip_range.vlan, all_ip.count(), ip_dict[ip_range] = [ip_range, ip_range.vlan, all_ip.count(),
used_ip, active_ip, all_ip.count()-used_ip] used_ip, active_ip, all_ip.count()-used_ip]
_all_adherent = all_adherent() _all_adherent = all_adherent(including_asso=False)
_all_has_access = all_has_access() _all_has_access = all_has_access(including_asso=False)
_all_baned = all_baned() _all_baned = all_baned()
_all_whitelisted = all_whitelisted() _all_whitelisted = all_whitelisted()
_all_active_interfaces_count = all_active_interfaces_count() _all_active_interfaces_count = all_active_interfaces_count()

View file

@ -44,15 +44,15 @@ from machines.models import Interface, Machine
from users.models import Adherent, User, Ban, Whitelist from users.models import Adherent, User, Ban, Whitelist
from preferences.models import AssoOption 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 """ Fonction renvoyant tous les users adherents. Optimisee pour n'est
qu'une seule requete sql qu'une seule requete sql
Inspecte les factures de l'user et ses cotisation, regarde si elles Inspecte les factures de l'user et ses cotisation, regarde si elles
sont posterieur à now (end_time)""" sont posterieur à now (end_time)"""
if search_time is None: if search_time is None:
search_time = timezone.now() search_time = timezone.now()
return User.objects.filter( filter_user = (
facture__in=Facture.objects.filter( Q(facture__in=Facture.objects.filter(
vente__in=Vente.objects.filter( vente__in=Vente.objects.filter(
Q(type_cotisation='All') | Q(type_cotisation='Adhesion'), Q(type_cotisation='All') | Q(type_cotisation='Adhesion'),
cotisation__in=Cotisation.objects.filter( 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)) ).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): def all_baned(search_time=None):
@ -87,7 +92,7 @@ def all_whitelisted(search_time=None):
).distinct() ).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 + """ Return all connected users : active users and whitelisted +
asso_user defined in AssoOption pannel 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 including_asso:
if asso_user: asso_user = AssoOption.get_cached_value('utilisateur_asso')
filter_user |= Q(id=asso_user.id) if asso_user:
filter_user |= Q(id=asso_user.id)
return User.objects.filter(filter_user).distinct() return User.objects.filter(filter_user).distinct()