mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-05 01:16:27 +00:00
Nouvelles methodes pour user
This commit is contained in:
parent
65dedc07d8
commit
6507bc5bda
1 changed files with 31 additions and 4 deletions
|
@ -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):
|
||||
|
|
Loading…
Reference in a new issue