コード例 #1
0
ファイル: Formexampe.py プロジェクト: Ely-S/Pyterodactyl
from pytero import app, processor, formview, Run, Jinja, FormError
from wtforms import Form
from wtforms.fields import TextField, PasswordField
from wtforms.validators import Required
J=Jinja(".")


class Login(Form):
    username = TextField("Username", [Required()])
    password = PasswordField("Password", [Required()])
    method="POST"


class bob:

    @formview(Login)
    def GET(self, f):
        return J.forms(form=f, action='/')

    @processor(Login)
    def POST(self, form):
        if form.username.data!=u"bob" or form.password.data !=u"abc123":
            raise FormError({"username & password": ["Invalid Combo"]})
        return 'welcomebob'

urls=['/$', bob]
a=app(urls, debug=True)

if __name__=="__main__":
    Run(a)
コード例 #2
0

class Bob:

    @formview(SForm)
    def GET(self, f):
        if hasattr(f, 'errors'):
            return """
            errors:<br/>%s
            <form method='post'>
            <input name='bob'><input type='submit'>
            </form>
            """ % reduce(lambda i, o: i + "<br/>" + o, f.errors)
        else:
            return"""
                <form method='post'>
                <input name='bob'><input type='submit'>
                </form>
                """

    @processor(SForm)
    def POST(self, f):
        if f.bob!=u"bob":
            raise FormError(["nice try", "you're not bob"])
        return "Hello Bob"

a=app(['/$', Bob], debug=True)

if __name__=="__main__":
    Run(a)