Commit 6507bc5b authored by Gabriel Detraz's avatar Gabriel Detraz Committed by root

Nouvelles methodes pour user

parent 65dedc07
......@@ -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):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment