Fixed plugin view ID clashes

This commit is contained in:
Joel Collins 2019-11-27 14:34:45 +00:00
parent 0819c2ee4d
commit 45e7bcb167
2 changed files with 21 additions and 4 deletions

View file

@ -39,7 +39,7 @@ def plugins_representation(plugin_loader_object: PluginLoader):
for view_id, view_data in plugin.views.items():
logging.debug(f"Representing view {view_id}")
uri = url_for(f"v2_plugins_blueprint.{view_id}")
uri = url_for(f"v2_plugins_blueprint.{plugin._name_python_safe}_{view_id}")
# Make links dictionary if it doesn't yet exist
view_d = {"links": {"self": uri}}
@ -86,7 +86,9 @@ def construct_blueprint(microscope_obj):
blueprint.add_url_rule(
plugin_view["rule"],
view_func=plugin_view["view"].as_view(
plugin_view_id, microscope=microscope_obj, plugin=plugin
f"{plugin._name_python_safe}_{plugin_view_id}",
microscope=microscope_obj,
plugin=plugin,
),
)

View file

@ -1,6 +1,7 @@
import importlib
import copy
import os
import collections
import inspect
import logging
@ -258,9 +259,11 @@ class BasePlugin:
# Expand the rule to include plugin name
full_rule = "/{}/{}".format(self._name_uri_safe, cleaned_rule)
# Create a Python-safe route ID
view_id = cleaned_rule.replace("/", "_")
# Create a Python-safe route ID
logging.debug(view_id)
# Store route information in a dictionary
d = {"rule": full_rule, "view": view_class}
@ -271,10 +274,22 @@ class BasePlugin:
@property
def gui(self):
print(self._gui)
# Handle missing/no GUI
if not self._gui:
return None
# Handle GUI as a dictionary-returning callable function
elif isinstance(self._gui, collections.Callable):
api_gui = self._gui()
# Handle GUI as a static dictionary
elif isinstance(self._gui, dict):
api_gui = copy.deepcopy(self._gui)
# Handle borked GUI
else:
raise ValueError(
"GUI must be a dictionary, or a dictionary-returning function with no arguments."
)
api_gui = copy.deepcopy(self._gui)
api_gui["id"] = self._name
if "forms" in api_gui and isinstance(api_gui["forms"], list):