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 | dbfc67f0f44ad1cdc6fff1775102e6538847d9bc (patch) | |
| tree | eb0c268aefd7a8286639e026160e082c9f4b18a7 | |
| parent | 8164cc4e529c6114b3a6d13fb6e1ce730277ca6b (diff) | |
| download | Ishtar-dbfc67f0f44ad1cdc6fff1775102e6538847d9bc.tar.bz2 Ishtar-dbfc67f0f44ad1cdc6fff1775102e6538847d9bc.zip | |
Improve hierarchical display
| -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; +} | 
