File: simple.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 (36 lines) | stat: -rw-r--r-- 1,044 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
from nevow import inevow
from nevow import loaders
from nevow import rend

from nevow import tags as T

class Simple(rend.Page):
    
    addSlash = True

    def render_theTitle(self, context, data):
        return [x * 5 for x in "title"]

    def render_sample(self, context, data):
        request = inevow.IRequest(context)
        session = inevow.ISession(context)
        count = getattr(session, 'count', 1)
        session.count = count + 1
        return ["Welcome, person from ", request.client.host, "! You are using ",
            request.getHeader('user-agent'), " and have been here ", 
            T.span(id="count")[count], " times."]

    def child_reset(self, context):
        inevow.ISession(context).count = 1
        return '<html><body><span id="reset">Count reset</span></body></html>'

    docFactory = loaders.stan(
        T.html[
            T.head[
                T.title[render_theTitle]
            ],
            T.body[
                T.h1["Hello."],
                render_sample,
            ]
        ])