summaryrefslogtreecommitdiff
path: root/ishtar_common/utils.py
diff options
context:
space:
mode:
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
commit7014fd98d3eec2f40cc2a574de35bb0c339a94e7 (patch)
tree5f38e92243a02add2b1e0176585f17f8c4aef7d6 /ishtar_common/utils.py
parenta9a1a82a5cc32ea8e5b7a8051de5ff4cd0c6fdc7 (diff)
downloadIshtar-7014fd98d3eec2f40cc2a574de35bb0c339a94e7.tar.bz2
Ishtar-7014fd98d3eec2f40cc2a574de35bb0c339a94e7.zip
Colors and orders in short menu - cache mechanism (refs #1562)
Diffstat (limited to 'ishtar_common/utils.py')
-rw-r--r--ishtar_common/utils.py17
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'):