From 6a868f55d08cd9be71be95af6617abdcab80a57c Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Thu, 18 Feb 2016 12:00:34 +0100 Subject: Force update of cache when modifying site configuration --- ishtar_common/models.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'ishtar_common/models.py') diff --git a/ishtar_common/models.py b/ishtar_common/models.py index f5c6ed223..0b1f42460 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -821,9 +821,9 @@ class IshtarSiteProfile(models.Model, Cached): return obj -def get_current_profile(): +def get_current_profile(force=False): cache_key, value = get_cache(IshtarSiteProfile, 'is-current-profile') - if value: + if value and not force: return value q = IshtarSiteProfile.objects.filter(active=True) if not q.count(): @@ -835,6 +835,14 @@ def get_current_profile(): return obj +def cached_site_changed(sender, **kwargs): + if not kwargs['instance']: + return + get_current_profile(force=True) + +post_save.connect(cached_site_changed, sender=IshtarSiteProfile) + + class GlobalVar(models.Model, Cached): slug = models.SlugField(_(u"Variable name"), unique=True) description = models.TextField(_(u"Description of the variable"), -- cgit v1.2.3