Removed old JSONResponse class
This commit is contained in:
parent
7c450b6214
commit
b350f62013
5 changed files with 26 additions and 90 deletions
|
|
@ -2,12 +2,12 @@ import logging
|
|||
|
||||
from flask import abort, redirect, request, send_file, url_for
|
||||
from labthings import Schema, fields, find_component
|
||||
from labthings.marshalling import marshal_with
|
||||
from labthings.marshalling import marshal_with, use_args
|
||||
from labthings.utilities import description_from_view
|
||||
from labthings.views import PropertyView, View
|
||||
from marshmallow import pre_dump
|
||||
|
||||
from openflexure_microscope.api.utilities import JsonResponse, get_bool
|
||||
from openflexure_microscope.api.utilities import get_bool
|
||||
|
||||
|
||||
class InstrumentSchema(Schema):
|
||||
|
|
@ -203,7 +203,8 @@ class CaptureTags(View):
|
|||
|
||||
return capture_obj.tags
|
||||
|
||||
def put(self, id_):
|
||||
@use_args(fields.List(fields.String(), required=True))
|
||||
def put(self, args, id_):
|
||||
"""
|
||||
Add tags to a single image capture
|
||||
"""
|
||||
|
|
@ -213,17 +214,12 @@ class CaptureTags(View):
|
|||
if not capture_obj:
|
||||
return abort(404) # 404 Not Found
|
||||
|
||||
# TODO: Replace with normal Flask request JSON thing
|
||||
data_dict = JsonResponse(request).json
|
||||
|
||||
if type(data_dict) != list:
|
||||
return abort(400)
|
||||
|
||||
capture_obj.put_tags(data_dict)
|
||||
capture_obj.put_tags(args)
|
||||
|
||||
return capture_obj.tags
|
||||
|
||||
def delete(self, id_):
|
||||
@use_args(fields.List(fields.String(), required=True))
|
||||
def delete(self, args, id_):
|
||||
"""
|
||||
Delete tags from a single image capture
|
||||
"""
|
||||
|
|
@ -233,12 +229,7 @@ class CaptureTags(View):
|
|||
if not capture_obj:
|
||||
return abort(404) # 404 Not Found
|
||||
|
||||
data_dict = JsonResponse(request).json
|
||||
|
||||
if type(data_dict) != list:
|
||||
return abort(400)
|
||||
|
||||
for tag in data_dict:
|
||||
for tag in args:
|
||||
capture_obj.delete_tag(str(tag))
|
||||
|
||||
return capture_obj.tags
|
||||
|
|
@ -259,7 +250,8 @@ class CaptureAnnotations(View):
|
|||
|
||||
return capture_obj.annotations
|
||||
|
||||
def put(self, id_):
|
||||
@use_args(fields.Dict())
|
||||
def put(self, args, id_):
|
||||
"""
|
||||
Update metadata for a single image capture
|
||||
"""
|
||||
|
|
@ -269,12 +261,6 @@ class CaptureAnnotations(View):
|
|||
if not capture_obj:
|
||||
return abort(404) # 404 Not Found
|
||||
|
||||
data_dict = JsonResponse(request).json
|
||||
logging.debug(data_dict)
|
||||
|
||||
if type(data_dict) != dict:
|
||||
return abort(400)
|
||||
|
||||
capture_obj.put_annotations(data_dict)
|
||||
capture_obj.put_annotations(args)
|
||||
|
||||
return capture_obj.annotations
|
||||
|
|
|
|||
|
|
@ -1,12 +1,11 @@
|
|||
import logging
|
||||
|
||||
from flask import abort, request
|
||||
from labthings import find_component
|
||||
from labthings import find_component, fields
|
||||
from labthings.marshalling import use_args
|
||||
from labthings.utilities import create_from_path, get_by_path, set_by_path
|
||||
from labthings.views import PropertyView, View
|
||||
|
||||
from openflexure_microscope.api.utilities import JsonResponse
|
||||
|
||||
|
||||
class SettingsProperty(PropertyView):
|
||||
def get(self):
|
||||
|
|
@ -16,17 +15,17 @@ class SettingsProperty(PropertyView):
|
|||
microscope = find_component("org.openflexure.microscope")
|
||||
return microscope.read_settings()
|
||||
|
||||
def put(self):
|
||||
@use_args(fields.Dict())
|
||||
def put(self, args):
|
||||
"""
|
||||
Update current microscope settings, including camera and stage
|
||||
"""
|
||||
microscope = find_component("org.openflexure.microscope")
|
||||
payload = JsonResponse(request)
|
||||
|
||||
logging.debug("Updating settings from PUT request:")
|
||||
logging.debug(payload.json)
|
||||
logging.debug(args)
|
||||
|
||||
microscope.update_settings(payload.json)
|
||||
microscope.update_settings(args)
|
||||
microscope.save_settings()
|
||||
|
||||
return self.get()
|
||||
|
|
@ -50,16 +49,16 @@ class NestedSettingsProperty(View):
|
|||
|
||||
return value
|
||||
|
||||
def put(self, route):
|
||||
@use_args(fields.Dict())
|
||||
def put(self, args, route):
|
||||
"""
|
||||
Update a nested section of the current microscope settings
|
||||
"""
|
||||
microscope = find_component("org.openflexure.microscope")
|
||||
keys = route.split("/")
|
||||
payload = JsonResponse(request)
|
||||
|
||||
dictionary = create_from_path(keys)
|
||||
set_by_path(dictionary, keys, payload.json)
|
||||
set_by_path(dictionary, keys, args)
|
||||
|
||||
microscope.update_settings(dictionary)
|
||||
microscope.save_settings()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue