{"id":39,"date":"2009-10-23T08:29:09","date_gmt":"2009-10-23T11:29:09","guid":{"rendered":"http:\/\/www.fnbrandao.com.br\/blog\/?p=39"},"modified":"2009-10-23T08:29:09","modified_gmt":"2009-10-23T11:29:09","slug":"turbogears-2-e-elixir","status":"publish","type":"post","link":"https:\/\/www.fnbrandao.com.br\/blog\/2009\/10\/turbogears-2-e-elixir\/","title":{"rendered":"Turbogears 2 e Elixir"},"content":{"rendered":"<p>Para se integrar o elixir no turbogears 2, basta editar o arquivo model\/__init__.py do seu projeto para ficar desse jeito:<\/p>\n<p><code><\/p>\n<pre># -*- coding: utf-8 -*-\r\n\r\nfrom zope.sqlalchemy import ZopeTransactionExtension\r\nfrom sqlalchemy.orm import scoped_session, sessionmaker\r\nfrom sqlalchemy.ext.declarative import declarative_base\r\nimport elixir\r\n\r\nmaker = sessionmaker(autoflush=True, autocommit=False,\r\n                     extension=ZopeTransactionExtension())\r\nDBSession = scoped_session(maker)\r\nelixir.session = DBSession\r\nelixir.options_defaults[\"shortnames\"] = True\r\n\r\nDeclarativeBase = declarative_base()\r\n\r\nmetadata = DeclarativeBase.metadata\r\nelixir.metadata = metadata\r\n\r\ndef init_model(engine):\r\n    \"\"\"Call me before using any of the tables or classes in the model.\"\"\"\r\n\r\n    DBSession.configure(bind=engine)\r\n\r\nfrom xyz.model.auth import User, Group, Permission\r\nfrom xyz.model.entidades import Xyz\r\n\r\nelixir.setup_all()<\/pre>\n<p><\/code><\/p>\n<p>E para declarar suas entidades, basta fazer do jeito do Elixir, estendendo a classe <em>elixir.Entity<\/em>.<\/p>\n<p>Com essa integra\u00e7\u00e3o conseguimos utilizar o padr\u00e3o <a href=\"http:\/\/en.wikipedia.org\/wiki\/Active_record_pattern\">Active Record<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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[&#8220;shortnames&#8221;] = True DeclarativeBase [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3,96],"tags":[99,98,93,97],"class_list":["post-39","post","type-post","status-publish","format-standard","hentry","category-programacao","category-python-programacao","tag-active-record","tag-elixir","tag-python","tag-turbogears"],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.fnbrandao.com.br\/blog\/wp-json\/wp\/v2\/posts\/39","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.fnbrandao.com.br\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.fnbrandao.com.br\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.fnbrandao.com.br\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.fnbrandao.com.br\/blog\/wp-json\/wp\/v2\/comments?post=39"}],"version-history":[{"count":0,"href":"https:\/\/www.fnbrandao.com.br\/blog\/wp-json\/wp\/v2\/posts\/39\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.fnbrandao.com.br\/blog\/wp-json\/wp\/v2\/media?parent=39"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fnbrandao.com.br\/blog\/wp-json\/wp\/v2\/categories?post=39"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fnbrandao.com.br\/blog\/wp-json\/wp\/v2\/tags?post=39"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}