Move tree node widget code to the widgets.py file and prettify a bit
This commit is contained in:
@@ -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')
|
||||
]
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user