Turbogears 2 e Elixir

8:29 am Programação, Python

Para 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.

Leave a Comment

Your comment

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.