Nevermind that - I figured out that the sequence renderer only returns those tags that have either "pattern" or "render" specials, so it seems to randomly loose stuff.

A. Goryunov wrote:
I've noticed that Page.renderString() "swallows" some of the stan nodes. I've also tried the example below in an actual Twisted service and got the same result. Doing it with an XML template also yields erroneous output. Namely, it looses "table", "tr", a couple of "td" tags were MIA too I believe, as well as two "input"s.

The code I was using for testing is attached. It's supposed to be a library of widgets that are constructed using Fragments and render_sequence.

------------------------------------------------------------------------

from nevow import tags as T
from nevow import flat, rend, loaders




class TestPage(rend.Page):
    docFactory = loaders.stan(
        T.html[
            T.body[
                T.invisible(render=T.directive("widget"))[
                    T.invisible(pattern="widget_name")['PortalContent'],
                    T.invisible(pattern="widget_slot")['main_content'],
                    T.invisible(pattern="widget_slot")[
                        T.invisible(render=T.directive("widget"))[
                            T.invisible(pattern="widget_name")['PortalBarVert'],
                            T.invisible(pattern="widget_slot")[
                                T.invisible(render=T.directive("widget"))[
                                    
T.invisible(pattern="widget_name")['LoginForm'],
                                    T.invisible(pattern="widget_slot")['Sign 
in'],
                                    T.invisible(pattern="widget_slot")['User: 
'],
                                    
T.invisible(pattern="widget_slot")['Password: '],
                                    T.invisible(pattern="widget_slot")[T.input(type="submit", 
name="null", value="Submit")]
                                ]
                            ]
                        ]
                    ]
                ]
            ]])

    def render_widget(self,ctx,data):
        wName = ctx.tag.onePattern("widget_name").children[0].strip('\n\t ')
        attrs = ctx.tag.allPatterns("widget_slot")
        args = []
        for attr in attrs:
            args.append(T.xml(attr.children))
        try:
            wdgt = globals()[wName](args)
            return ctx.tag[wdgt]
        except IndexError:
            return ctx.tag[T.p(style="font-color : red")["Unknown widget name: 
%s" % wName]]
class LoginForm(rend.Fragment):
    docFactory = loaders.stan(
        T.div(class_="login-form", render=T.directive("sequence"))[
            T.p(class_="small-form-title", pattern="item", 
render=T.directive('arg')),
            T.form(action="_submit", method="post")[
                T.table(id="login-form-table")[
                    T.tr[
                        T.td(align="right")[
                            T.label(for_="user", pattern="item", 
render=T.directive('arg'))
                            ],
                        T.td(align="left")[
                            T.input(type="text", name="user",
                                    class_="login-input")
                            ]
                        ],
                    T.tr[
                        T.td(align="right")[
                            T.label(for_="pass", pattern="item", 
render=T.directive('arg'))
                            ],
                        T.td(align="left")[
                            T.input(type="password", name="pass",
                                    class_="login-input")
                            ]
                        ],
                    T.tr[T.td(colspan="2")],
                    T.tr[
                        T.td(colspan="2", align="center", pattern="item", 
render=T.directive('arg'))
                        ]
                    ]
                ]
            ])

    def render_arg(self,ctx,data):
        return ctx.tag[data]

class PortalContent(rend.Fragment):
    docFactory = loaders.stan(
        T.table(id="portal-content", render=T.directive("sequence"))[
            T.tr[
                T.td(class_="portal-content-main", pattern='item', 
render=T.directive('arg')),
                T.td(class_="portal-content-sidebar", id="portal-sidebar-right",
                     pattern="item", render=T.directive("arg"))
                ]
            ])

    def render_arg(self,ctx,data):
        return ctx.tag[data]
class PortalBarVert(rend.Fragment):
    docFactory = loaders.stan(
        T.table(class_="portal-bar-vertical", render=T.directive('sequence'))[
            T.tr(pattern='item', render=T.directive('arg'))
            ])

    def render_arg(self,ctx,data):
        return ctx.tag[T.td(class_='vert-sidebar-slot')[data]]



page = TestPage()
df = page.renderString()
def printPage(result):
    print result

def printErr(err):
    print err
df.addCallback(printPage)
df.addErrback(printErr)
------------------------------------------------------------------------

_______________________________________________
Twisted-web mailing list
[email protected]
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web

_______________________________________________
Twisted-web mailing list
[email protected]
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web

Reply via email to