-
-
Save kucerarichard/b1fdc1b6eb56717c6496e61a7f1dda00 to your computer and use it in GitHub Desktop.
Test TurboGears request.validation in minimal mode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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