Fixed plugin view ID clashes
This commit is contained in:
parent
0819c2ee4d
commit
45e7bcb167
2 changed files with 21 additions and 4 deletions
|
|
@ -39,7 +39,7 @@ def plugins_representation(plugin_loader_object: PluginLoader):
|
||||||
|
|
||||||
for view_id, view_data in plugin.views.items():
|
for view_id, view_data in plugin.views.items():
|
||||||
logging.debug(f"Representing view {view_id}")
|
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
|
# Make links dictionary if it doesn't yet exist
|
||||||
view_d = {"links": {"self": uri}}
|
view_d = {"links": {"self": uri}}
|
||||||
|
|
||||||
|
|
@ -86,7 +86,9 @@ def construct_blueprint(microscope_obj):
|
||||||
blueprint.add_url_rule(
|
blueprint.add_url_rule(
|
||||||
plugin_view["rule"],
|
plugin_view["rule"],
|
||||||
view_func=plugin_view["view"].as_view(
|
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,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import importlib
|
import importlib
|
||||||
import copy
|
import copy
|
||||||
import os
|
import os
|
||||||
|
import collections
|
||||||
import inspect
|
import inspect
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
|
@ -258,9 +259,11 @@ class BasePlugin:
|
||||||
# Expand the rule to include plugin name
|
# Expand the rule to include plugin name
|
||||||
full_rule = "/{}/{}".format(self._name_uri_safe, cleaned_rule)
|
full_rule = "/{}/{}".format(self._name_uri_safe, cleaned_rule)
|
||||||
|
|
||||||
# Create a Python-safe route ID
|
|
||||||
view_id = cleaned_rule.replace("/", "_")
|
view_id = cleaned_rule.replace("/", "_")
|
||||||
|
|
||||||
|
# Create a Python-safe route ID
|
||||||
|
logging.debug(view_id)
|
||||||
|
|
||||||
# Store route information in a dictionary
|
# Store route information in a dictionary
|
||||||
d = {"rule": full_rule, "view": view_class}
|
d = {"rule": full_rule, "view": view_class}
|
||||||
|
|
||||||
|
|
@ -271,10 +274,22 @@ class BasePlugin:
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def gui(self):
|
def gui(self):
|
||||||
|
print(self._gui)
|
||||||
|
# Handle missing/no GUI
|
||||||
if not self._gui:
|
if not self._gui:
|
||||||
return None
|
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
|
api_gui["id"] = self._name
|
||||||
|
|
||||||
if "forms" in api_gui and isinstance(api_gui["forms"], list):
|
if "forms" in api_gui and isinstance(api_gui["forms"], list):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue