Files
pretix_cgo/src/pretix/helpers/json.py
Raphael Michel 87424c25de Logging: Automatically serialize file objects
Sentry PRETIXEU-RY
2019-01-30 10:59:00 +01:00

19 lines
503 B
Python

from django.core.files import File
from i18nfield.utils import I18nJSONEncoder
from pretix.base.reldate import RelativeDateWrapper
class CustomJSONEncoder(I18nJSONEncoder):
def default(self, obj):
if isinstance(obj, RelativeDateWrapper):
return obj.to_string()
elif isinstance(obj, File):
return obj.name
else:
return super().default(obj)
def safe_string(original):
return original.replace("<", "\\u003C").replace(">", "\\u003E")