added elixir simplicity - hope the sessions gets cleared automagically somehow

git-svn-id: http://yolanda.mister-muffin.de/svn@374 7eef14d0-6ed0-489d-bf55-20463b2d70db
main
josch 16 years ago
parent 6a851c384b
commit 3662a1f4b4

@ -8,7 +8,7 @@ import yolanda.lib.helpers
from yolanda.config.routing import make_map
from sqlalchemy import engine_from_config
from yolanda.model import init_model
from yolanda import model
def load_environment(global_conf, app_conf):
"""Configure the Pylons environment via the ``pylons.config``
@ -36,4 +36,6 @@ def load_environment(global_conf, app_conf):
# any Pylons config options)
engine = engine_from_config(config, 'sqlalchemy.')
init_model(engine)
model.metadata.bind = engine
model.metadata.bind.echo = True
model.Session.bind = engine

@ -23,10 +23,7 @@ class BaseController(WSGIController):
# the request is routed to. This routing information is
# available in environ['pylons.routes_dict']
response.headers['Content-type'] = "application/xml"
try:
return WSGIController.__call__(self, environ, start_response)
finally:
Session.remove()
return WSGIController.__call__(self, environ, start_response)
# Include the '_' function in the public names
__all__ = [__name for __name in locals().keys() if not __name.startswith('_') \

@ -1,20 +1,11 @@
from sqlalchemy.orm import scoped_session, sessionmaker
import elixir
# replace the elixir session with our own
Session = scoped_session(sessionmaker(autoflush=True, transactional=True))
elixir.session = Session
elixir.options_defaults.update({
'shortnames': True
})
Session = elixir.session(autoflush=True, transactional=True)
# use the elixir metadata
metadata = elixir.metadata
# this will be called in config/environment.py
def init_model(engine):
metadata.bind = engine
# import your entities, and set them up
from entities import *
elixir.setup_all()

@ -1,8 +1,6 @@
from elixir.entity import *
from elixir.fields import *
from sqlalchemy.types import *
from datetime import datetime
from elixir import *
class Person(Entity):
name = Field(Unicode(128))
birthdate = Field(DateTime, default=datetime.now)
class Video(Entity):
using_options(tablename='videos')
title = Field(Unicode(255))

Loading…
Cancel
Save