[Twisted-Python] Woven and nested database queries
Wenderson Teixeira
wenderson at casadosprogramadores.com.br
Fri Nov 28 04:41:21 MST 2003
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")
More information about the Twisted-Python
mailing list