Menu

Tree [9ed234] master kt/10290 /
 History

HTTPS access


File Date Author Commit
 admin 2015-05-19 Kenton Taylor Kenton Taylor [9ed234] [#10290] Added transition upon successful new c...
 api 2015-04-17 Dave Brondsema Dave Brondsema [a5d7d0] Change PUT response to 204 since there is no co...
 demo-app 2015-04-12 Kenton Taylor Kenton Taylor [fb1022] [#10266] Form validations WIP
 .gitattributes 2015-02-03 Dave Brondsema Dave Brondsema [fe166f] Initial package setup, based on https://github....
 .gitignore 2015-03-11 Dave Brondsema Dave Brondsema [972b4b] Prepare for first pypi release
 LICENSE.txt 2015-02-03 Dave Brondsema Dave Brondsema [fe166f] Initial package setup, based on https://github....
 README.md 2015-04-17 Dave Brondsema Dave Brondsema [971a26] Instructions for linking demo admin components ...

Read Me

Gazette

Gazette is a flexible CMS library that can be added into any app. It has several pieces which can be used together or separately:

  • A library to store content and render it as HTML (python)
  • A REST API for the content (python)
  • A client-side UI to manage content in your webapp (ember)

Getting Started

Requirements

  • Python 2.7+ or Python 3.3+

Python 3 will need a custom datastore backend. Datastores are simple and pluggable, but the existing datastores do not work with Python 3.

Installation

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

Running the demo

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).

Running the API service

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.

Using Gazette in your app

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
    ),
)

Security

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.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.