Source

pyconjp2011 / sprox / pyconjp2011 / sprox_demo / __init__.py

Full commit
import os
from webob import Request, Response
from webob.dec import wsgify
from sqlalchemy import engine_from_config
from sprox.formbase import AddRecordForm
from mako.lookup import TemplateLookup
import tw.forms

from .. import models

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

templates = TemplateLookup(directories=[templates_dir])

class UserForm(AddRecordForm):
    __model__ = models.User
    user_image = tw.forms.FileField('user_image')

user_form = UserForm(models.DBSession)

@wsgify
def index(request):
    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
    application = make_middleware(application, {
        'toscawidgets.framework.default_view': 'mako',
        'toscawidgets.middleware.inject_resources': True,
    }, stack_registry=True)
    
    return application