mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-22 11:23:10 +00:00
Supprime cached proprety
This commit is contained in:
parent
e395bc33bd
commit
1a6fb71843
3 changed files with 10 additions and 14 deletions
|
@ -59,7 +59,7 @@ def create_cotis(vente, user, duration, date_start=False):
|
||||||
if date_start:
|
if date_start:
|
||||||
end_adhesion = Cotisation.objects.filter(vente__in=Vente.objects.filter(facture__in=Facture.objects.filter(user=user).exclude(valid=False))).filter(date_start__lt=date_start).aggregate(Max('date_end'))['date_end__max']
|
end_adhesion = Cotisation.objects.filter(vente__in=Vente.objects.filter(facture__in=Facture.objects.filter(user=user).exclude(valid=False))).filter(date_start__lt=date_start).aggregate(Max('date_end'))['date_end__max']
|
||||||
else:
|
else:
|
||||||
end_adhesion = user.end_adhesion
|
end_adhesion = user.end_adhesion()
|
||||||
date_start = date_start or timezone.now()
|
date_start = date_start or timezone.now()
|
||||||
end_adhesion = end_adhesion or date_start
|
end_adhesion = end_adhesion or date_start
|
||||||
date_max = max(end_adhesion, date_start)
|
date_max = max(end_adhesion, date_start)
|
||||||
|
@ -116,7 +116,7 @@ def new_facture(request, userid):
|
||||||
if art_item.cleaned_data['article'].iscotisation:
|
if art_item.cleaned_data['article'].iscotisation:
|
||||||
create_cotis(new_vente, user, art_item.cleaned_data['article'].duration*art_item.cleaned_data['quantity'])
|
create_cotis(new_vente, user, art_item.cleaned_data['article'].duration*art_item.cleaned_data['quantity'])
|
||||||
if any(art_item.cleaned_data['article'].iscotisation for art_item in articles if art_item.cleaned_data):
|
if any(art_item.cleaned_data['article'].iscotisation for art_item in articles if art_item.cleaned_data):
|
||||||
messages.success(request, "La cotisation a été prolongée pour l'adhérent %s jusqu'au %s" % (user.name, user.end_adhesion) )
|
messages.success(request, "La cotisation a été prolongée pour l'adhérent %s jusqu'au %s" % (user.pseudo, user.end_adhesion()) )
|
||||||
else:
|
else:
|
||||||
messages.success(request, "La facture a été crée")
|
messages.success(request, "La facture a été crée")
|
||||||
return redirect("/users/profil/" + userid)
|
return redirect("/users/profil/" + userid)
|
||||||
|
|
|
@ -106,7 +106,7 @@ class Interface(models.Model):
|
||||||
""" Renvoie si une interface doit avoir accès ou non """
|
""" Renvoie si une interface doit avoir accès ou non """
|
||||||
machine = self.machine
|
machine = self.machine
|
||||||
user = self.machine.user
|
user = self.machine.user
|
||||||
return machine.active and user.has_access
|
return machine.active and user.has_access()
|
||||||
|
|
||||||
def mac_bare(self):
|
def mac_bare(self):
|
||||||
return str(EUI(self.mac_address, dialect=mac_bare)).lower()
|
return str(EUI(self.mac_address, dialect=mac_bare)).lower()
|
||||||
|
|
|
@ -247,14 +247,12 @@ class User(AbstractBaseUser):
|
||||||
def is_infra(self):
|
def is_infra(self):
|
||||||
return self.has_right('infra')
|
return self.has_right('infra')
|
||||||
|
|
||||||
@cached_property
|
|
||||||
def end_adhesion(self):
|
def end_adhesion(self):
|
||||||
date_max = Cotisation.objects.filter(vente__in=Vente.objects.filter(facture__in=Facture.objects.filter(user=self).exclude(valid=False))).aggregate(models.Max('date_end'))['date_end__max']
|
date_max = Cotisation.objects.filter(vente__in=Vente.objects.filter(facture__in=Facture.objects.filter(user=self).exclude(valid=False))).aggregate(models.Max('date_end'))['date_end__max']
|
||||||
return date_max
|
return date_max
|
||||||
|
|
||||||
@cached_property
|
|
||||||
def is_adherent(self):
|
def is_adherent(self):
|
||||||
end = self.end_adhesion
|
end = self.end_adhesion()
|
||||||
if not end:
|
if not end:
|
||||||
return False
|
return False
|
||||||
elif end < timezone.now():
|
elif end < timezone.now():
|
||||||
|
@ -296,25 +294,23 @@ class User(AbstractBaseUser):
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@cached_property
|
|
||||||
def has_access(self):
|
def has_access(self):
|
||||||
""" Renvoie si un utilisateur a accès à internet """
|
""" Renvoie si un utilisateur a accès à internet """
|
||||||
return self.state == User.STATE_ACTIVE \
|
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_adherent() or self.is_whitelisted)
|
||||||
|
|
||||||
@cached_property
|
|
||||||
def end_access(self):
|
def end_access(self):
|
||||||
""" Renvoie la date de fin normale d'accès (adhésion ou whiteliste)"""
|
""" Renvoie la date de fin normale d'accès (adhésion ou whiteliste)"""
|
||||||
if not self.end_adhesion:
|
if not self.end_adhesion():
|
||||||
if not self.end_whitelist:
|
if not self.end_whitelist:
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
return self.end_whitelist
|
return self.end_whitelist
|
||||||
else:
|
else:
|
||||||
if not self.end_whitelist:
|
if not self.end_whitelist:
|
||||||
return self.end_adhesion
|
return self.end_adhesion()
|
||||||
else:
|
else:
|
||||||
return max(self.end_adhesion, self.end_whitelist)
|
return max(self.end_adhesion(), self.end_whitelist)
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def solde(self):
|
def solde(self):
|
||||||
|
@ -356,7 +352,7 @@ class User(AbstractBaseUser):
|
||||||
if base:
|
if base:
|
||||||
user_ldap.name = self.pseudo
|
user_ldap.name = self.pseudo
|
||||||
user_ldap.sn = self.pseudo
|
user_ldap.sn = self.pseudo
|
||||||
user_ldap.dialupAccess = str(self.has_access)
|
user_ldap.dialupAccess = str(self.has_access())
|
||||||
user_ldap.home_directory = '/home/' + self.pseudo
|
user_ldap.home_directory = '/home/' + self.pseudo
|
||||||
user_ldap.mail = self.email
|
user_ldap.mail = self.email
|
||||||
user_ldap.given_name = str(self.surname).lower() + '_' + str(self.name).lower()[:3]
|
user_ldap.given_name = str(self.surname).lower() + '_' + str(self.name).lower()[:3]
|
||||||
|
@ -370,7 +366,7 @@ class User(AbstractBaseUser):
|
||||||
else:
|
else:
|
||||||
user_ldap.shadowexpire = None
|
user_ldap.shadowexpire = None
|
||||||
if access_refresh:
|
if access_refresh:
|
||||||
user_ldap.dialupAccess = str(self.has_access)
|
user_ldap.dialupAccess = str(self.has_access())
|
||||||
if mac_refresh:
|
if mac_refresh:
|
||||||
user_ldap.macs = [inter.mac_bare() for inter in Interface.objects.filter(machine__in=Machine.objects.filter(user=self))]
|
user_ldap.macs = [inter.mac_bare() for inter in Interface.objects.filter(machine__in=Machine.objects.filter(user=self))]
|
||||||
user_ldap.save()
|
user_ldap.save()
|
||||||
|
|
Loading…
Reference in a new issue