Move tree node widget code to the widgets.py file and prettify a bit

This commit is contained in:
Roberto Rosario
2012-02-05 00:48:31 -04:00
parent 735d3db97a
commit 9c03663924
2 changed files with 20 additions and 6 deletions

View File

@@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from django.utils.safestring import mark_safe
#from django.utils.safestring import mark_safe
from django.utils.html import conditional_escape, mark_safe
from .models import IndexInstanceNode
@@ -71,3 +73,18 @@ def get_breadcrumbs(index_instance, simple=False, single_link=False, include_cou
else:
output.insert(0, u' / '.join(result))
return mark_safe(u' '.join(output))
def node_level(x):
"""
Render an indented tree like output for a specific node
"""
return mark_safe(
u''.join(
[
u'     ' * (getattr(x, x._mptt_meta.level_attr) - 1),
u'' if x.parent else u'',
unicode(x if x.parent else 'root')
]
)
)