Source

pyconjp2011 / wtforms / pyconjp2011 / wtforms_demo / __init__.py

Full commit
import os
from webob import Request, Response
from webob.dec import wsgify
from sqlalchemy import engine_from_config
from mako.lookup import TemplateLookup
import wtforms
from wtforms.ext.sqlalchemy.fields import QuerySelectMultipleField

from .. import models

here = os.path.dirname(__file__)
templates_dir = os.path.join(here, "templates")

templates = TemplateLookup(directories=[templates_dir])

class UserForm(wtforms.Form):
    username = wtforms.TextField('User Name')
    password = wtforms.PasswordField('Password')
    user_image = wtforms.FileField('User Image')
    groups = QuerySelectMultipleField(query_factory=lambda: models.DBSession.query(models.Group))

@wsgify
def index(request):
    user_form = UserForm()
    tmpl = templates.get_template('index.mak')
    return Response(tmpl.render(form=user_form))


def main(global_conf, **settings):
    engine = engine_from_config(settings)
    models.init_db(engine)
    application = index
    
    return application