From 3662a1f4b4769e3651fe381cd7beb8962072bfb0 Mon Sep 17 00:00:00 2001 From: josch Date: Mon, 18 Aug 2008 22:56:39 +0000 Subject: [PATCH] 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 --- trunk/yolanda/config/environment.py | 6 ++++-- trunk/yolanda/lib/base.py | 5 +---- trunk/yolanda/model/__init__.py | 11 +---------- trunk/yolanda/model/entities.py | 12 +++++------- 4 files changed, 11 insertions(+), 23 deletions(-) diff --git a/trunk/yolanda/config/environment.py b/trunk/yolanda/config/environment.py index 2c606da..71d2a70 100644 --- a/trunk/yolanda/config/environment.py +++ b/trunk/yolanda/config/environment.py @@ -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 diff --git a/trunk/yolanda/lib/base.py b/trunk/yolanda/lib/base.py index e4a034a..30d8654 100644 --- a/trunk/yolanda/lib/base.py +++ b/trunk/yolanda/lib/base.py @@ -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('_') \ diff --git a/trunk/yolanda/model/__init__.py b/trunk/yolanda/model/__init__.py index 2c524b7..b931e0d 100644 --- a/trunk/yolanda/model/__init__.py +++ b/trunk/yolanda/model/__init__.py @@ -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() diff --git a/trunk/yolanda/model/entities.py b/trunk/yolanda/model/entities.py index 117d1db..da30fd6 100644 --- a/trunk/yolanda/model/entities.py +++ b/trunk/yolanda/model/entities.py @@ -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))