mirror of https://github.com/JohnHammond/CTFd.git
Fix serializer
parent
593fed300b
commit
89ade49695
|
@ -1,6 +1,6 @@
|
|||
import json
|
||||
import six
|
||||
from collections import OrderedDict
|
||||
from collections import defaultdict, OrderedDict
|
||||
|
||||
from CTFd.utils.exports.encoders import JSONEncoder
|
||||
|
||||
|
@ -9,7 +9,7 @@ class JSONSerializer(object):
|
|||
def __init__(self, query, fileobj):
|
||||
self.query = query
|
||||
self.fileobj = fileobj
|
||||
self.buckets = []
|
||||
self.buckets = defaultdict(list)
|
||||
|
||||
def serialize(self):
|
||||
for row in self.query:
|
||||
|
@ -17,7 +17,7 @@ class JSONSerializer(object):
|
|||
self.close()
|
||||
|
||||
def write(self, path, result):
|
||||
self.buckets.append([result])
|
||||
self.buckets[path].append(result)
|
||||
|
||||
def wrap(self, result):
|
||||
result = OrderedDict([("count", len(result)), ("results", result)])
|
||||
|
@ -25,7 +25,7 @@ class JSONSerializer(object):
|
|||
return result
|
||||
|
||||
def close(self):
|
||||
for result in self.buckets:
|
||||
for path, result in self.buckets.items():
|
||||
result = self.wrap(result)
|
||||
|
||||
# Certain databases (MariaDB) store JSON as LONGTEXT.
|
||||
|
|
Loading…
Reference in New Issue