[Twisted-web] Re: [Twisted-Python] again on nested sequence

Valentino Volonghi aka Dialtone dialtone at divmod.com
Mon Jul 17 12:24:43 CDT 2006


On Mon, 17 Jul 2006 15:15:30 -0200, Manlio Perillo <manlio_perillo at libero.it> wrote:
>Here is another solution:

The following is NOT a solution for multiple reasons the main of which is that the context is going away and soon you won't be able to use this.

The second is that IData is not for external use but rather internal Nevow usage.

>class Main(rend.Page):
>    addSlash = True
>    docFactory = loaders.xmlfile('nestedsequence.xhtml')
>
>    def data_control_list(self, ctx, data):
>        print "data_control_list"
>
>        return [('a', 'first'),  ('b', 'second')]
>
>    def render_control(self, ctx, data):
>        print 'render_control'
>
>        ctx.fillSlots('ctrl_label', data[1])
>        ctx.fillSlots('ctrl_name', data[0])
>
>        option_list = [('1', 'uno'), ('2', 'due')]
>        ctx.remember(option_list, inevow.IData)
>
>        return ctx.tag
>
>    def render_option(self, ctx, data):
>        ctx.fillSlots('opt_label', data[1])
>        ctx.fillSlots('opt_value', data[0])
>
>        return ctx
>
>The template is the same, the only change is
>n:render="sequence" instead of
>n:render="option_list"
>in the <select> element.
>
>However there is a thing the I don't understand:
>why render_control is called two times?
>
>In my previous solution, both render_option_list and render_control are
> called two times.

I don't remember the template and thus I don't think I can be of any help here. But this way of coding is called 'being clever' and you'll regret it when you'll have to maintain that code or understand how the code actually works.



More information about the Twisted-web mailing list