Speed up development with full-stack environments for every branch.

Learn More

TurboGears Form Validation with Action Buttons [Python]

Forked from TurboGears Forms Validation.

189 Runs 331 Views 134 Copies
Saved

Saved

amol 16

amol
published 4 years ago

from wsgiref.simple_server import make_server
from tg import TGController, AppConfig, expose, validate
from tw2.forms import TableForm, TextField, SubmitButton
from tw2.core import Validator
from datetime import date

class SaluteForm(TableForm):
    action = '/submit'
    
    name = TextField(label='Your Name', placeholder='John Doe',
                     validator=Validator(required=True))

    submit = None
    submit1 = SubmitButton(key='action', value='Greet', name='action')
    submit2 = SubmitButton(key='action', value='Hello', name='action')


class RootController(TGController):
  @expose('index.html')
  def index(self, **kw):
    return dict(form=SaluteForm)

  @expose('submit.html')
  @validate(SaluteForm, error_handler=index)
  def submit(self, action, name):
    return dict(action=action, name=name)
    
    
config = AppConfig(minimal=True, root_controller=RootController())
config.renderers = ['genshi']
config.use_toscawidgets2 = True

print "Serving on port 80..."
httpd = make_server('', 80, config.make_wsgi_app())
httpd.serve_forever()
Please login/signup to get access to the terminal.

Your session has timed out.

Dismiss (the page may not function properly).