#!/usr/bin/env python from web import template, form, application, ctx from socket import gethostbyaddr urls = ( '/', 'index', '/neu.*', 'new', '/new.*', 'new', '/help/spam.*', 'spam', '/help/unsubscribe\.([a-z]+).*', 'unsubscribe', ) render = template.render('templates/', base='layout'); 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__": app = application(urls, globals(), autoreload=False) app.run()