Update dependencies and fix deprecations

This commit is contained in:
Lexi / Zoe 2022-09-17 16:42:38 +02:00
parent 0d4fbef13d
commit 19d264a03b
Signed by: binaryDiv
GPG key ID: F8D4956E224DA232
8 changed files with 154 additions and 131 deletions

View file

@ -1,29 +0,0 @@
from datetime import datetime
from typing import Any
from flask.json import JSONEncoder as _FlaskJSONEncoder
__all__ = [
'JSONEncoder',
]
class JSONEncoder(_FlaskJSONEncoder):
"""
Custom JSON encoder built on top of the Flask JSONEncoder class.
"""
def default(self, obj: Any) -> Any:
"""
Convert any object to a JSON serializable type.
"""
# Convert datetimes to ISO format without microseconds (e.g. '2022-01-02T10:20:30+00:00')
if isinstance(obj, datetime):
return obj.isoformat(timespec='seconds')
# Use to_dict() method on objects that have it
if hasattr(obj, 'to_dict'):
return obj.to_dict()
# Fallback to the Flask JSONEncoder
return super().default(obj)