[Twisted-Python] again on nested sequence

Manlio Perillo manlio_perillo at libero.it
Mon Jul 17 05:40:28 EDT 2006

Manlio Perillo ha scritto:
> 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. 

I have Cc to twisted-web, hoping this will help the archiving.


Just for future reference, here is an alternate solution.
It contains more code, but it is more database friendly
(and I like this - better performance too?).

It also contains some correction for the HTML code.

<!DOCTYPE html
  PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<html xmlns="http://www.w3.org/1999/xhtml"
      lang="it" xml:lang="it">
    <title>Nested sequence II</title>
    <form action="post" method="post">
      <ul n:render="sequence" n:data="control_list">
        <li n:pattern="item" n:render="control">
          <label><n:slot name="ctrl_label"/>
            <select n:render="option_list">
              <n:attr name="name"><n:slot name="ctrl_name" /></n:attr>
              <option n:pattern="item" n:render="option">
                  <n:attr name="value"><n:slot name="opt_value" /></n:attr>
                  <n:slot name="opt_label" />
      <input type="submit" value="send" />

class Main(rend.Page):
    addSlash = True
    docFactory = loaders.xmlfile('nestedsequence.xhtml')

    def data_control_list(self, ctx, data):
        return [('a', 'first'),  ('b', 'second')]

    def render_option_list(self, ctx, data):
        option_list = [('1', 'uno'), ('2', 'due')]
        tag = ctx.tag

        pattern = inevow.IQ(ctx).patternGenerator("item")
        content = [pattern(data=option) for option in option_list]

        return ctx.tag.clear()[content]

    def render_control(self, ctx, data):
        print '*', data
        ctx.fillSlots('ctrl_label', data[1])
        ctx.fillSlots('ctrl_name', data[0])

        return ctx.tag

    def render_option(self, ctx, data):
        ctx.fillSlots('opt_label', data[1])
        ctx.fillSlots('opt_value', data[0])

        return ctx

Maybe it is not reusable as the previous solution, but it's not a problem.

Regards  Manlio Perillo

More information about the Twisted-Python mailing list