Skip to content

Commit

Permalink
Flask extensions should use IBlueprint interface.
Browse files Browse the repository at this point in the history
Flask extensions can register more than just routes for the app. So
change the extension point from IRoutes, to IBlueprint, a very simple
interface that has one method `get_blueprint`, enabling extensions to
return Flask Blueprint objects to be registered with the Flask app at
start up.
  • Loading branch information
brew committed May 30, 2016
1 parent 9fed8b4 commit ec77544
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ckan/config/middleware.py
Expand Up @@ -35,7 +35,7 @@
from flask_debugtoolbar import DebugToolbarExtension

from ckan.plugins import PluginImplementations
from ckan.plugins.interfaces import IMiddleware, IRoutes
from ckan.plugins.interfaces import IMiddleware, IBlueprint
from ckan.lib.i18n import get_locales_from_config
import ckan.lib.uploader as uploader
from ckan.lib import jinja_extensions
Expand Down Expand Up @@ -347,7 +347,7 @@ def hello_world_post():
app.register_blueprint(api)

# Set up each iRoute extension as a Flask Blueprint
for plugin in PluginImplementations(IRoutes):
for plugin in PluginImplementations(IBlueprint):
if hasattr(plugin, 'get_blueprint'):
app.register_blueprint(plugin.get_blueprint(),
prioritise_rules=True)
Expand Down
8 changes: 8 additions & 0 deletions ckan/plugins/interfaces.py
Expand Up @@ -1566,3 +1566,11 @@ def get_resource_uploader(self):
:type id: string
'''


class IBlueprint(Interface):

'''Register an extension as a Flask Blueprint.'''

def get_blueprint(self):
'''Return a Flask Blueprint object to be registered by the app.'''

0 comments on commit ec77544

Please sign in to comment.