File: nestedsequence.py

package info (click to toggle)
nevow 0.9.31-3
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 2,804 kB
  • ctags: 4,921
  • sloc: python: 19,639; ansic: 136; sh: 53; xml: 42; makefile: 25; sql: 5
file content (40 lines) | stat: -rw-r--r-- 1,240 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from twisted.python.components import registerAdapter
from nevow import rend, loaders, tags as t, inevow, accessors

class Edge(object):
    pass

class Vertex(object):
    def __init__(self, name):
        self.name = name
        self.edges = []

v1 = Vertex('v1')
v2 = Vertex('v2')
v3 = Vertex('v3')
v1.edges = [Edge(), Edge(), Edge(), Edge()]
v2.edges = [Edge(), Edge(), Edge(), Edge()]
v3.edges = [Edge(), Edge(), Edge(), Edge()]

class Root(rend.Page):
    addSlash = True
    docFactory = loaders.stan(
        t.html[
            t.head[t.title["Nested Sequence"]],
            t.body[
                t.ul(data=t.directive("vertexes"), render=t.directive("sequence"))[
                    t.li(pattern="item")[
                        t.span(data=t.directive("name"), render=t.directive("string")),
                        t.ul(data=t.directive('edges'), render=t.directive("sequence"))[
                            t.li(pattern="item", render=t.directive("string"))
                            ]
                        ]
                    ]
                ]
            ]
        )
    
    def data_vertexes(self, ctx, data):
        return [v1, v2, v3]

registerAdapter(accessors.ObjectContainer, Vertex, inevow.IContainer)