diff options
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'): | 
