diff options
author | Étienne Loks <etienne.loks@proxience.com> | 2014-07-21 19:21:27 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@proxience.com> | 2014-07-21 19:21:27 +0200 |
commit | a27dca4b361b0d2f46a20f9ac2719ef811c093e0 (patch) | |
tree | 5f38e92243a02add2b1e0176585f17f8c4aef7d6 /ishtar_common/utils.py | |
parent | 0cc64347e47a0c3117bb4514e6b966f651f552f4 (diff) | |
download | Ishtar-a27dca4b361b0d2f46a20f9ac2719ef811c093e0.tar.bz2 Ishtar-a27dca4b361b0d2f46a20f9ac2719ef811c093e0.zip |
Colors and orders in short menu - cache mechanism (refs #1562)
Diffstat (limited to 'ishtar_common/utils.py')
-rw-r--r-- | ishtar_common/utils.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/ishtar_common/utils.py b/ishtar_common/utils.py index d5fc37276..f50031d5d 100644 --- a/ishtar_common/utils.py +++ b/ishtar_common/utils.py @@ -17,7 +17,24 @@ # See the file COPYING for details. +from django.core.cache import cache from django.utils.translation import ugettext +from django.template.defaultfilters import slugify + +def get_cache(cls, extra_args=[]): + cache_key = cls.__name__ + for arg in extra_args: + if not arg: + cache_key += '-0' + else: + if type(arg) == dict: + cache_key += '-' + "_".join([unicode(arg[k]) for k in arg]) + elif type(arg) in (list, tuple): + cache_key += '-' + "_".join([unicode(v) for v in arg]) + else: + cache_key += '-' + unicode(arg) + cache_key = slugify(cache_key) + return cache_key, cache.get(cache_key) def cached_label_changed(sender, **kwargs): if not kwargs.get('instance'): |