Source

pyconjp2011 / tw2 / pyconjp2011 / tw2_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 tw2.core
import tw2.forms

from .. import models

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

templates = TemplateLookup(directories=[templates_dir])

class UserForm(tw2.forms.TableForm):
    user_name = tw2.forms.TextField(validator=tw2.core.Required)
    password = tw2.forms.PasswordField(validator=tw2.core.Required)
    user_image = tw2.forms.FileField()


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



from tw.api import make_middleware

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

    return application