Turbogears 2 e Elixir
October 23, 2009 Programação, Python No CommentsPara se integrar o elixir no turbogears 2, basta editar o arquivo model/__init__.py do seu projeto para ficar desse jeito:
# -*- coding: utf-8 -*-
from zope.sqlalchemy import ZopeTransactionExtension
from sqlalchemy.orm import scoped_session, sessionmaker
from sqlalchemy.ext.declarative import declarative_base
import elixir
maker = sessionmaker(autoflush=True, autocommit=False,
extension=ZopeTransactionExtension())
DBSession = scoped_session(maker)
elixir.session = DBSession
elixir.options_defaults["shortnames"] = True
DeclarativeBase = declarative_base()
metadata = DeclarativeBase.metadata
elixir.metadata = metadata
def init_model(engine):
"""Call me before using any of the tables or classes in the model."""
DBSession.configure(bind=engine)
from xyz.model.auth import User, Group, Permission
from xyz.model.entidades import Xyz
elixir.setup_all()
E para declarar suas entidades, basta fazer do jeito do Elixir, estendendo a classe elixir.Entity.
Com essa integração conseguimos utilizar o padrão Active Record.