Switched away from using JSONify
This commit is contained in:
parent
4fffa1fcba
commit
cda5cdbb44
9 changed files with 26 additions and 29 deletions
|
|
@ -8,7 +8,7 @@ import logging, logging.handlers
|
||||||
import os
|
import os
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
|
|
||||||
from flask import Flask, jsonify, send_file
|
from flask import Flask, send_file
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
|
@ -129,7 +129,7 @@ def routes():
|
||||||
"""
|
"""
|
||||||
List of all connected API routes
|
List of all connected API routes
|
||||||
"""
|
"""
|
||||||
return jsonify(list_routes(app))
|
return list_routes(app)
|
||||||
|
|
||||||
|
|
||||||
@app.route("/log")
|
@app.route("/log")
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ from labthings.server.extensions import BaseExtension
|
||||||
from labthings.server.view import View
|
from labthings.server.view import View
|
||||||
from labthings.server.decorators import ThingAction, ThingProperty, marshal_task
|
from labthings.server.decorators import ThingAction, ThingProperty, marshal_task
|
||||||
|
|
||||||
from openflexure_microscope.devel import JsonResponse, request, jsonify, taskify, abort
|
from openflexure_microscope.devel import JsonResponse, request, taskify, abort
|
||||||
from openflexure_microscope.utilities import set_properties
|
from openflexure_microscope.utilities import set_properties
|
||||||
|
|
||||||
import time
|
import time
|
||||||
|
|
@ -309,7 +309,7 @@ class MeasureSharpnessAPI(View):
|
||||||
if not microscope:
|
if not microscope:
|
||||||
abort(503, "No microscope connected. Unable to measure sharpness.")
|
abort(503, "No microscope connected. Unable to measure sharpness.")
|
||||||
|
|
||||||
return jsonify({"sharpness": measure_sharpness(microscope)})
|
return {"sharpness": measure_sharpness(microscope)}
|
||||||
|
|
||||||
|
|
||||||
@ThingAction
|
@ThingAction
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
from openflexure_microscope.devel import (
|
from openflexure_microscope.devel import (
|
||||||
JsonResponse,
|
JsonResponse,
|
||||||
request,
|
request,
|
||||||
jsonify,
|
|
||||||
taskify,
|
taskify,
|
||||||
update_task_progress,
|
update_task_progress,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,6 @@ from openflexure_microscope.api.utilities.gui import build_gui
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from flask import jsonify
|
|
||||||
|
|
||||||
# Some value that will change over time
|
# Some value that will change over time
|
||||||
# Here, we add 1 to it every time a GET request is made
|
# Here, we add 1 to it every time a GET request is made
|
||||||
val_int = 0
|
val_int = 0
|
||||||
|
|
@ -81,7 +79,7 @@ class TestAPIView(View):
|
||||||
def get(self):
|
def get(self):
|
||||||
global val_int
|
global val_int
|
||||||
val_int += 1
|
val_int += 1
|
||||||
return jsonify({"val": True})
|
return {"val": True}
|
||||||
|
|
||||||
|
|
||||||
@ThingAction
|
@ThingAction
|
||||||
|
|
@ -89,7 +87,7 @@ class TestDoAPIView(View):
|
||||||
def post(self):
|
def post(self):
|
||||||
global val_int
|
global val_int
|
||||||
val_int += 1
|
val_int += 1
|
||||||
return jsonify({"val": True})
|
return {"val": True}
|
||||||
|
|
||||||
|
|
||||||
# Using the dynamic form
|
# Using the dynamic form
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ from openflexure_microscope.api.v2.views.captures import capture_schema
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import io
|
import io
|
||||||
from flask import jsonify, request, abort, url_for, redirect, send_file
|
from flask import request, abort, url_for, redirect, send_file
|
||||||
|
|
||||||
|
|
||||||
@ThingAction
|
@ThingAction
|
||||||
|
|
@ -164,7 +164,7 @@ class GPUPreviewStartAPI(View):
|
||||||
microscope.camera.start_preview(fullscreen=fullscreen, window=window)
|
microscope.camera.start_preview(fullscreen=fullscreen, window=window)
|
||||||
|
|
||||||
# TODO: Make schema for microscope state
|
# TODO: Make schema for microscope state
|
||||||
return jsonify(microscope.state)
|
return microscope.state
|
||||||
|
|
||||||
|
|
||||||
@ThingAction
|
@ThingAction
|
||||||
|
|
@ -176,4 +176,4 @@ class GPUPreviewStopAPI(View):
|
||||||
microscope = find_component("org.openflexure.microscope")
|
microscope = find_component("org.openflexure.microscope")
|
||||||
microscope.camera.stop_preview()
|
microscope.camera.stop_preview()
|
||||||
# TODO: Make schema for microscope state
|
# TODO: Make schema for microscope state
|
||||||
return jsonify(microscope.state)
|
return microscope.state
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ from labthings.server import fields
|
||||||
|
|
||||||
from openflexure_microscope.utilities import axes_to_array, filter_dict
|
from openflexure_microscope.utilities import axes_to_array, filter_dict
|
||||||
|
|
||||||
from flask import Blueprint, jsonify, request
|
from flask import Blueprint, request
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
|
@ -53,7 +53,7 @@ class MoveStageAPI(View):
|
||||||
logging.warning("Unable to move. No stage found.")
|
logging.warning("Unable to move. No stage found.")
|
||||||
|
|
||||||
# TODO: Make schema for microscope state
|
# TODO: Make schema for microscope state
|
||||||
return jsonify(microscope.state["stage"]["position"])
|
return microscope.state["stage"]["position"]
|
||||||
|
|
||||||
|
|
||||||
@ThingAction
|
@ThingAction
|
||||||
|
|
@ -67,4 +67,4 @@ class ZeroStageAPI(View):
|
||||||
microscope.stage.zero_position()
|
microscope.stage.zero_position()
|
||||||
|
|
||||||
# TODO: Make schema for microscope state
|
# TODO: Make schema for microscope state
|
||||||
return jsonify(microscope.state["stage"])
|
return microscope.state["stage"]
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import logging
|
import logging
|
||||||
from flask import abort, request, redirect, url_for, send_file, jsonify
|
from flask import abort, request, redirect, url_for, send_file
|
||||||
|
|
||||||
from openflexure_microscope.api.utilities import get_bool, JsonResponse
|
from openflexure_microscope.api.utilities import get_bool, JsonResponse
|
||||||
|
|
||||||
|
|
@ -185,7 +185,7 @@ class CaptureTags(View):
|
||||||
if not capture_obj:
|
if not capture_obj:
|
||||||
return abort(404) # 404 Not Found
|
return abort(404) # 404 Not Found
|
||||||
|
|
||||||
return jsonify(capture_obj.tags)
|
return capture_obj.tags
|
||||||
|
|
||||||
def put(self, id):
|
def put(self, id):
|
||||||
"""
|
"""
|
||||||
|
|
@ -205,7 +205,7 @@ class CaptureTags(View):
|
||||||
|
|
||||||
capture_obj.put_tags(data_dict)
|
capture_obj.put_tags(data_dict)
|
||||||
|
|
||||||
return jsonify(capture_obj.tags)
|
return capture_obj.tags
|
||||||
|
|
||||||
def delete(self, id):
|
def delete(self, id):
|
||||||
"""
|
"""
|
||||||
|
|
@ -225,7 +225,7 @@ class CaptureTags(View):
|
||||||
for tag in data_dict:
|
for tag in data_dict:
|
||||||
capture_obj.delete_tag(str(tag))
|
capture_obj.delete_tag(str(tag))
|
||||||
|
|
||||||
return jsonify(capture_obj.tags)
|
return capture_obj.tags
|
||||||
|
|
||||||
|
|
||||||
@Tag("captures")
|
@Tag("captures")
|
||||||
|
|
@ -240,7 +240,7 @@ class CaptureAnnotations(View):
|
||||||
if not capture_obj:
|
if not capture_obj:
|
||||||
return abort(404) # 404 Not Found
|
return abort(404) # 404 Not Found
|
||||||
|
|
||||||
return jsonify(capture_obj.annotations)
|
return capture_obj.annotations
|
||||||
|
|
||||||
def put(self, id):
|
def put(self, id):
|
||||||
"""
|
"""
|
||||||
|
|
@ -260,4 +260,4 @@ class CaptureAnnotations(View):
|
||||||
|
|
||||||
capture_obj.put_annotations(data_dict)
|
capture_obj.put_annotations(data_dict)
|
||||||
|
|
||||||
return jsonify(capture_obj.annotations)
|
return capture_obj.annotations
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ from labthings.server.view import View
|
||||||
|
|
||||||
from labthings.server.decorators import ThingProperty, Tag, doc_response
|
from labthings.server.decorators import ThingProperty, Tag, doc_response
|
||||||
|
|
||||||
from flask import jsonify, request, abort
|
from flask import request, abort
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -18,7 +18,7 @@ class SettingsProperty(View):
|
||||||
Current microscope settings, including camera and stage
|
Current microscope settings, including camera and stage
|
||||||
"""
|
"""
|
||||||
microscope = find_component("org.openflexure.microscope")
|
microscope = find_component("org.openflexure.microscope")
|
||||||
return jsonify(microscope.read_settings())
|
return microscope.read_settings()
|
||||||
|
|
||||||
def put(self):
|
def put(self):
|
||||||
"""
|
"""
|
||||||
|
|
@ -51,7 +51,7 @@ class NestedSettingsProperty(View):
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return abort(404)
|
return abort(404)
|
||||||
|
|
||||||
return jsonify(value)
|
return value
|
||||||
|
|
||||||
@doc_response(404, description="Settings key cannot be found")
|
@doc_response(404, description="Settings key cannot be found")
|
||||||
def put(self, route):
|
def put(self, route):
|
||||||
|
|
@ -78,7 +78,7 @@ class StateProperty(View):
|
||||||
Show current read-only state of the microscope
|
Show current read-only state of the microscope
|
||||||
"""
|
"""
|
||||||
microscope = find_component("org.openflexure.microscope")
|
microscope = find_component("org.openflexure.microscope")
|
||||||
return jsonify(microscope.state)
|
return microscope.state
|
||||||
|
|
||||||
|
|
||||||
@Tag("properties")
|
@Tag("properties")
|
||||||
|
|
@ -96,7 +96,7 @@ class NestedStateProperty(View):
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return abort(404)
|
return abort(404)
|
||||||
|
|
||||||
return jsonify(value)
|
return value
|
||||||
|
|
||||||
|
|
||||||
@ThingProperty
|
@ThingProperty
|
||||||
|
|
@ -106,7 +106,7 @@ class ConfigurationProperty(View):
|
||||||
Show current read-only state of the microscope
|
Show current read-only state of the microscope
|
||||||
"""
|
"""
|
||||||
microscope = find_component("org.openflexure.microscope")
|
microscope = find_component("org.openflexure.microscope")
|
||||||
return jsonify(microscope.configuration)
|
return microscope.configuration
|
||||||
|
|
||||||
|
|
||||||
@Tag("properties")
|
@Tag("properties")
|
||||||
|
|
@ -124,4 +124,4 @@ class NestedConfigurationProperty(View):
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return abort(404)
|
return abort(404)
|
||||||
|
|
||||||
return jsonify(value)
|
return value
|
||||||
|
|
|
||||||
|
|
@ -17,4 +17,4 @@ from labthings.core.tasks import (
|
||||||
|
|
||||||
|
|
||||||
# Flask things
|
# Flask things
|
||||||
from flask import abort, escape, jsonify, Response, request
|
from flask import abort, escape, Response, request
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue