mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Add automatic browser menu integration for modules.
Modules may now include functions that return lists of menu items that will be included on the main browser window menu. While we're at it, move the test views into a separate module.
This commit is contained in:
@@ -17,11 +17,14 @@ from flask_security.utils import login_user
|
||||
from flask_mail import Mail
|
||||
from settings_model import db, Role, User
|
||||
|
||||
import inspect, logging, os
|
||||
import inspect, imp, logging, os
|
||||
|
||||
# Configuration settings
|
||||
import config
|
||||
|
||||
# Global module list
|
||||
modules = [ ]
|
||||
|
||||
def create_app(app_name=config.APP_NAME):
|
||||
"""Create the Flask application, startup logging and dynamically load
|
||||
additional modules (blueprints) that are found in this directory."""
|
||||
@@ -88,6 +91,7 @@ def create_app(app_name=config.APP_NAME):
|
||||
|
||||
path = os.path.dirname(os.path.realpath(__file__))
|
||||
files = os.listdir(path)
|
||||
|
||||
for f in files:
|
||||
d = os.path.join(path, f)
|
||||
if os.path.isdir(d) and os.path.isfile(os.path.join(d, '__init__.py')):
|
||||
@@ -98,10 +102,16 @@ def create_app(app_name=config.APP_NAME):
|
||||
|
||||
# Looks like a module, so import it, and register the blueprint if present
|
||||
# We rely on the ordering of syspath to ensure we actually get the right
|
||||
# module here.
|
||||
# module here. Note that we also try to load the 'browser' module for
|
||||
# the browser integration hooks.
|
||||
app.logger.info('Examining potential module: %s' % d)
|
||||
module = __import__(f, globals(), locals(), ['views'], -1)
|
||||
if hasattr(module.views, 'blueprint'):
|
||||
module = __import__(f, globals(), locals(), ['browser', 'views'], -1)
|
||||
|
||||
# Add the module to the global module list
|
||||
modules.append(module)
|
||||
|
||||
# Register the blueprint if present
|
||||
if 'views' in dir(module) and 'blueprint' in dir(module.views):
|
||||
app.logger.info('Registering blueprint module: %s' % f)
|
||||
app.register_blueprint(module.views.blueprint)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user