fix json_encoder for flask 2.x
This commit is contained in:
parent
59f5d4529d
commit
e6c143ad92
|
@ -6,7 +6,7 @@ from flask_cors import CORS
|
||||||
from datetime import datetime, date
|
from datetime import datetime, date
|
||||||
from flask.json import jsonify
|
from flask.json import jsonify
|
||||||
from json import JSONEncoder
|
from json import JSONEncoder
|
||||||
from flask.json.provider import JSONProvider
|
from flask.json.provider import JSONProvider
|
||||||
from sqlalchemy.exc import OperationalError
|
from sqlalchemy.exc import OperationalError
|
||||||
from werkzeug.exceptions import HTTPException
|
from werkzeug.exceptions import HTTPException
|
||||||
|
|
||||||
|
@ -14,7 +14,6 @@ from flaschengeist import logger
|
||||||
from flaschengeist.controller import pluginController
|
from flaschengeist.controller import pluginController
|
||||||
from flaschengeist.utils.hook import Hook
|
from flaschengeist.utils.hook import Hook
|
||||||
from flaschengeist.config import configure_app
|
from flaschengeist.config import configure_app
|
||||||
from flaschengeist.plugins import Plugin
|
|
||||||
|
|
||||||
from flaschengeist.database import db
|
from flaschengeist.database import db
|
||||||
|
|
||||||
|
@ -39,8 +38,8 @@ class CustomJSONEncoder(JSONEncoder):
|
||||||
return list(iterable)
|
return list(iterable)
|
||||||
return JSONEncoder.default(self, o)
|
return JSONEncoder.default(self, o)
|
||||||
|
|
||||||
class CustomJSONProvider(JSONProvider):
|
|
||||||
|
|
||||||
|
class CustomJSONProvider(JSONProvider):
|
||||||
ensure_ascii: bool = True
|
ensure_ascii: bool = True
|
||||||
sort_keys: bool = True
|
sort_keys: bool = True
|
||||||
|
|
||||||
|
@ -62,8 +61,8 @@ def load_plugins(app: Flask):
|
||||||
try:
|
try:
|
||||||
# Load class
|
# Load class
|
||||||
cls = plugin.entry_point.load()
|
cls = plugin.entry_point.load()
|
||||||
#plugin = cls.query.get(plugin.id) if plugin.id is not None else plugin
|
# plugin = cls.query.get(plugin.id) if plugin.id is not None else plugin
|
||||||
#plugin = db.session.query(cls).get(plugin.id) if plugin.id is not None else plugin
|
# plugin = db.session.query(cls).get(plugin.id) if plugin.id is not None else plugin
|
||||||
plugin = db.session.get(cls, plugin.id) if plugin.id is not None else plugin
|
plugin = db.session.get(cls, plugin.id) if plugin.id is not None else plugin
|
||||||
# Custom loading tasks
|
# Custom loading tasks
|
||||||
plugin.load()
|
plugin.load()
|
||||||
|
@ -79,9 +78,9 @@ def load_plugins(app: Flask):
|
||||||
logger.info(f"Loaded plugin: {plugin.name}")
|
logger.info(f"Loaded plugin: {plugin.name}")
|
||||||
app.config["FG_PLUGINS"][plugin.name] = plugin
|
app.config["FG_PLUGINS"][plugin.name] = plugin
|
||||||
|
|
||||||
|
|
||||||
def create_app(test_config=None, cli=False):
|
def create_app(test_config=None, cli=False):
|
||||||
app = Flask("flaschengeist")
|
app = Flask("flaschengeist")
|
||||||
# app.json_encoder = CustomJSONEncoder
|
|
||||||
app.json_provider_class = CustomJSONProvider
|
app.json_provider_class = CustomJSONProvider
|
||||||
app.json = CustomJSONProvider(app)
|
app.json = CustomJSONProvider(app)
|
||||||
CORS(app)
|
CORS(app)
|
||||||
|
|
Loading…
Reference in New Issue