[Twisted-Python] t.w.w.form maybe bug?
Alessandro Praduroux
pradu at pradu.it
Tue Jul 22 10:48:07 MDT 2003
Hello,
I am trying to create a page with a list of elements that can be possibly
edited by the user, along with a form to edit the elements or insert new
ones.
So, I setup the things as follows:
class Test(page.Page)
template = """
<html>
<head></head>
<body>
<table border="1" cellpadding="2" width="80%" model="configs"
view="List">
<tr
pattern="listHeader"><th> </th><th>Nome</th><th>Limiti</th><th>Bilanciamento</th></tr>
<tr pattern="listItem" view="conf"></tr>
</table>
<div><form method="POST" action="/balancing/edit"
model="editform"></form></div>
</body>
</html>
"""
def wmfactory_configs(self, request):
cf = libra.RouteConfig()
return cf.configurations()
def wmfactory_editform(self, request):
return self._form
def wchild_edit(self, request):
fp = form.FormProcessor(self._form, callback=lambda x:
util.Redirect("/balancing"))
fp.mangle_timein = fp.mangle_multi
return fp
def wvupdate_conf(self, request, node, data):
r = microdom.lmx(node)
d = r.td()
d.a(href="/balancing/?action=edit&cfg=%s"%data[0]).text("Modifica")
d.br()
d.a(href="/balancing/?action=delete&cfg=%s"%data[0]).text("Elimina")
r.td().text(data[0])
((h0,m0,s0),(h1,m1,s1)) = data[1]["limit"]
r.td().text("dalle %02d:%02d:%02d alle
%02d:%02d:%02d"%(h0,m0,s0,h1,m1,s1))
bl = ["%s: %d%%"%(k,v) for (k,v) in data[1]["weights"]]
d = r.td()
for l in bl:
d.text(l)
d.br()
def setUp(self, request, d):
self._action = request.args.get("action",[""])[0]
if self._action == "delete":
cf = libra.RouteConfig()
cf.delCfg(request.args.get("cfg",[""])[0])
cf.save()
if self._action == "edit":
cf = libra.RouteConfig()
c = cf.getCfg(request.args.get("cfg",[""])[0])
args = [
fm.Hidden("action","edit"),
lw.Static("Nome",request.args.get("cfg",[""])[0]),
lw.Static("Dalle","%02d:%02d%02d"%c['limit'][0]),
lw.Static("Alle","%02d:%02d%02d"%c['limit'][1]),
]
for (k,v) in c["weights"]:
args.append(fm.String(k, str(v)))
cfs = fm.MethodSignature(*args)
self._form = cfs.method(self.processEdit)
else:
cfs = fm.MethodSignature(
fm.Hidden("action","new"),
fm.String("Nome"),
lw.Timein("Dalle",(00,00,00)),
lw.Timein("Alle",(23,59,59))
)
self._form = cfs.method(self.processEdit)
def processEdit(self,**kw):
if kw["action"] == "new":
print "new", kw
else:
print "edit", kw
one thing to notice: the page is not part of an .rpy, but it's added as child
of the root page using putChild
The first time the page is rendered, i get the form I espect (the second one
defined in setUp).
If I follow a link that should end up with the first form displayed, nothing
happens (better, I am presented with the same form again and again).
digging into t.w.w.form.FormFillerWidget, I notice the following (around line
280):
argList = self.model.fmethod.getArgs()
That means the widget is rendered using the model it was built with, not the
model that is passed in setUp(self, request, node, data)
Now the questions:
1. I am doing things really wrong here?
2. the fact that the render-time model is completely ignored is by design or a
bug?
3. would changing the line above to read "argList = data.getArgs()" really
solve the issue (here it seems to work) or it will introduce some subtle bugs
I'm not aware of?
Thanks in advance for the help
--
Linux webmaster & sysadmin
pradu at pradu.it
More information about the Twisted-Python
mailing list