mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-09-12 01:03:09 +00:00
Mise en cache de l'instance en entier, supprime les clefs foireuses
This commit is contained in:
parent
a3c0a50f4a
commit
9f560b2141
3 changed files with 72 additions and 51 deletions
|
@ -69,18 +69,17 @@ class OptionalUser(models.Model):
|
||||||
)
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def set_in_cache(cls, key):
|
def set_in_cache(cls):
|
||||||
machine_options, _created = cls.objects.get_or_create()
|
optionaluser, _created = cls.objects.get_or_create()
|
||||||
value = getattr(machine_options, key)
|
cache.set('optionaluser', optionaluser, None)
|
||||||
cache.set('optionaluser_' + key, value, None)
|
return optionaluser
|
||||||
return value
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_cached_value(cls, key):
|
def get_cached_value(cls, key):
|
||||||
value = cache.get('optionaluser_' + key)
|
optionaluser = cache.get('optionaluser')
|
||||||
if value == None:
|
if optionaluser == None:
|
||||||
value = cls.set_in_cache(key)
|
optionaluser = cls.set_in_cache()
|
||||||
return value
|
return getattr(optionaluser, key)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
permissions = (
|
permissions = (
|
||||||
|
@ -148,6 +147,13 @@ class OptionalUser(models.Model):
|
||||||
c.save()
|
c.save()
|
||||||
|
|
||||||
|
|
||||||
|
@receiver(post_save, sender=OptionalUser)
|
||||||
|
def optionaluser_post_save(sender, **kwargs):
|
||||||
|
"""Ecriture dans le cache"""
|
||||||
|
user_pref = kwargs['instance']
|
||||||
|
user_pref.set_in_cache()
|
||||||
|
|
||||||
|
|
||||||
class OptionalMachine(models.Model):
|
class OptionalMachine(models.Model):
|
||||||
"""Options pour les machines : maximum de machines ou d'alias par user
|
"""Options pour les machines : maximum de machines ou d'alias par user
|
||||||
sans droit, activation de l'ipv6"""
|
sans droit, activation de l'ipv6"""
|
||||||
|
@ -176,18 +182,17 @@ class OptionalMachine(models.Model):
|
||||||
return not self.get_cached_value('ipv6_mode') == 'DISABLED'
|
return not self.get_cached_value('ipv6_mode') == 'DISABLED'
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def set_in_cache(cls, key):
|
def set_in_cache(cls):
|
||||||
machine_options, _created = cls.objects.get_or_create()
|
optionalmachine, _created = cls.objects.get_or_create()
|
||||||
value = getattr(machine_options, key)
|
cache.set('optionalmachine', optionalmachine, None)
|
||||||
cache.set('optionalmachine_' + key, value, None)
|
return optionalmachine
|
||||||
return value
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_cached_value(cls, key):
|
def get_cached_value(cls, key):
|
||||||
value = cache.get('optionalmachine_' + key)
|
optionalmachine = cache.get('optionalmachine')
|
||||||
if value == None:
|
if optionalmachine == None:
|
||||||
value = cls.set_in_cache(key)
|
optionalmachine = cls.set_in_cache()
|
||||||
return value
|
return getattr(optionalmachine, key)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
permissions = (
|
permissions = (
|
||||||
|
@ -250,9 +255,9 @@ class OptionalMachine(models.Model):
|
||||||
|
|
||||||
@receiver(post_save, sender=OptionalMachine)
|
@receiver(post_save, sender=OptionalMachine)
|
||||||
def optionalmachine_post_save(sender, **kwargs):
|
def optionalmachine_post_save(sender, **kwargs):
|
||||||
"""Synchronisation ipv6"""
|
"""Synchronisation ipv6 et ecriture dans le cache"""
|
||||||
machine_pref = kwargs['instance']
|
machine_pref = kwargs['instance']
|
||||||
|
machine_pref.set_in_cache()
|
||||||
if machine_pref.ipv6_mode != "DISABLED":
|
if machine_pref.ipv6_mode != "DISABLED":
|
||||||
for interface in machines.models.Interface.objects.all():
|
for interface in machines.models.Interface.objects.all():
|
||||||
interface.sync_ipv6()
|
interface.sync_ipv6()
|
||||||
|
@ -291,18 +296,17 @@ class OptionalTopologie(models.Model):
|
||||||
)
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def set_in_cache(cls, key):
|
def set_in_cache(cls):
|
||||||
machine_options, _created = cls.objects.get_or_create()
|
optionaltopologie, _created = cls.objects.get_or_create()
|
||||||
value = getattr(machine_options, key)
|
cache.set('optionaltopologie', optionaltopologie, None)
|
||||||
cache.set('optionaltopologie_' + key, value, None)
|
return optionaltopologie
|
||||||
return value
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_cached_value(cls, key):
|
def get_cached_value(cls, key):
|
||||||
value = cache.get('optionaltopologie_' + key)
|
optionaltopologie = cache.get('optionaltopologie')
|
||||||
if value == None:
|
if optionaltopologie == None:
|
||||||
value = cls.set_in_cache(key)
|
optionaltopologie = cls.set_in_cache()
|
||||||
return value
|
return getattr(optionaltopologie, key)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
permissions = (
|
permissions = (
|
||||||
|
@ -362,6 +366,13 @@ class OptionalTopologie(models.Model):
|
||||||
de voir les préférences concernant la topologie"
|
de voir les préférences concernant la topologie"
|
||||||
|
|
||||||
|
|
||||||
|
@receiver(post_save, sender=OptionalTopologie)
|
||||||
|
def optionaltopologie_post_save(sender, **kwargs):
|
||||||
|
"""Ecriture dans le cache"""
|
||||||
|
topologie_pref = kwargs['instance']
|
||||||
|
topologie_pref.set_in_cache()
|
||||||
|
|
||||||
|
|
||||||
class GeneralOption(models.Model):
|
class GeneralOption(models.Model):
|
||||||
"""Options générales : nombre de resultats par page, nom du site,
|
"""Options générales : nombre de resultats par page, nom du site,
|
||||||
temps où les liens sont valides"""
|
temps où les liens sont valides"""
|
||||||
|
@ -390,18 +401,17 @@ class GeneralOption(models.Model):
|
||||||
)
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def set_in_cache(cls, key):
|
def set_in_cache(cls):
|
||||||
machine_options, _created = cls.objects.get_or_create()
|
generaloption, _created = cls.objects.get_or_create()
|
||||||
value = getattr(machine_options, key)
|
cache.set('generaloption', generaloption, None)
|
||||||
cache.set('generaloption_' + key, value, None)
|
return generaloption
|
||||||
return value
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_cached_value(cls, key):
|
def get_cached_value(cls, key):
|
||||||
value = cache.get('generaloption_' + key)
|
generaloption = cache.get('generaloption')
|
||||||
if value == None:
|
if generaloption == None:
|
||||||
value = cls.set_in_cache(key)
|
generaloption = cls.set_in_cache()
|
||||||
return value
|
return getattr(generaloption, key)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
permissions = (
|
permissions = (
|
||||||
|
@ -462,6 +472,13 @@ class GeneralOption(models.Model):
|
||||||
de voir les préférences générales"
|
de voir les préférences générales"
|
||||||
|
|
||||||
|
|
||||||
|
@receiver(post_save, sender=GeneralOption)
|
||||||
|
def generaloption_post_save(sender, **kwargs):
|
||||||
|
"""Ecriture dans le cache"""
|
||||||
|
general_pref = kwargs['instance']
|
||||||
|
general_pref.set_in_cache()
|
||||||
|
|
||||||
|
|
||||||
class Service(models.Model):
|
class Service(models.Model):
|
||||||
"""Liste des services affichés sur la page d'accueil : url, description,
|
"""Liste des services affichés sur la page d'accueil : url, description,
|
||||||
image et nom"""
|
image et nom"""
|
||||||
|
@ -572,18 +589,17 @@ class AssoOption(models.Model):
|
||||||
)
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def set_in_cache(cls, key):
|
def set_in_cache(cls):
|
||||||
machine_options, _created = cls.objects.get_or_create()
|
assooption, _created = cls.objects.get_or_create()
|
||||||
value = getattr(machine_options, key)
|
cache.set('assooption', assooption, None)
|
||||||
cache.set('assooption_' + key, value, None)
|
return assooption
|
||||||
return value
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_cached_value(cls, key):
|
def get_cached_value(cls, key):
|
||||||
value = cache.get('assooption_' + key)
|
assooption = cache.get('assooption')
|
||||||
if value == None:
|
if assooption == None:
|
||||||
value = cls.set_in_cache(key)
|
assooption = cls.set_in_cache()
|
||||||
return value
|
return getattr(assooption, key)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
permissions = (
|
permissions = (
|
||||||
|
@ -643,6 +659,13 @@ class AssoOption(models.Model):
|
||||||
de voir les préférences concernant l'association"
|
de voir les préférences concernant l'association"
|
||||||
|
|
||||||
|
|
||||||
|
@receiver(post_save, sender=AssoOption)
|
||||||
|
def assooption_post_save(sender, **kwargs):
|
||||||
|
"""Ecriture dans le cache"""
|
||||||
|
asso_pref = kwargs['instance']
|
||||||
|
asso_pref.set_in_cache()
|
||||||
|
|
||||||
|
|
||||||
class MailMessageOption(models.Model):
|
class MailMessageOption(models.Model):
|
||||||
"""Reglages, mail de bienvenue et autre"""
|
"""Reglages, mail de bienvenue et autre"""
|
||||||
PRETTY_NAME = "Options de corps de mail"
|
PRETTY_NAME = "Options de corps de mail"
|
||||||
|
|
|
@ -364,8 +364,7 @@ def new_switch(request):
|
||||||
request.POST or None,
|
request.POST or None,
|
||||||
)
|
)
|
||||||
if switch.is_valid() and machine.is_valid() and interface.is_valid():
|
if switch.is_valid() and machine.is_valid() and interface.is_valid():
|
||||||
options, _created = AssoOption.objects.get_or_create()
|
user = AssoOption.get_cached_value('utilisateur_asso')
|
||||||
user = options.utilisateur_asso
|
|
||||||
if not user:
|
if not user:
|
||||||
messages.error(request, "L'user association n'existe pas encore,\
|
messages.error(request, "L'user association n'existe pas encore,\
|
||||||
veuillez le créer ou le linker dans preferences")
|
veuillez le créer ou le linker dans preferences")
|
||||||
|
|
|
@ -701,7 +701,6 @@ class User(FieldPermissionModelMixin, AbstractBaseUser, PermissionsMixin):
|
||||||
else:
|
else:
|
||||||
return False, u"Vous n'avez pas le droit d'éditer ce club"
|
return False, u"Vous n'avez pas le droit d'éditer ce club"
|
||||||
else:
|
else:
|
||||||
options, _created = AssoOption.objects.get_or_create()
|
|
||||||
if self == user_request:
|
if self == user_request:
|
||||||
return True, None
|
return True, None
|
||||||
elif user_request.has_perm('users.change_all_users'):
|
elif user_request.has_perm('users.change_all_users'):
|
||||||
|
@ -709,7 +708,7 @@ class User(FieldPermissionModelMixin, AbstractBaseUser, PermissionsMixin):
|
||||||
elif user_request.has_perm('users.change_user'):
|
elif user_request.has_perm('users.change_user'):
|
||||||
if self.groups.filter(listright__critical=True):
|
if self.groups.filter(listright__critical=True):
|
||||||
return False, u"Utilisateurs avec droits critiques, ne peut etre édité"
|
return False, u"Utilisateurs avec droits critiques, ne peut etre édité"
|
||||||
elif self == options.utilisateur_asso:
|
elif self == AssoOption.get_cached_value('utilisateur_asso'):
|
||||||
return False, u"Impossible d'éditer l'utilisateur asso sans droit change_all_users"
|
return False, u"Impossible d'éditer l'utilisateur asso sans droit change_all_users"
|
||||||
else:
|
else:
|
||||||
return True, None
|
return True, None
|
||||||
|
|
Loading…
Reference in a new issue