[Twisted-Python] again on nested sequence
Manlio Perillo
manlio_perillo at libero.it
Mon Jul 17 03:11:26 MDT 2006
Valentino Volonghi aka Dialtone ha scritto:
>
>
> On Sun, 16 Jul 2006 16:18:07 -0200, Manlio Perillo
> <manlio_perillo at libero.it> wrote:
>
> This is off topic here... Twisted-web is the list.
Sorry and thanks for the response.
> [...]
> <li n:pattern="item" n:render="control">
> # You call the render_control method on the IRenderer implementor which
> # is the Main instance this method fills 2 slots ctrl_label and ctrl_name.
> # every slot inside this <li> tag that has one of those 2 names will be
> # filled unless an inner tag fills one of those slots with a different
Thanks!
Nested slots "was" another of "obscure" points about nevow rendering
machinery.
However, I still want to do more tests on this.
> # value
> <label><n:slot name="ctrl_label"/>
>
> <select n:render="sequence" n:data="option_list">
> # Here you call IContainer(ctx).child('option_list')
> # IContainer(ctx) is what was returned at the beginning with
> # data_control_list.
> # That result of that call is a list and the IContainer adapter
> # for lists does position lookup.
> # __getitem__ for lists takes integers and since all the values
> # coming from the template are strings they have to be converted
> # to integers. The value coming is 'option_list' and this cannot
> # be converted to an integer. And thus the error.
> # The solution? Fairly simple, although it would have been
> better that,
> # after I explained how part of the rendering works, YOU tried
> to find
> # the solution, anyway I'll explain it :).
Ok.
Yesterday I read some old messages in the archive, so now I (hopefully)
understand better how data directives works.
Anyway thanks for your solutions, it is much simpler
(I have to modify how the query are done, dicts insteads of list).
> [...]
>
>
> The best solution is the following (NOT TESTED, but should work):
>
> class Main(rend.Page):
> docFactory = loaders.xmlfile('nested.xhtml')
> def data_control_list(self, ctx, data):
> return [{'ctrl_name': 'a',
> 'ctrl_label': 'first',
> 'option_list': {'opt_value': '1',
> 'opt_label': 'uno'}
> },
> {'ctrl_name': 'b',
> 'ctrl_label': 'second',
> 'option_list': {'opt_value': '2',
> 'opt_label': 'second'}
> }]
>
>
Actually option_list is a list of dicts:
def data_control_list(self, ctx, data):
option_list = [
{'opt_value': '1',
'opt_label': 'uno'
},
{'opt_value': '2',
'opt_label': 'due'
}
]
return [{'ctrl_name': 'a',
'ctrl_label': 'first',
'option_list': option_list
},
{'ctrl_name': 'b',
'ctrl_label': 'second',
'option_list': option_list
}]
> [...]
> <select>
> <n:attr name="name"><n:slot name="ctrl_name" /></n:attr>
> <nevow:invisible n:render="sequence" n:data="option_list">
> # Yes, I added the tag above because I'm unsure about the way
> # n:attr is dealt with when it is between the sequence render
> and
> # the patterns inside the sequence. This solution removes the
> # uncertainty. It's generally better to keep the slots filled
> # directly inside the interested renderer without crossing
> any other
> # special renderer tag like this template was doing.
I have tried without nevow:invisible and it seems to work.
> <option n:pattern="item" n:render="mapping">
> <n:attr name="label"><n:slot name="opt_label" /></n:attr>
> <n:attr name="value"><n:slot name="opt_value" /></n:attr>
> </option>
> </nevow:invisible>
> </select>
> </label>
> </li>
> </ul>
> </body>
> </html>
>
Thanks and regards Manlio Perillo
More information about the Twisted-Python
mailing list