[Twisted-Python] Woven: access to submodels

Mary mary-twisted at puzzling.org
Fri Aug 8 18:43:35 MDT 2003


Replying to an old thread here, I work though my problems slowly...

On Sat, Jul 19, 2003, Donovan Preston wrote:
> So, fortunately, things may be simpler than they seem.  You can just
> pass the DeferredWrapper as the Main Model to the next Page instance
> you construct, and as long as you are going to be rendering that Page
> next, Woven will just wait on it as it would any other Deferred.

[some bits of code snipped]

> class DeferredProducer(model.MethodModel):
>     def wmfactory_someDeferred(self, reqeuest):
>         d = defer.Deferred()
>         reactor.callLater(0.5, self.produce, d)
>         return d
> 
>     def produce(self, d):
>         d.callback( "Hello, here is some text" )
> 
> class MainPage(page.Page):
>     template = """<html>
>     <h3 model="someNotDeferred" view="Text"> qawsf</h3>
>     <span model="someDeferred" view="Text"> qwensd</span>
> </html> """
> 
>     def getDynamicChild(self, name, request):
>         return ChildPage(
>                     self.model.getSubmodel(request, 'someDeferred'))
> 
> class ChildPage(page.Page):
>     template = """<html>
>     Hello! Our main model is a deferred, so the next node will have to 
> wait
>     <span model="." view="Text"> ncxnz</span>
> </html> """

Sorry, I'm not too familiar with the stages in which this gets sent to
the browser, but this code assumes that the ChildPage is always going to
exist.

In my blog model, obviously there are authors that don't exist. So
/author/Mary/ would be represented by a ChildPage Resource, but
/author/Donovan/ should 404. Is that possible in a code structure like
this, or is it too late to produce the appropriate error at the:
    <span model="." view="Text"> ncxnz</span>
stage, which is the first time Twisted Web needs to wait on our Deferred
main model?

-Mary




More information about the Twisted-Python mailing list