diff options
Diffstat (limited to 'ishtar_common/models.py')
| -rw-r--r-- | ishtar_common/models.py | 80 | 
1 files changed, 52 insertions, 28 deletions
| diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 0b89e6416..c0ac5004f 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -683,7 +683,11 @@ class GeneralType(Cached, models.Model):          return "_".join(items)      @classmethod -    def get_help(cls, dct={}, exclude=[], force=False): +    def get_help(cls, dct=None, exclude=None, force=False, full_hierarchy=None): +        if not dct: +            dct = {} +        if not exclude: +            exclude = []          keys = ['__get_help']          keys += ["{}".format(ex) for ex in exclude]          keys += ['{}-{}'.format(str(k), dct[k]) for k in dct] @@ -752,7 +756,8 @@ class GeneralType(Cached, models.Model):      @classmethod      def get_types(cls, dct=None, instances=False, exclude=None, -                  empty_first=True, default=None, initial=None, force=False): +                  empty_first=True, default=None, initial=None, force=False, +                  full_hierarchy=False):          if not dct:              dct = {}          if not exclude: @@ -761,7 +766,8 @@ class GeneralType(Cached, models.Model):          if not instances and empty_first and not default:              types = [('', '--')]          types += cls._pre_get_types(dct, instances, exclude, -                                    default, force) +                                    default, force, +                                    get_full_hierarchy=full_hierarchy)          if not initial:              return types          new_vals = cls._get_initial_types(initial, [idx for idx, lbl in types]) @@ -770,7 +776,7 @@ class GeneralType(Cached, models.Model):      @classmethod      def _pre_get_types(cls, dct=None, instances=False, exclude=None, -                       default=None, force=False): +                       default=None, force=False, get_full_hierarchy=False):          if not dct:              dct = {}          if not exclude: @@ -790,10 +796,10 @@ class GeneralType(Cached, models.Model):              if not cache_key:                  return cls._get_parent_types(                      base_dct, instances, exclude=exclude, -                    default=default) +                    default=default, get_full_hierarchy=get_full_hierarchy)              vals = [v for v in cls._get_parent_types(                  base_dct, instances, exclude=exclude, -                default=default)] +                default=default, get_full_hierarchy=get_full_hierarchy)]              cache.set(cache_key, vals, settings.CACHE_TIMEOUT)              return vals @@ -873,7 +879,7 @@ class GeneralType(Cached, models.Model):      @classmethod      def _get_childs(cls, item, child_list, prefix=0, instances=False, -                    is_last=False, last_of=None): +                    is_last=False, last_of=None, get_full_hierarchy=False):          if not last_of:              last_of = [] @@ -884,32 +890,39 @@ class GeneralType(Cached, models.Model):          lst = []          total = len(current_child_lst) +        full_hierarchy_initial = get_full_hierarchy          for idx, child in enumerate(current_child_lst):              mylast_of = last_of[:] +            p = ''              if instances:                  child.rank = prefix                  lst.append(child)              else: -                p = '' -                cprefix = prefix -                while cprefix: -                    cprefix -= 1 -                    if not cprefix: -                        if (idx + 1) == total: -                            p += cls.PREFIX_LAST -                        else: -                            p += cls.PREFIX_MEDIUM -                    elif is_last: -                        if mylast_of: -                            clast = mylast_of.pop(0) -                            if clast: -                                p += cls.PREFIX_EMPTY +                if full_hierarchy_initial: +                    if isinstance(full_hierarchy_initial, str): +                        p = full_hierarchy_initial + " > " +                    else: +                        p = "" +                else: +                    cprefix = prefix +                    while cprefix: +                        cprefix -= 1 +                        if not cprefix: +                            if (idx + 1) == total: +                                p += cls.PREFIX_LAST +                            else: +                                p += cls.PREFIX_MEDIUM +                        elif is_last: +                            if mylast_of: +                                clast = mylast_of.pop(0) +                                if clast: +                                    p += cls.PREFIX_EMPTY +                                else: +                                    p += cls.PREFIX                              else: -                                p += cls.PREFIX +                                p += cls.PREFIX_EMPTY                          else: -                            p += cls.PREFIX_EMPTY -                    else: -                        p += cls.PREFIX +                            p += cls.PREFIX                  lst.append((                      child[0], SafeText(p + str(_(child[1])))                  )) @@ -919,15 +932,23 @@ class GeneralType(Cached, models.Model):                  child_id = child.id              else:                  child_id = child[0] +                if get_full_hierarchy: +                    if p: +                        if not p.endswith(" > "): +                            p += " > " +                        get_full_hierarchy = p + child[1] +                    else: +                        get_full_hierarchy = child[1]              for sub_child in cls._get_childs(                      child_id, child_list, prefix, instances, -                    is_last=((idx + 1) == total), last_of=clast_of): +                    is_last=((idx + 1) == total), last_of=clast_of, +                    get_full_hierarchy=get_full_hierarchy):                  lst.append(sub_child)          return lst      @classmethod      def _get_parent_types(cls, dct=None, instances=False, exclude=None, -                          default=None): +                          default=None, get_full_hierarchy=False):          if not dct:              dct = {}          if not exclude: @@ -944,8 +965,11 @@ class GeneralType(Cached, models.Model):                  else:                      item_id = item[0]                      yield item +                    if get_full_hierarchy: +                        get_full_hierarchy = item[1]                  for child in cls._get_childs( -                        item_id, child_list, instances=instances): +                        item_id, child_list, instances=instances, +                        get_full_hierarchy=get_full_hierarchy):                      yield child      def save(self, *args, **kwargs): | 
