From 225164273f4e60034690799d264882bce41e90a1 Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Sat, 28 Oct 2017 05:12:18 +0200 Subject: [PATCH] Nouvelles methodes pour user --- users/models.py | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/users/models.py b/users/models.py index e78989b0..54500f4e 100644 --- a/users/models.py +++ b/users/models.py @@ -378,6 +378,22 @@ class User(AbstractBaseUser): user=self ).exclude(valid=False) ) + ).filter( + Q(type_cotisation='All') | Q(type_cotisation='Adhesion') + ).aggregate(models.Max('date_end'))['date_end__max'] + return date_max + + def end_connexion(self): + """ Renvoie la date de fin de connexion d'un user. Examine les objets + cotisation""" + date_max = Cotisation.objects.filter( + vente__in=Vente.objects.filter( + facture__in=Facture.objects.filter( + user=self + ).exclude(valid=False) + ) + ).filter( + Q(type_cotisation='All') | Q(type_cotisation='Connexion') ).aggregate(models.Max('date_end'))['date_end__max'] return date_max @@ -392,6 +408,17 @@ class User(AbstractBaseUser): else: return True + def is_connected(self): + """ Renvoie True si l'user est adhérent : si + self.end_adhesion()>now et end_connexion>now""" + end = self.end_connexion() + if not end: + return False + elif end < DT_NOW: + return False + else: + return self.is_adherent() + @cached_property def end_ban(self): """ Renvoie la date de fin de ban d'un user, False sinon """ @@ -433,20 +460,20 @@ class User(AbstractBaseUser): def has_access(self): """ Renvoie si un utilisateur a accès à internet """ return self.state == User.STATE_ACTIVE\ - and not self.is_ban and (self.is_adherent() or self.is_whitelisted) + and not self.is_ban and (self.is_connected() or self.is_whitelisted) def end_access(self): """ Renvoie la date de fin normale d'accès (adhésion ou whiteliste)""" - if not self.end_adhesion(): + if not self.end_connexion(): if not self.end_whitelist: return None else: return self.end_whitelist else: if not self.end_whitelist: - return self.end_adhesion() + return self.end_connexion() else: - return max(self.end_adhesion(), self.end_whitelist) + return max(self.end_connexion(), self.end_whitelist) @cached_property def solde(self):