From 2d26023da0bc0929e748f3fa13deac12479003b9 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Sun, 9 Apr 2017 20:05:44 +0200 Subject: Fix hiearchical display of types --- ishtar_common/models.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 988254359..83cb25d46 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -568,7 +568,7 @@ class GeneralType(Cached, models.Model): @classmethod def _get_childs(cls, item, dct, prefix=0, instances=False, exclude=[], - is_last=False): + is_last=False, last_of=[]): prefix += 1 dct['parent'] = item childs = cls.objects.filter(**dct) @@ -580,6 +580,7 @@ class GeneralType(Cached, models.Model): child_lst = childs.all() total = len(child_lst) for idx, child in enumerate(child_lst): + mylast_of = last_of[:] if instances: child.rank = prefix lst.append(child) @@ -594,15 +595,24 @@ class GeneralType(Cached, models.Model): else: p += cls.PREFIX_MEDIUM elif is_last: - p += cls.PREFIX_EMPTY + if mylast_of: + clast = mylast_of.pop(0) + if clast: + p += cls.PREFIX_EMPTY + else: + p += cls.PREFIX + else: + p += cls.PREFIX_EMPTY else: p += cls.PREFIX lst.append(( child.pk, SafeUnicode(p + unicode(_(unicode(child)))) )) + clast_of = last_of[:] + clast_of.append(idx + 1 == total) for sub_child in cls._get_childs( child, dct, prefix, instances, exclude=exclude, - is_last=((idx + 1) == total)): + is_last=((idx + 1) == total), last_of=clast_of): lst.append(sub_child) return lst -- cgit v1.2.3