Switched to ActionView and PropertyView from decorators

This commit is contained in:
Joel Collins 2020-05-26 10:54:21 +01:00
parent 677b08d509
commit 1819ca6a9c
18 changed files with 57 additions and 98 deletions

View file

@ -1,6 +1,6 @@
from labthings.server.extensions import BaseExtension
from labthings.server.find import find_component
from labthings.server.view import View
from labthings.server.view import View, PropertyView
from labthings.server.decorators import (
use_args,
@ -36,8 +36,7 @@ def rename(microscope, new_name):
## Extension views
# Since we only have a GET method here, it'll register as a read-only property
@ThingProperty
class ExampleIdentifyView(View):
class ExampleIdentifyView(PropertyView):
# Format our returned object using MicroscopeIdentifySchema
@marshal_with(MicroscopeIdentifySchema())
def get(self):
@ -52,11 +51,10 @@ class ExampleIdentifyView(View):
return microscope
@ThingProperty
# We can use a single schema for all methods if the input and output will be formatted identically
# Eg. Here, we will always expect a "name" string argument, and always return a "name" string attribute
@PropertySchema({"name": fields.String(required=True, example="My Example Microscope")})
class ExampleRenameView(View):
class ExampleRenameView(PropertyView):
def get(self):
"""
Show the current microscope name

View file

@ -1,6 +1,6 @@
from labthings.server.extensions import BaseExtension
from labthings.server.find import find_component
from labthings.server.view import View
from labthings.server.view import View, ActionView, PropertyView
from labthings.server.decorators import (
use_args,
@ -41,8 +41,7 @@ def rename(microscope, new_name):
## Extension views
# Since we only have a GET method here, it'll register as a read-only property
@ThingProperty
class ExampleIdentifyView(View):
class ExampleIdentifyView(PropertyView):
# Format our returned object using MicroscopeIdentifySchema
@marshal_with(MicroscopeIdentifySchema())
def get(self):
@ -57,11 +56,10 @@ class ExampleIdentifyView(View):
return microscope
@ThingProperty
# We can use a single schema for all methods if the input and output will be formatted identically
# Eg. Here, we will always expect a "name" string argument, and always return a "name" string attribute
@PropertySchema({"name": fields.String(required=True, example="My Example Microscope")})
class ExampleRenameView(View):
class ExampleRenameView(PropertyView):
def get(self):
"""
Show the current microscope name
@ -89,8 +87,7 @@ class ExampleRenameView(View):
return microscope
@ThingAction
class QuickCaptureAPI(View):
class QuickCaptureAPI(ActionView):
"""
Take an image capture and return it without saving
"""

View file

@ -1,6 +1,6 @@
from labthings.server.extensions import BaseExtension
from labthings.server.find import find_component
from labthings.server.view import View
from labthings.server.view import View, ActionView
from labthings.server.decorators import (
use_args,
@ -66,8 +66,7 @@ def timelapse(microscope, n_images, t_between):
## Extension views
@ThingAction
class TimelapseAPI(View):
class TimelapseAPI(ActionView):
"""
Take a series of images in a timelapse
"""

View file

@ -1,6 +1,6 @@
from labthings.server.extensions import BaseExtension
from labthings.server.find import find_component
from labthings.server.view import View
from labthings.server.view import View, ActionView
from labthings.server.decorators import (
use_args,
@ -68,8 +68,7 @@ def timelapse(microscope, n_images, t_between):
## Extension views
@ThingAction
class TimelapseAPI(View):
class TimelapseAPI(ActionView):
"""
Take a series of images in a timelapse, running as a background task
"""