mirror of https://github.com/JohnHammond/CTFd.git
Make minified JSON
parent
89ade49695
commit
41a0ebc68d
|
@ -1,11 +0,0 @@
|
|||
import json
|
||||
from datetime import datetime, date
|
||||
from decimal import Decimal
|
||||
|
||||
|
||||
class JSONEncoder(json.JSONEncoder):
|
||||
def default(self, obj):
|
||||
if isinstance(obj, (datetime, date)):
|
||||
return obj.isoformat()
|
||||
if isinstance(obj, Decimal):
|
||||
return str(obj)
|
|
@ -1,8 +1,16 @@
|
|||
import json
|
||||
import six
|
||||
from collections import defaultdict, OrderedDict
|
||||
from datetime import datetime, date
|
||||
from decimal import Decimal
|
||||
|
||||
from CTFd.utils.exports.encoders import JSONEncoder
|
||||
|
||||
class JSONEncoder(json.JSONEncoder):
|
||||
def default(self, obj):
|
||||
if isinstance(obj, (datetime, date)):
|
||||
return obj.isoformat()
|
||||
if isinstance(obj, Decimal):
|
||||
return str(obj)
|
||||
|
||||
|
||||
class JSONSerializer(object):
|
||||
|
@ -20,8 +28,9 @@ class JSONSerializer(object):
|
|||
self.buckets[path].append(result)
|
||||
|
||||
def wrap(self, result):
|
||||
result = OrderedDict([("count", len(result)), ("results", result)])
|
||||
result["meta"] = {}
|
||||
result = OrderedDict(
|
||||
[("count", len(result)), ("results", result), ("meta", {})]
|
||||
)
|
||||
return result
|
||||
|
||||
def close(self):
|
||||
|
@ -40,5 +49,5 @@ class JSONSerializer(object):
|
|||
except ValueError:
|
||||
pass
|
||||
|
||||
data = json.dumps(result, cls=JSONEncoder, indent=2)
|
||||
data = json.dumps(result, cls=JSONEncoder, separators=(",", ":"))
|
||||
self.fileobj.write(data.encode("utf-8"))
|
||||
|
|
Loading…
Reference in New Issue