[Twisted-web] appropriate way to use patternGenerator
Carl Shimer
carl at clingfire.net
Mon May 9 09:43:08 MDT 2005
Ok... I think I understand this issue a bit better. I am deriving most of
my work in this area from the chatola example. In chatola the pattern is
created at object initialization time (which won't work in my scenario).
The pattern needs to be used in the server side handler that is invoked by
the client javascript. Excerpt from my class:
def on_submit(self,client,inputname,inputtags):
# THIS IS THE HACK RIGHT here
self.locelpattern
=inevow.IQ(self._maincontentimpl(None,None)).patternGenerator('loc_el')
# slot filling time
client.append('placecontent',self.locelpattern.fillSlots('foobar',inputname)
.fillSlots('foobaz',inputtags))
#client.sendScript("focusInput();")
def render_input(self,ctx,data):
return ctx.tag(onsubmit=livepage.handler(self.on_submit,
getValue('inputname'),getValue('inputtags')))
My solution (based on your comments):
1) put a method in the stan tree prior to the set of tags that I want to
generate a pattern for
2) store the pattern on the object for later use by on_submit.
def render_pattern(self,ctx,data):
self.locelpattern = inevow.IQ(ctx).patternGenerator('loc_el')
return ''
excepts from the stan tree:
T.div(_id='content')[
self.render_pattern,
T.div(pattern='loc_el',_pattern='loc_el')[
T.div(_class='row')[
T.span[T.slot(name='foobar')],T.span[T.slot(name='foobaz')]
]
-----Original Message-----
From: twisted-web-bounces at twistedmatrix.com
[mailto:twisted-web-bounces at twistedmatrix.com] On Behalf Of James Y Knight
Sent: Monday, May 09, 2005 9:36 AM
To: Discussion of twisted.web, Nevow,and Woven
Subject: Re: [Twisted-web] appropriate way to use patternGenerator
On May 8, 2005, at 6:31 PM, Carl Shimer wrote:
> I spent the last couple of hours trying to get the nevow LivePage
> stuff to
> work. The problem was on this line of my code:
>
> Inevow.IQ(self.docFactory).patternGenerator('foo')
>
It sounds like you're doing things the hard way, but I don't quite
understand your description of what you want to do -- it's a bit too
abstract for me. Patterns are designed for use by the immediately
enclosing renderer, so they operate on the unrendered tree, not the
rendered tree.
This is how most pattern uses look. A renderer which uses them,
immediately enclosing the patterns themselves.
def render_boolean(self, ctx, data):
return IQ(ctx).allPatterns(data and 'true' or 'false')
<div n:data="foo" n:render="boolean">
<span n:pattern="true">True!</span>
<span n:pattern="false">False!</span>
</div>
Perhaps your use case would be better served by filling slots?
James
_______________________________________________
Twisted-web mailing list
Twisted-web at twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-web/attachments/20050509/c7a51d50/attachment.htm
More information about the Twisted-web
mailing list