CouchDB Loader

Simple loader to fetch Brevé templates from CouchDB.

import couchdb.client

class CouchLoader ( object ):
    __slots__ = [ 'uri' ]

    def __init__ ( self, uri ):
        self.uri = uri

    def stat ( self, template, root ):
        db = couchdb.client.Database ( "%s/%s" % ( self.uri, root ) )
        uid = ( root, template )
        return uid, db [ template ][ '_rev' ]

    def load ( self, uid ):
        root, template = uid
        db = couchdb.client.Database ( "%s/%s" % ( self.uri, root ) )
        return db [ template ][ 'content' ]

Loader assumes that template (stored as JSON string) is in "content" field. The URL is the CouchDB ID.

An example of using it from Pylons:

from breve.plugin.pylons_adapter import render

class ContentController ( BaseController ):
    def index ( self, page ):
        loader = CouchLoader ( 'http://localhost:5984' )
        return render ( page, loader = loader )
edit page
Back to top
Rendered using Brevé 1.3.0Copyright © 2007, Cliff Wells