[Twisted-web] [Nevow] nested sequence pattern

Manlio Perillo manlio_perillo at libero.it
Sat Jun 17 16:35:24 CDT 2006

Manlio Perillo ha scritto:
> Hi.
> I have an SQL Table like:
> letters, numbers
> A,      1
> A,      2
> A,      3
> B,      4
> B,      7
> C,      2
> I want to render it in a table like:
> [...]
> Is this possible with Nevow template? And how?

I have solved but I don't like the solution.

Only two question:

with this template

    <n:invisible n:render="table" n:data="theLetters">
        <tbody n:pattern="tbody" n:render="tbody"
          <tr n:pattern="header" n:render="header">
            <td scope="rowgroup"><n:slot name="letter" /></td>
          <tr n:pattern="row" n:render="row">
            <td><n:slot name="number" /></td>

1) Why I can access the "header" pattern from "table" render?
2) How can I use the "theNumbers" data directive?

my renderers are

def data_theLetters(self, ctx, data):
    return "SELECT DISTINCT letters FROM MyTable"

def render_table(self, ctx, data):
    tag = ctx.tag

    pattern = tag.patternGenerator("tbody")
    content = []
    for letter in data:
        numbers = """SELECT numbers FROM MyTable
                     WHERE letter = :letter"""
        content.append(pattern(data=(letter, numbers)))

    return ctx.tag.clear()[content]

def render_tbody(self, ctx, data):
     tag = ctx.tag

     header = tag.onePattern("header")(data = data[0])
     pattern = tag.patternGenerator("row")

     content = [pattern(data=row) for row in data[1]]

     return tag.clear()[header, content]

Thanks and regards   Manlio Perillo

More information about the Twisted-web mailing list