aMa
aMa

Reputation: 649

Is there any better way to display ete2 Tree in Django template?

I am building a WebApplication using Django framework. At server side I am building ete2 tree according to the input given by user using browser. Now my problem is I need to display this tree in client side (browser) in tree format with each node as a hyperlink (clicking on nodes displayed in tree format should invoke a function at server side passing node name as parameter, that why I mentioned it as hyperlink).

one solution came to my mind is parse the ete2.tree in views function and build a string with all html tags needed which at display on browser looks like the following.

             + root
               + child1
                   + grandson
               + child2

Code to do this: from ete2 import Tree

def display_view(request):
      global tree
      string = tree2str(tree)
      return render_to_response('index.html', {'string': string} )

def tree2strtr():
  global tree
  tmp = ''
  for node in tree.traverse():
    if node.name != 'NoName':
      tmp += '<a href="/process/?objectName=%s">%s</a>' % (node.name, node.name)
      tmp += '</br>'
  return tmp

Is there a better way to do that ? Any suggestions please..

Upvotes: 2

Views: 169

Answers (0)

Related Questions