Skip to content

Commit

Permalink
[#3196] Simplify add core blueprint function as per @TkTech advice
Browse files Browse the repository at this point in the history
  • Loading branch information
amercader committed Nov 14, 2016
1 parent ee5047d commit 93dc635
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions ckan/config/middleware/flask_app.py
Expand Up @@ -4,6 +4,7 @@
import importlib
import inspect
import itertools
import pkgutil

from flask import Flask, Blueprint
from flask.ctx import _AppCtxGlobals
Expand Down Expand Up @@ -273,17 +274,11 @@ def register_extension_blueprint(self, blueprint, **kwargs):
def _register_core_blueprints(app):
u'''Register all blueprints defined in the `views` folder
'''
views_path = os.path.join(os.path.dirname(__file__),
u'..', u'..', u'views')
module_names = [f.rstrip(u'.py')
for f in os.listdir(views_path)
if f.endswith(u'.py') and not f.startswith(u'_')]
blueprints = []
for name in module_names:
module = importlib.import_module(u'ckan.views.{0}'.format(name))
blueprints.extend([m for m in inspect.getmembers(module)
if isinstance(m[1], Blueprint)])
if blueprints:
for blueprint in blueprints:
def is_blueprint(mm):
return isinstance(mm, Blueprint)

for loader, name, _ in pkgutil.iter_modules(['ckan/views'], 'ckan.views.'):
module = loader.find_module(name).load_module(name)
for blueprint in inspect.getmembers(module, is_blueprint):
app.register_blueprint(blueprint[1])
log.debug(u'Registered core blueprint: {0}'.format(blueprint[0]))
log.debug(u'Registered core blueprint: {0!r}'.format(blueprint[0]))

0 comments on commit 93dc635

Please sign in to comment.