I've recently discovered Glashammer, and I'm now in the process of rewriting one of my current Django projects (
EPIC; a Trac/Redmine replacement) over to Glashammer.
I want to use a database-backed configuration system for pretty much everything except database location and session cookie name. I need a lot of things to be 'project'-dependent and editable through the page at runtime, and the extra flexibility of database-backed configuration will make that possible.
My issue comes with where to place some of the initialization code. Currently, I have the following setup code in my main app: (I'm using Elixir with SQLAlchemy, which is why create_all() has no arguments)
def setup_data(app):
setup_all()
create_all()
Configuration.setValue('global', 'templatesDir', 'templates')
# Data directories
templatesDir = Configuration.getPath('global', 'templatesDir', default='templates')
app.add_template_searchpath(templatesDir)
mediaDir = Configuration.getPath('global', 'mediaDir', default='media')
app.add_shared('main', mediaDir)
def setup(app):
# Configuration file variables
app.add_config_var('data_dir', str, DEFAULT_DATA_DIRECTORY)
app.add_config_var('databaseUrl', str, 'sqlite:///' + join(DEFAULT_DATA_DIRECTORY, '/test.db'))
databaseUrl = app.conf['databaseUrl']
# Database setup
metadata.bind = databaseUrl
app.add_setup(setup_sqlalchdb, databaseUrl, metadata)
Configuration.baseDir = app.conf['data_dir']
app.add_setup(setup_auth, True)
app.add_data_func(setup_data)
The separation between 'setup' and 'data' callables isn't entirely clear to me. In the documentation, it states about the data callables, "This is separate from the setup callables in that they are run afterwards, so we
can be sure that code requiring this bundle’s initialization has been called." This doesn't make it clear which ones are run after which. What happens when there are setup callables that register both setup and data callables? For example, in the above code, will setup_auth or setup_data be called first?
Chat:
FunkieMous