[core][plugin] Allow blueprints to be set on instance level
This ensures blueprints are read from the plugin instance instead of the class, allowing custom routes to be added within the `load()` function. Signed-off-by: Ferdinand Thiessen <rpm@fthiessen.de>
This commit is contained in:
parent
6ad8cd1728
commit
aa8f8f6e64
|
@ -41,9 +41,14 @@ def load_plugins(app: Flask):
|
|||
for plugin in pluginController.get_enabled_plugins():
|
||||
logger.debug(f"Searching for enabled plugin {plugin.name}")
|
||||
try:
|
||||
# Load class
|
||||
cls = plugin.entry_point.load()
|
||||
if hasattr(cls, "blueprint") and cls.blueprint is not None:
|
||||
app.register_blueprint(cls.blueprint)
|
||||
plugin = cls.query.get(plugin.id) if plugin.id is not None else plugin
|
||||
# Custom loading tasks
|
||||
plugin.load()
|
||||
# Register blueprint
|
||||
if hasattr(plugin, "blueprint") and plugin.blueprint is not None:
|
||||
app.register_blueprint(plugin.blueprint)
|
||||
except:
|
||||
logger.error(
|
||||
f"Plugin {plugin.name} was enabled, but could not be loaded due to an error.",
|
||||
|
@ -51,9 +56,7 @@ def load_plugins(app: Flask):
|
|||
)
|
||||
continue
|
||||
logger.info(f"Loaded plugin: {plugin.name}")
|
||||
app.config["FG_PLUGINS"][plugin.name] = cls.query.get(plugin.id) if plugin.id is not None else plugin
|
||||
app.config["FG_PLUGINS"][plugin.name].load()
|
||||
|
||||
app.config["FG_PLUGINS"][plugin.name] = plugin
|
||||
|
||||
def create_app(test_config=None, cli=False):
|
||||
app = Flask("flaschengeist")
|
||||
|
|
|
@ -226,7 +226,7 @@ class AuthPlugin(Plugin):
|
|||
password: string
|
||||
|
||||
"""
|
||||
raise MethodNotAllowed
|
||||
raise NotImplementedError
|
||||
|
||||
def delete_user(self, user):
|
||||
"""If backend is using (writeable) external data, then delete the user from external database.
|
||||
|
@ -235,7 +235,7 @@ class AuthPlugin(Plugin):
|
|||
user: User object
|
||||
|
||||
"""
|
||||
raise MethodNotAllowed
|
||||
raise NotImplementedError
|
||||
|
||||
def get_avatar(self, user) -> _Avatar:
|
||||
"""Retrieve avatar for given user (if supported by auth backend)
|
||||
|
|
Loading…
Reference in New Issue