Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add app object late-binding support.

A `CouchDBKit` object can now be instantiated without providing an
app object and provided at a later time by manually calling the object's
`init_app` function.

This change does not impact the existing extension API.
  • Loading branch information...
commit 9362f8afbed5498f032ce35c388f7b613b382194 1 parent fc68713
@mattd mattd authored
Showing with 20 additions and 6 deletions.
  1. +2 −0  .gitignore
  2. +3 −0  CONTRIBUTORS
  3. +15 −6 flaskext/couchdbkit.py
View
2  .gitignore
@@ -7,6 +7,8 @@ Thumbs.db
*.db-journal
*.pyc
*.pyo
+*.swp
+*.swo
# zc.bulidout
.installed.cfg
View
3  CONTRIBUTORS
@@ -4,3 +4,6 @@ Alan Plum
Benoit Chesneau
* Compatibility with reskit 3.0.
+
+Matt Dawson
+* Add app object late-binding support.
View
21 flaskext/couchdbkit.py
@@ -5,7 +5,7 @@
Flask extension that provides integration with CouchDBKit.
- :copyright: (c) 2010 by Kridsada Thanabulpong.
+ :copyright: (c) 2011 by Kridsada Thanabulpong.
:license: BSD, see LICENSE for more details.
"""
from __future__ import absolute_import
@@ -31,10 +31,22 @@ class CouchDBKit(object):
"""This class is used to control CouchDB integration to a Flask
application.
- :param app: The application to bind this CouchDBKit instance into.
+ :param app: The application to which this CouchDBKit should be bound. If an
+ app is not provided at initialization time, it may be provided later by
+ calling `init_app` manually.
"""
+ def __init__(self, app=None):
+ _include_couchdbkit(self)
+ if app is not None:
+ self.init_app(app)
+
+ def init_app(self, app):
+ """Bind an app to a CouchDBKit instance and initialize the database.
- def __init__(self, app):
+ :param app: The application to which the CouchDBKit instance should be
+ bound.
+ """
+ self.app = app
app.config.setdefault('COUCHDB_SERVER', 'http://localhost:5984/')
app.config.setdefault('COUCHDB_DATABASE', None)
app.config.setdefault('COUCHDB_KEEPALIVE', None)
@@ -48,10 +60,7 @@ def __init__(self, app):
else:
server = Server(server_uri)
- self.app = app
self.server = server
-
- _include_couchdbkit(self)
self.init_db()
def init_db(self):
Please sign in to comment.
Something went wrong with that request. Please try again.