diff options
author | Étienne Loks <etienne.loks@proxience.com> | 2015-12-13 17:16:06 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@proxience.com> | 2015-12-13 17:16:06 +0100 |
commit | 75b6812ebf861dd704f8801e6692d2266490d4bb (patch) | |
tree | eb0c268aefd7a8286639e026160e082c9f4b18a7 /ishtar_common | |
parent | 23cdeb61230cb552f77732dab5f7f9dae7c2aebd (diff) | |
download | Ishtar-75b6812ebf861dd704f8801e6692d2266490d4bb.tar.bz2 Ishtar-75b6812ebf861dd704f8801e6692d2266490d4bb.zip |
Improve hierarchical display
Diffstat (limited to 'ishtar_common')
-rw-r--r-- | ishtar_common/models.py | 41 | ||||
-rw-r--r-- | ishtar_common/static/media/admin.css | 11 |
2 files changed, 43 insertions, 9 deletions
diff --git a/ishtar_common/models.py b/ishtar_common/models.py index b5e371b25..48218ba94 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -337,10 +337,14 @@ class GeneralType(models.Model): yield (item.pk, _(unicode(item)) if item and unicode(item) else '') - PREFIX = "› " + PREFIX = "│ " + PREFIX_EMPTY = " " + PREFIX_MEDIUM = "├ " + PREFIX_LAST = "└ " @classmethod - def _get_childs(cls, item, dct, prefix=0, instances=False, exclude=[]): + def _get_childs(cls, item, dct, prefix=0, instances=False, exclude=[], + is_last=False): prefix += 1 dct['parent'] = item childs = cls.objects.filter(**dct) @@ -348,16 +352,35 @@ class GeneralType(models.Model): childs = childs.exclude(txt_idx__in=exclude) if hasattr(cls, 'order'): childs = childs.order_by('order') - for child in childs.all(): + lst = [] + child_lst = childs.all() + total = len(child_lst) + for idx, child in enumerate(child_lst): if instances: child.rank = prefix - yield child + lst.append(child) else: - yield (child.pk, SafeUnicode(prefix * cls.PREFIX + - unicode(_(unicode(child))))) - for sub_child in cls._get_childs(child, dct, prefix, instances, - exclude=exclude): - yield sub_child + 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: + p += cls.PREFIX_EMPTY + else: + p += cls.PREFIX + lst.append(( + child.pk, SafeUnicode(p + unicode(_(unicode(child)))) + )) + for sub_child in cls._get_childs( + child, dct, prefix, instances, exclude=exclude, + is_last=((idx + 1) == total)): + lst.append(sub_child) + return lst @classmethod def _get_parent_types(cls, dct={}, instances=False, exclude=[], diff --git a/ishtar_common/static/media/admin.css b/ishtar_common/static/media/admin.css new file mode 100644 index 000000000..8b4ed7aa7 --- /dev/null +++ b/ishtar_common/static/media/admin.css @@ -0,0 +1,11 @@ +.selector{ + width: 1160px; +} + +.selector-available, .selector-chosen { + width: 540px; +} + +.selector select { + width: 540px; +} |