diff options
Diffstat (limited to 'ishtar_common/utils.py')
| -rw-r--r-- | ishtar_common/utils.py | 25 | 
1 files changed, 23 insertions, 2 deletions
| diff --git a/ishtar_common/utils.py b/ishtar_common/utils.py index 5d9e85c60..cc01f23e7 100644 --- a/ishtar_common/utils.py +++ b/ishtar_common/utils.py @@ -28,6 +28,7 @@ from django.conf import settings  from django.contrib.gis.geos import GEOSGeometry  from django.core.cache import cache  from django.core.urlresolvers import reverse +from django.utils.datastructures import MultiValueDict as BaseMultiValueDict  from django.utils.safestring import mark_safe  from django.utils.translation import ugettext_lazy as _, ugettext  from django.template.defaultfilters import slugify @@ -47,13 +48,33 @@ class BColors:      UNDERLINE = '\033[4m' +class MultiValueDict(BaseMultiValueDict): +    def get(self, *args, **kwargs): +        v = super(MultiValueDict, self).getlist(*args, **kwargs) +        if callable(v): +            v = v() +        if type(v) in (list, tuple) and len(v) > 1: +            v = ",".join(v) +        elif type(v) not in (int, unicode): +            v = super(MultiValueDict, self).get(*args, **kwargs) +        return v + +    def getlist(self, *args, **kwargs): +        lst = super(MultiValueDict, self).getlist(*args, **kwargs) +        if type(lst) not in (tuple, list): +            lst = [lst] +        return lst + +  def get_current_year():      return datetime.datetime.now().year -def get_cache(cls, extra_args=[]): +def get_cache(cls, extra_args=tuple(), app_label=None): +    if not app_label: +        app_label = cls._meta.app_label      cache_key = u"{}-{}-{}".format( -        settings.PROJECT_SLUG, cls._meta.app_label, cls.__name__) +        settings.PROJECT_SLUG, app_label, cls.__name__)      for arg in extra_args:          if not arg:              cache_key += '-0' | 
