Ok here is the problem in brief. I do have a pyramid setup that does start to look like a cms. I have as base models: [accounts, pages, errors, menus, configs]
It works pretty well but I do have a little problem with something. Currently i'm using git and on some branches I do have different templates and on the master branch I do my change to the core.
I'd like to be able to install themes instead. Themes would be a collection of template files/static file(css/js).
That can be achieved with entry_points and my config view can look them up and display a list of installed themes. That so far can be done.
Being able to switch different themes on the fly would be a very good start so I wouldn't have to fork my projects only for new themes.
The second problem is that theses sites requires different content. For example, one would require "Question" and the other "Products"
So I have this idea in mind
class TemplatePlugin(PyramidPlugin):
template_path = ''
static_path = ''
def register(self, config, app):
'''Inject the plugin in the application... how I'm not sure yet'''
def unregister(self):
'''unregister the plugin if something is needed'''
def (before/after)_(request/newapp...)(self,...):
'''do some stuff for some events most are optional'''
And a different plugin for models
class PyramidPlugin(pyramid_plugin):
def register(self, config, app):
'''add routes,
add view handlers (view_config)
add models acl to the acl list
'''
# other functions similar to the above class to handle events
My biggest problem is how does it find files. I will have to do some test but i'm worried about translations, and file path.
How does it works through entries points is still a mistery to me. Will plugins use babel translations... can I use my babel translation in my template plugins? When an entry point is loaded..current dir is the dir of the project or the dir of the entry point? I believe I can easily get the path with distribution but I'm not sure what is the right way to do all this... I feel like i'm getting in a whole new land filled with mines.
In Pyramid you can pick templates at run-time using render_to_reponse function. But if you want a more cooked solution, you might get inspired by Kotti, a Pyramid CMS that already has support for addons and look and feel customization with 'Babel' for internationalization. In order to use another 'theme' you have to write another package with some templates and static assets following the convention Kotti uses and then you activate the package in the .ini configuration file.
To understand how Kotti achieves this, you should start following the code path from this line
In any case, Kotti makes some assumptions about how the Pyramid application is configured, such as SQLAlchemy for storage, formencode for form generation or traversal to map views to resources, so YMMV. Pyramid itself is unopinionated about the way you do this.