Hi all, first time poster, beginner Django user.

RIght now, I'm trying to build a page that telnets into two or more
switches, gathers the data from each switch, and puts the information
into a palatable form.  I managed to get the information into a format
that I think is acceptable; a list of dictionaries that have
dictionaries with lists in them.

Here is a very slimmed down version of it, as the original would fill
too much space:

switch_info = [{'Router':[{'module':'1', 'type':'RJ45', 'av_ports':
[{'port':'fa1/1', 'duplex':'auto'}, {'port':'fa1/2',
'duplex':'auto'}]}, {'module':'2', 'type':'RJ45', 'av_ports':
[{'port':'fa2/1', 'duplex':'auto'}, {'port':'fa2/2',
'duplex':'auto'}]}]}, {'Switch':[{'module':'1', 'type':'RJ45',
'av_ports':[{'port':'fa1/1', 'duplex':'full'}, {'port':'fa1/2',
'duplex':'auto'}]}, {'module':'2', 'type':'RJ45', 'av_ports':
[{'port':'fa2/1', 'duplex':'auto'}, {'port':'fa2/2',
'duplex':'auto'}]}]}]

If you were to organize that better, you'd see that there are two
dictionaries within a list, Router and Switch.  Each of those
dictionaries have a list of two dictionaries, comprised of module
information.  And THOSE module dictionaries have a key that has a list
of information for each port.  Rather complex, as you can see.

However, I want to use a treeview script that yahoo provides, and in
order to get all that information into the script, I will have to use
for loops.

I've gotten far enough to the point that the port information and
module information branch out correctly, but the two roots of the tree
are a problem.  The roots are supposed to be the keys, Router and
Switch.  However, all I've gotten so far is the actual dictionaries.
So, I want it to look like this:

###############################
-Router
|    |
|    -1, RJ45
|     |    |
|     |    -fa1/1, auto
|     |    |
|     |    -fa1/2, auto
|     |
|     +2, RJ45
|
+Switch

Instead, it looks like this:

-{'Router': [{'av_ports': [{'duplex': 'auto', 'port': 'fa1/1'},
{'duplex': 'auto', 'port': 'fa1/2'}], 'type': 'RJ45', 'module': '1'},
{'av_ports': [{'duplex': 'auto', 'port': 'fa2/1'}, {'duplex': 'auto',
'port': 'fa2/2'}], 'type': 'RJ45', 'module': '2'}]}
|       |
|       1, RJ45
|        |   |
|        |   |
|        |   fa1/1, auto
|        |   |
|        |   |
|        |   fa1/2, auto
|        |
|        2, RJ45
|
+{'Switch': [{'av_ports': [{'duplex': 'full', 'port': 'fa1/1'},
{'duplex': 'auto', 'port': 'fa1/2'}], 'type': 'RJ45', 'module': '1'},
{'av_ports': [{'duplex': 'auto', 'port': 'fa2/1'}, {'duplex': 'auto',
'port': 'fa2/2'}], 'type': 'RJ45', 'module': '2'}]}

##################################
And here's the code within the template:

#################################
The code for the javascript tree can be found here:

http://developer.yahoo.com/yui/treeview/

var tree;
function treeInit() {
   tree = new YAHOO.widget.TreeView("treeDiv1");
   var root = tree.getRoot();
   {% for switches in switch_info %}
   var tmpNode = new YAHOO.widget.TextNode("{{switches|}}", root,
false);
   {% for row in switches.Router %}
   var tmpNode1 = new YAHOO.widget.TextNode("{{row.module}},
{{row.type}}", tmpNode, false);

   {% for item in row.av_ports %}
   var tmpNode2 = new YAHOO.widget.TextNode("{{item.port}},
{{item.duplex}}", tmpNode1, false);
   {% endfor %}
   {% endfor %}
   {% for row in switches.Switch %}
   var tmpNode1 = new YAHOO.widget.TextNode("{{row.module}},
{{row.type}}", tmpNode, false);

   {% for item in row.av_ports %}
   var tmpNode2 = new YAHOO.widget.TextNode("{{item.port}},
{{item.duplex}}", tmpNode1, false);
   {% endfor %}
   {% endfor %}
   {% endfor %}
    tree.draw();
###############################

Is there any possible way to have the first loop just display the key?


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to