Skip to content

Instantly share code, notes, and snippets.

@amol-
Created September 3, 2019 21:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save amol-/7656d4d60665b89f85087c57b5deaadb to your computer and use it in GitHub Desktop.
Save amol-/7656d4d60665b89f85087c57b5deaadb to your computer and use it in GitHub Desktop.
Test TurboGears request.validation in minimal mode
from wsgiref.simple_server import make_server
import tg
from tg import RestController, expose, validate, MinimalApplicationConfigurator
from formencode import validators
class RootController(RestController):
@expose('json')
@validate({"man":validators.String(not_empty=True), "pin":validators.String(not_empty=True), "sou":validators.String(not_empty=True), "win":validators.String(not_empty=True)})
def calc(self, **kw):
validation_status = tg.request.validation
errors = [{key: str(value)} for key, value in validation_status.errors.items()]
return dict(errors=errors)
# Configure a new minimal application with our root controller.
config = MinimalApplicationConfigurator()
config.update_blueprint({
'root_controller': RootController()
})
# Serve the newly configured web application.
print("Serving on port 8080...")
httpd = make_server('', 8080, config.make_wsgi_app())
httpd.serve_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment