Source

pyconjp2011 / formalchemy / pyconjp2011 / formalchemy_demo / __init__.py

import os
from webob import Request, Response
from webob.dec import wsgify
from sqlalchemy import engine_from_config
from mako.lookup import TemplateLookup
from formalchemy import FieldSet
from formalchemy import Field
from formalchemy import fields

from .. import models

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

templates = TemplateLookup(directories=[templates_dir])

user_form = FieldSet(models.User, models.DBSession)
user_form.append(Field(name='user_image').with_renderer(fields.FileFieldRenderer))

@wsgify
def index(request):
    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