[Twisted-Python] Woven: access to submodels

Mary mary-twisted at puzzling.org
Sun Jul 13 03:12:42 MDT 2003


On Sun, Jul 13, 2003, Moshe Zadka wrote:
> On Sun, 13 Jul 2003, Mary <mary-twisted at puzzling.org> wrote:
> 
> >     def getDynamicChild(self, name, request):
> >         return IndividualPage(amodel=self.getSubmodel('authors')[name]))
> 
> Rar! You are very evil.
> Please do not reinvent SQL in Python: write *another* select query, that
> only selects posts from this author.

I have to anyway... the SELECT query you saw doesn't extract any posts
at all, it extracts the names of authors (posts.names -- plus a little
extraneous information) who have made posts.

So I take it that in this design the arguments to __init__/initialize of
child IndividualPage would be just the name of the author?

This leaves a few questions still:

 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.

 At present, my model does not have the IndividualPage make a query to
 this effect, it relies on its parent AuthorsPage to have accessed a
 list of all authors in the system (actually, the SELECT query given
 ignores authors who have made no posts, a deliberate choice).

 Should I have IndividualPage access this information itself? If not, I
 still continue to rely on the information presently accesible to
 AuthorsPage -- how should I make this information available to
 IndividualPage? (related to point 3). If I don't use the authors model,
 then I have to make an essentially identical query anyway. There's a
 few options about where I make the query, how many times I make it, and
 where I should store the results. And of course, where (and how) I pass
 a Deferred around.

 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)?

 3. (Generalisation of point 1.) To whatever extent it is even
 acceptable to share query results of some kind between parents and
 children (perhaps in the form of Models), what functions do I call in
 Woven to share the information? Should an object ever access its own
 sub-models?

-Mary




More information about the Twisted-Python mailing list