Yeah, I had a type, temp should have been uspan. it's not meant to be "coorrect" tho, just give an idea of what I am after. Again, thanks for the suggestions. As always, they are appreciated.
-C On Wed, Jun 17, 2009 at 6:47 AM, Corey Kovacs <[email protected]>wrote: > Thanks Uwe and Diez, I'll give these suggestions a go.. > > -C > > > On Wed, Jun 17, 2009 at 6:38 AM, Diez B. Roggisch <[email protected]> wrote: > >> >> Corey Kovacs schrieb: >> > I am trying create a representation of a computer rack using genshi in >> > TG2. What I am trying to do is >> > loop through the rack elevations and when I find an elevation where a >> > host belongs, I want to add some >> > data to show a host is at that spot. Thats the easy part. I also want to >> > modify the rowspan for the <td> >> > element so that the host <td> spans the appropriate number of elevations >> > to show the vertical size of >> > the machine. >> > >> > I've done this using PHP but have long since decided to rewrite my >> > project in Python/TG. Now I am >> > finding that i am somewhat limited in what i can achieve with immutable >> > variables. >> > >> > Basically, I need this.. >> > >> > temp=0 >> > print "<TABLE>" >> > print "<TR><TD>row</TD><TD>rack.rackid</TD><TD>row</TD></TR>" >> > for(row=1; row<43; row++) >> > for host in hostlist: >> > if host.elevation == row: >> > uspan = host.height-1 >> > print "<TR><TD>row</TD><TD >> > rowspan=uspan>host.hostname</TD><TD>row</TD></TR>" >> > while temp > 0 : >> > row++ >> > print "<TR><TD>row</TD><TD>row</TD></TR>" >> > uspan-- >> > else >> > print "<TR><TD>row</TD><TD></TD><TD>row</TD></TR>" >> > >> > print "<TR><TD>row</TD><TD>PDU</TD><TD>row</TD></TR>" >> > print "<TR><TD>row</TD><TD>PDU</TD><TD>row</TD></TR>" >> > >> > >> > The above (really ugly) pseudo-code mashup tries to explain it >> >> I guess there is an error in there, the temp-variable is never set. But >> I guess you could ditch it & use >> >> while uspan: >> ... >> >> >> Now in genshi, one does this via pre-computation of the rowlist. >> Essentially, you extract your logic to create a data-structure that fits >> your needs. You can do this in your controller (I don't see anything >> wrong with that, the MVC-pattern in webapps goes only so far), or inside >> a <?python-block. >> >> rows = [None] * 43 >> for host in hostlist: >> host_rows = [Bunch()] * host.height >> for row in host_rows: >> row.rowspan = None >> row.host = host # for template reference >> host_rows[0].rowspan = host.heighth - 1 >> rows[host.elevation:host.elevation + host.height] = host_rows >> >> >> Then in the template, you can do this: >> >> <table> >> <py:c py:strip="True" py:for="row in rows"> >> <tr py:if="not row">normal row without host</tr> >> <tr py:if="row and row.rowspan"><!-- first row with host --> >> </tr> >> <tr py:if="row and not row.rowspan"><!-- following host-rows --> >> </tr> >> </py:c> >> </table> >> >> >> >> Diez >> >> >> >> > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "TurboGears" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/turbogears?hl=en -~----------~----~----~----~------~----~------~--~---

