Fwd: [Twisted-web] [Nevow] again on data directive

Manlio Perillo manlio_perillo at libero.it
Thu Jan 4 06:53:06 CST 2007

sifu ha scritto:
> hmmmm... couldn't send it to the list.
> ---------- Forwarded message ----------
> From: sifu <lists at 0xx0.net>
> To: "Twisted Web World" <twisted-web at twistedmatrix.com>
> 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  />

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>

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

More information about the Twisted-web mailing list