summaryrefslogtreecommitdiffstats
path: root/index.py
blob: 26351bb7110ffbf78f07f7f7b6bc9a06482f3bb9 (plain)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python

from socket import gethostbyaddr
from web import template, form, application, ctx, wsgi

urls = (
    r'/', 'index',
    r'/neu.*', 'new',
    r'/new.*', 'new',
    r'/help/spam.*', 'spam',
    r'/help/unsubscribe\.([a-z]+).*', 'unsubscribe',
)

render = template.render('templates/', base='layout');
app = application(urls, globals(), autoreload=False)


create_form = form.Form(
    form.Textbox('name',
                 form.notnull,
                 description = 'Name of your list'),
    form.Textbox('email',
                 form.notnull,
                 form.regexp('.*fu-berlin\.de', 'E-mail address should end with fu-berlin.de'),
                 description = 'Your E-mail address'),
    )

class index:
    def GET(self):
        return render.index()

class spam:
    def GET(self):
        return render.spam()

class unsubscribe:
    def GET(self, lang):
        if (lang.startswith('de')):
            return render.unsubscribe_de()
        else:
            return render.unsubscribe_en()

class new:
    def GET(self):
        form = create_form()
        user = {'ip': ctx.ip, 'host': gethostbyaddr(ctx.ip)[0]}
        return render.new(form, user)

    def POST(self):
        form  = create_form()
        user = {'ip': ctx.ip, 'host': gethostbyaddr(ctx.ip)[0]}
        if not form.validates():
            return render.new(form, user)
        else:
            return "Done."


if __name__ == "__main__":
    if ('--fastcgi' in sys.argv):
        wsgi.runwsgi = lambda func, addr=None: wsgi.runfcgi(func, addr)

    app.run()