An extendable Pyramid application using PCA and Jinja2 plugins
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.idea
pcaexample
pcaplugin
.directory
.gitignore
LICENSE
README.md
screenshot.png

README.md

An extendable Pyramid application using PCA and Jinja2 plugins

Pyramid is a great framework for developing web applications that also supports the development of "Extensible" and "Pluggable" software based on certain rules. However, there is no much documentation on how to create such type of applications.

CKAN is an excellent example of a Web application that can be extended or customized using plugins. It relies on PyUtilib Component Architecture to declare a series of interfaces and extension points that then are used by plugins to hook in. It also implements a series of Jinja2 extension (notably CKAN_EXTENDS) that allows easily template inheritance between CKAN and connected plugins.

CKAN however is developed using Pylons which is now superseded by Pyramid and coupled to its complexity makes it difficult to grasp how to apply such extensibility to Pyramid web applications.

This example applies a modified version of CKAN extensible system to a simple Pyramid application that can be used as a starter to develop more complex extendable web applications. The example allows plugins to extend the host by:

  • Adding new routes
  • Adding and overwriting templates
  • Adding new static resources
  • Adding new JSS or CSS resources
  • Easy Jinja2 template inheritance and resource injection

The example (pcaexample) is based on a “pyramid-cookiecutter-alchemy” Cookiecutter while the plugin is based on a “pyramid-cookiecutter-starter”. It uses Pyramid 1.8.3 with PyUtilib 5.4.1.

Please note that this example implements Pyramid "Extensible" and "Pluggable" capabilities in a way that I feel it would satisfy most needs. I don't claim is the best nor the most logical way of doing it. Comments and suggestions are welcomed.

Installation and testing

To build and run the example host application (pcaexample) on Linux do:

$ git clone https://github.com/qlands/pyramid-pca-jinja2.git
$ virtualenv pcaexample_env
$ . ./pcaexample_env/bin/activate
$ cd pyramid-pca-jinja2
$ cd pcaexample
$ python setup.py install
$ initialize_pcaexample_db ./development.ini
$ pserve ./development.ini

To build the a example of the plugin (pcaplugin) on Linux do:

$ cd pyramid-pca-jinja2
$ cd pcaplugin
$ python setup.py develop
$ cd ..
$ cd pcaexample

Edit the configuration of the host application (development.ini) to load the plugin by uncommenting line 26 to read:

pcaexample.plugins = examplePlugin

Then do:

$ pserve ./development.ini

Screenshot

Image

Author

Carlos Quiros (cquiros_at_qlands.com / c.f.quiros_at_cgiar.org)