sifu ha scritto:
hmmmm... couldn't send it to the list.
---------- Forwarded message ----------
From: sifu <[EMAIL PROTECTED]>
To: "Twisted Web World" <[email protected]>
Date: Thu, 4 Jan 2007 13:28:46 +0100
Subject: Re: [Twisted-web] [Nevow] again on data directive
with the current nevow you can do:
<div n:render="yyy xxx" />
def render_yyy( self, argument ):
def _( ctx, data ):
assert argument == 'xxx'
return _
but some nevow developers don't like the feature and want to get rid of it.
The problem with the current implementation is that data directives are
handled by the Nevow rendering machinery (with object adaptation).
I'm proposing that data directive must be handled by the user.
Here is an example:
<ul n:render="list">
<li n:data="x" n:render="item" />
<li n:data="y" n:render="item />
</ul>
def render_list(request, tag):
request.data = {'x': 1, 'y': 2}
return tag
def render_item(request, tag):
item = request.data[tag.data]
return tag[item]
Without data directive I have to do:
<ul n:render="list">
<li n:pattern="x"><n:slot name="value" /></li>
<li n:pattern="y" /><n:slot name="value" /></li>
</ul>
def render_list(request, tag):
data = {'x': 1, 'y': 2}
for key, val in data.iteritems():
pat = tag.onePattern(key)
pat.fillSlots('value', val)
return tag
In this example, using only patterns and slots is easy (and I do not
have to store data on the request object), but I'm not sure this will be
the same with a more complex template.
I will try to do same tests.
Regards Manlio Perillo
_______________________________________________
Twisted-web mailing list
[email protected]
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web