Add system actions list

This commit is contained in:
Joel Collins 2020-01-14 15:06:50 +00:00
parent 38f92c6261
commit fc1ba3d834

View file

@ -4,6 +4,11 @@ Top-level representation of enabled actions
from . import camera, stage, system
from openflexure_microscope.common.flask_labthings.view import View
from openflexure_microscope.common.flask_labthings.find import current_labthing
from openflexure_microscope.common.flask_labthings.utilities import description_from_view
from openflexure_microscope.common.flask_labthings.decorators import Tag
_actions = {
"capture": {
"rule": "/camera/capture/",
@ -46,3 +51,33 @@ _actions = {
def enabled_root_actions():
global _actions
return {k: v for k, v in _actions.items() if v["conditions"]}
@Tag("actions")
class ActionsView(View):
def get(self):
"""
List of enabled default API actions.
This list does not include any actions added by LabThings extensions, only
those part of the default OpenFlexure Microscope API.
"""
global _actions
actions = {}
for name, action in enabled_root_actions().items():
d = {
"links": {
"self": {
"href": current_labthing().url_for(action["view_class"]),
"mimetype": "application/json",
**description_from_view(action["view_class"])
}
},
"rule": action["rule"],
"view_class": str(action["view_class"]),
}
actions[name] = d
return actions