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

Supprime cached proprety

This commit is contained in:
Gabriel Detraz 2017-07-18 03:49:36 +02:00 committed by chirac
parent e67080cb23
commit 856a666a72
3 changed files with 10 additions and 14 deletions

View file

@ -59,7 +59,7 @@ def create_cotis(vente, user, duration, date_start=False):
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']
else:
end_adhesion = user.end_adhesion
end_adhesion = user.end_adhesion()
date_start = date_start or timezone.now()
end_adhesion = end_adhesion or 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:
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):
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:
messages.success(request, "La facture a été crée")
return redirect("/users/profil/" + userid)

View file

@ -106,7 +106,7 @@ class Interface(models.Model):
""" Renvoie si une interface doit avoir accès ou non """
machine = self.machine
user = self.machine.user
return machine.active and user.has_access
return machine.active and user.has_access()
def mac_bare(self):
return str(EUI(self.mac_address, dialect=mac_bare)).lower()

View file

@ -247,14 +247,12 @@ class User(AbstractBaseUser):
def is_infra(self):
return self.has_right('infra')
@cached_property
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']
return date_max
@cached_property
def is_adherent(self):
end = self.end_adhesion
end = self.end_adhesion()
if not end:
return False
elif end < timezone.now():
@ -296,25 +294,23 @@ class User(AbstractBaseUser):
else:
return True
@cached_property
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_adherent() or self.is_whitelisted)
@cached_property
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_adhesion():
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_adhesion()
else:
return max(self.end_adhesion, self.end_whitelist)
return max(self.end_adhesion(), self.end_whitelist)
@cached_property
def solde(self):
@ -356,7 +352,7 @@ class User(AbstractBaseUser):
if base:
user_ldap.name = 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.mail = self.email
user_ldap.given_name = str(self.surname).lower() + '_' + str(self.name).lower()[:3]
@ -370,7 +366,7 @@ class User(AbstractBaseUser):
else:
user_ldap.shadowexpire = None
if access_refresh:
user_ldap.dialupAccess = str(self.has_access)
user_ldap.dialupAccess = str(self.has_access())
if mac_refresh:
user_ldap.macs = [inter.mac_bare() for inter in Interface.objects.filter(machine__in=Machine.objects.filter(user=self))]
user_ldap.save()