Gazette is a flexible CMS library that can be added into any app. It has several pieces which can be used together or separately:
Python 3 will need a custom datastore backend. Datastores are simple and pluggable, but the existing datastores do not work with Python 3.
First, set up a python "virtualenv" to install Gazette into.
Gazette can be installed with pip, although you'll need the whole repo for the frontend JS app.
$ pip install Gazette
Or install directly from the git repo:
$ git clone git://git.code.sf.net/p/gazette/code gazette
$ cd gazette/api/python
$ python setup.py develop
Run these commands from your terminal:
# link the demo components into the ember app
ln -s ../../../demo-app/admin_components admin/app/gzplugins/components
cd admin/
npm install -g ember-cli
npm install -g bower
npm install
bower install
ember build -e demo
cd ..
cd demo-app/
pip install -r requirements.txt
python demo.py
Then visit http://localhost:8080/
Look at demo.py
and the templates as examples of how to use Gazette in an application. The admin_components
directory is where you put your Ember admin forms for your content types. It is symlinked into the Ember app at admin/app/gzplugins/components
(which is the Ember "pods" dir).
Quick and easy:
pip install -r requirements.txt
GZ_DS_DIR=demo-app/data/ python -m bottle gazette.api:app
For production deployment, set up a WSGI server to run the application gazette.api:app
. And use a few lines of python in your wsgi config to set up a Datastore
connection instead of the default filesystem configuration.
You can also embed the API application into another python webapp. This is useful if you already have a python webapp
and don't want to run a separate service for the API. See specific documentation for
Bottle subapplications, Pyramid wrapping, Django embedding, or dispatch middleware for any WSGI application.
When embedded you probably want your host application to handle errors rather than bottle's error handling, so set gazette.api.app.catchall = False
in your python setup code.
Refer to the demo as reference for accessing content from your app.
TODO: how to write your own content types (python class and template, ember admin component)
TODO: how to include the ember app
Example mongodb datastore configuration:
import pymongo
from datastore.core.serialize import SerializerShimDatastore
from gazette.models import Content
from gazette.utils import AutoKeyClassDatastore, MongoNonWrapDatastore, ContentDictSerializer, GazetteMongoDatastore
content_mongo = pymongo.MongoClient('localhost') # put your connection in here
main_ds = GazetteMongoDatastore(content_mongo['gazette'])
Content.ds = AutoKeyClassDatastore( # convert str to datastore.Key automatically for gazette convenience
SerializerShimDatastore(
MongoNonWrapDatastore( # tweak the mongo document for nicer mongo record structure
main_ds,
),
serializer=ContentDictSerializer, # convert Content to dict, so mongo can take it
),
)
Gazette does not handle authentication or authorization. It is a "dumb" datastore. The API can be secured by wrapping it with python middleware or using firewall rules. This allows your application to decide exactly what logic to use to authenticate a request. Your application should also control when to include the gazette admin interface.