Source

pyptug / webpy / forms / fo3.py

Full commit
#!/usr/bin/env python

import time
import web


class Redirect:

    def GET(self):
        web.seeother('/scan')


class ServerTime:

    def GET(self):
        timeStr = time.strftime("%H:%M:%S")  # obtains current time
        return timeStr


class ScanMember:

    def __init__(self):
        self.my_form = web.form.Form(
            web.form.Textbox('', class_='textfield', id='textfield'),
            description="Scan your badge",
        )
        self.render = web.template.render('templates/', base='base')

    def member_info(self, string):
        """ this would come from a database """
        if string == '0001':
            information = """Francois Dion<br />
            Founder of PYPTUG<br />
            francois.dion@gmail.com"""
        else:
            information = "Not a valid member id"
        return information

    def GET(self):
        form = self.my_form()
        return self.render.scan(
            form,
            "Member information will appear here."
        )

    def POST(self):
        form = self.my_form()
        if not form.validates():
            return self.render.scan(
                form,
                "Member information will appear here."
            )
        s = form.value['textfield']
        return self.member_info(s)

URLS = ('/', Redirect,
        '/scan', ScanMember,
        '/time', ServerTime)

if __name__ == '__main__':
    app = web.application(URLS, globals())
    app.run()