plugins - Make a pyramid app ready for standalone and embedded mode -
i'm developing wiki engine. since application can usefull (at least company's private use) in own should able run standalone pyramid application, own graphical theme. wiki feature useful part of bigger project, , able include other pyramid applications.
i found pyramid features me achieve first i'm not sure whether it's best way , second problems remain open.
here potential issues see:
templates: how switch between standalone mode , hosted mode
host variables: event if can reuse host template, variables may needed correctly render templates not set guest (the wiki engine) application.
authentication: guest app defines own login system (based on pyramid_persona). can guest application reuse host authentication system?
my current idea use config.include()
system of pyramid. in wiki engine, in __init__.py
define include(config)
method in addition the main()
method used standalone mode.
in host application define variable in .ini file points template file guest should use (ie base_template = hostapp:templates/wikibase.mako
)
inside guest application, includeme()
method reads base_template
variable , overrides global config.
then each guest view work this:
from pyramid.renderers import render @view_config(route_name="display_wiki_page", renderer=globals.base_template) def view_wiki(request): """returns formatted page content""" page = request.matchdict['page'] content = get_raw_page_content_from_database(page) page_formatted = render("wikiengine:templates/page_formatting_template.mako", {'request': request, 'content': content} ) return {'page_formatted': page_formatted}
so point base template can either 1 guest or host application. both contain (in mako): ${page_formatted | n }
but not solve problem of necessary host variables template rendered guest code. example host may need have hot_news
variable need displayed on each of host pages, pages host wiki.
for plan use event system, , add subscriber newrequest or beforerender , set needed variables here inside request object.
is correct approach ? there examples of i'm trying do?
pyramid's configuration mechanisms make easy clients of module override configuration. 1 of powerful parts of pyramid compared other popular web frameworks.
config.include()
approach solving problem. allows caller override defined within include.
assets can overridden using config.override_assets()
.
sharing user information requires module either provide user information or define contract can conform allowing them override model.
anyway huge topic. highly modular apps written on top of pyramid include substanced, kotti, ptah, bookie, etc.
Comments
Post a Comment