[Twisted-Python] Woven: access to submodels

Moshe Zadka m at moshez.org
Sun Jul 13 06:04:03 EDT 2003

On Sun, 13 Jul 2003, Mary <mary-twisted at puzzling.org> wrote:

>  1. Pure design issue: There still needs to be a query along the lines
>  of "does this author in fact exist?" so that /author/Mary/ generates a
>  list of my articles and /author/Humphrey/ generates an error page. This
>  was the query I was trying to avoid by passing the submodel around --
>  the "get me all posts by Mary" query was always going to be part of
>  IndividualPage.

Ah, I see. Well, a somewhat thorny issue in current web code [that
we may fix someday in the future, but you're not interested in that]
is that child-getting is synchronous. This means that an easy answer
is currently beyond us. A non-easy way to do that is to hack around:

from twisted.web import resource, server

class MaybeIndividualPage(resource.Resource):

    isLeaf = 1

    def __init__(self, author):
        self.author = author

    def render(self, request):
        def raiseException():
            raise LookupError
        def simulateServer(value):
            if value == server.NOT_DONE_YET:
        query = deferredWhichIsTrueIfExists(self.author).addCallback(
        lambda x: (x or error.NoResource()) and
        return server.NOT_DONE_YET

Then, in getDynamicChild, return MaybeIndividualPage(author) instead
of IndividualPage(author).

Basically, this is explicitly asyncing the child-getting mechanism
by going through the async-ready render method. I realize it's not
the best-looking code in the world, but it should get the job done.

>  2. More generally, since I'm unfamiliar with the design pattern(s)
>  associated with Woven, what level of information sharing in this sense
>  is acceptable between parents and children? (Pointers to other sources
>  of information would be welcome, since this question is pretty open
>  ended)?

Well, we don't have any real understanding of this issue either, since
Woven is not old enough. My gut instinct would be towards "pretty high",

Moshe Zadka -- http://moshez.org/
Buffy: I don't like you hanging out with someone that... short.
Riley: Yeah, a lot of young people nowadays are experimenting with shortness.
Agile Programming Language -- http://www.python.org/

More information about the Twisted-Python mailing list