[Twisted-web] newbie: Stan syntax question

Tommi Virtanen tv at twistedmatrix.com
Tue Dec 14 14:00:59 MST 2004


Mohamed Lrhazi wrote:

> How do you build a table dynamically, or any other stan structure for 
> that matter? Here is what I am trying to do:
>
> def render_tasks(self, context, data):       
>         attrs = ['task_id', 'task', 'arguments']
>         mytrs=T.tr
>         for row in self.tasklist:
>             for attr in attrs:
>                 mytrs += T.td[row.get(attr)]
>         header_tr=T.tr[T.th["ID"],T.th["Task"],T.th["Arguments"]]
>         mytable=T.table[header_tr,(mytrs)]
>         return context.tag[mytable]

stanTag[foo] mutates the tag, adding foo as child. So something like..

def render_tasks(self, context, data):       
        attrs = ['task_id', 'task', 'arguments']
        mytable = T.table[T.tr[T.th["ID"],T.th["Task"],T.th["Arguments"]]]
        for row in self.tasklist:
            mytr = T.tr()
            mytable[mytr]
            for attr in attrs:
                mytr[T.td[row.get(attr)]]
        return context.tag[mytable]




More information about the Twisted-web mailing list