[Twisted-Python] Woven and nested database queries
![](https://secure.gravatar.com/avatar/3773e102dfc1340857b4db9552cde905.jpg?s=120&d=mm&r=g)
Hi, I'm new to the list and I'm just starting with Twisted and Woven. I think the framework is great, but I'm having some problems. When I try to make two nested <div>, both with independent queries, I get na error, the solution I've found is to create another model called "loaddata", which does nothing, except call the queries. If anyone knows a better way, I'd like to hear, I've searched all over the Internet, and found nothing that could help. Thanks in advance, Wenderson Teixeira Here is the minimum working code that exemplifies it: from twisted.web.resource import Resource from twisted.web.woven import page from twisted.web import microdom from twisted.enterprise import adbapi class A(page.Page): # When "loaddata" is not present, I get the following error: # exceptions.AttributeError: DeferredWidget instance has no attribute 'd' template = """ <html> <body> <div model="loaddata"/> <p>A</p> <div model="a"> <div view="Text"/> <p>B</p> <ul model="b" view="List"> <li pattern="listItem" view="Text" /> </ul> </div> </body> </html> """ def wmfactory_loaddata(self, request): self.runAQuery(request) self.runBQuery(request) return [] def wmfactory_a(self, request): return self.runAQuery(request) def wmfactory_b(self, request): return self.runBQuery(request) def runQuery(self, queryStr, attr, callback): if not hasattr(self, attr): dbpool = adbapi.ConnectionPool("pyPgSQL.PgSQL", "192.168.1.180::manesco_01:manesco") deferredQuery = dbpool.runQuery(queryStr) deferredQuery.addCallback(callback) dbpool.close() return deferredQuery return getattr(self, attr) def runAQuery(self, request): # Sample data #return [[1, 'Wenderson', 'WT', 2, 'Tex', None]] return self.runQuery("SELECT * FROM advogado WHERE id_adv=77", "aDataset", self.gotAResult) def runBQuery(self, request): # Sample data #return [ # [1, 'Advogado Sr.'], # [2, 'Advogado Pleno'], # [3, 'Advogado Jr.'], # [4, 'Estagiario'], # [5, 'Assist. Criatividade'], # [6, 'Empresario'], # [7, 'Departamento Pessoal'] #] return self.runQuery("SELECT * FROM categoria", "bDataset", self.gotBResult) def gotAResult(self, data): self.aDataset = data return data def gotBResult(self, data): self.bDataset = data return data resource = A(directory = "C:\inetpub\wwwroot\man")
![](https://secure.gravatar.com/avatar/3773e102dfc1340857b4db9552cde905.jpg?s=120&d=mm&r=g)
Thanks for your reply, but I tested and that doesn't seem to work either. Tex -----Mensagem original----- De: twisted-python-admin@twistedmatrix.com [mailto:twisted-python-admin@twistedmatrix.com] Em nome de Tommi Virtanen Enviada em: sexta-feira, 28 de novembro de 2003 12:13 Para: twisted-python@twistedmatrix.com Assunto: Re: [Twisted-Python] Woven and nested database queries Wenderson Teixeira wrote:
Your problem is most likely Deferred models of which you need a submodel. Woven is buggy.
Try <ul model="./b" view="List">, that should work.
![](https://secure.gravatar.com/avatar/3773e102dfc1340857b4db9552cde905.jpg?s=120&d=mm&r=g)
Thanks for your reply, but I tested and that doesn't seem to work either. Tex -----Mensagem original----- De: twisted-python-admin@twistedmatrix.com [mailto:twisted-python-admin@twistedmatrix.com] Em nome de Tommi Virtanen Enviada em: sexta-feira, 28 de novembro de 2003 12:13 Para: twisted-python@twistedmatrix.com Assunto: Re: [Twisted-Python] Woven and nested database queries Wenderson Teixeira wrote:
Your problem is most likely Deferred models of which you need a submodel. Woven is buggy.
Try <ul model="./b" view="List">, that should work.
participants (2)
-
Tommi Virtanen
-
Wenderson Teixeira