2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2026-02-08 11:49:50 +00:00

more progress to better serializer

This commit is contained in:
2025-11-22 11:38:00 +02:00
parent f52eab842f
commit 7889162420
2 changed files with 61 additions and 57 deletions

View File

@@ -326,9 +326,6 @@ def shared_use_machine(request):
else:
print(f" - shared use cookie exists, but has wrong value: '{cookie_txt}' not '{PUBLIC_LAPTOP_COOKIE_TEXT}'")
return True
def get_cookie(request):
"""The initial idea of having a default turned out to be a bad idea as people just ignore the field.
@@ -539,6 +536,18 @@ class WriteAndCommitError(Exception):
def __str__(self):
return f"WriteAndCommitError: {self.message}"
# Custom JSON Encoder to handle non-serializable types
class CustomJSONEncoder(json.JSONEncoder):
def default(self, obj):
# Convert datetime objects to ISO 8601 string format
if isinstance(obj, datetime):
return obj.isoformat()
# Convert Decimal objects to string
if isinstance(obj, Decimal):
# Use str() for perfect precision, or float() for numerical representation
return str(obj)
# Let the base class handle other types
return json.JSONEncoder.default(self, obj)
"""The following is a Bard converted version of Radosts's MIT copyrighted Javascript on 2023-10-27
with hand-editing.