File: simplehtml.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 (28 lines) | stat: -rw-r--r-- 1,001 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
from twisted.python import util

from nevow import inevow
from nevow import loaders
from nevow import rend
from nevow import tags

class Simple(rend.Page):    

    addSlash = True
    docFactory = loaders.xmlfile(util.sibpath(__file__, 'simplehtml.html'))

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

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