This may sound like a really obvious, not really Pylons related
question but still, I'm pretty sure there are people who just doesn't
really pay attention to this or just new guys like me.
How do you guys make sort of init in your Pylons model/__init__.py to
set up DB connection and global variables?
Let's say we've got a pretty common __init__.py file like this:
from sqlalchemy import *
from sqlalchemy.exceptions import *
meta = MetaData()
toCharFormat = u'dd.mm.yyyy'
DB_LOCATION = config.get('sqlalchemy_conf.db_location', '')
Session = sessionmaker(.....)
def init():
if session.has_key('SA_sess'):
pass
else:
session['SA_sess'] = web_user_sess
import classifiers
import register
....
# Setting up WebUser common session
engine = create_engine(.....')
web_user_sess = Session(bind=engine)
..................
The main question is: Is the content of this file run only on
application start or on every request to any controller?
If every time - what's the best practice for specifying some init
function that will set up the connection?
What I'm doing right now is calling model.init() on every controller
call. It'd be way easier to just specify def __init__(self) in model,
but it looks like it doesn't work this way.
class MailController(BaseController):
def __init__(self):
model.init()
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---