Now supports non-indexed arrays of objects as GET parameters
This commit is contained in:
@@ -86,7 +86,33 @@ def array_from_params(datatype, params, path, hit_paths):
|
|||||||
return [
|
return [
|
||||||
from_param(datatype.item_type, value)
|
from_param(datatype.item_type, value)
|
||||||
for value in params.getall(path)]
|
for value in params.getall(path)]
|
||||||
else:
|
|
||||||
|
if iscomplex(datatype.item_type):
|
||||||
|
attributes = set()
|
||||||
|
r = re.compile('^%s\.(?P<attrname>[^\.])' % re.escape(path))
|
||||||
|
for p in params.keys():
|
||||||
|
m = r.match(p)
|
||||||
|
if m:
|
||||||
|
attributes.add(m.group('attrname'))
|
||||||
|
if attributes:
|
||||||
|
value = []
|
||||||
|
for attrdef in list_attributes(datatype.item_type):
|
||||||
|
attrpath = '%s.%s' % (path, attrdef.key)
|
||||||
|
hit_paths.add(attrpath)
|
||||||
|
attrvalues = params.getall(attrpath)
|
||||||
|
if len(value) < len(attrvalues):
|
||||||
|
value[-1:] = [
|
||||||
|
datatype.item_type()
|
||||||
|
for i in xrange(len(attrvalues) - len(value))
|
||||||
|
]
|
||||||
|
for i, attrvalue in enumerate(attrvalues):
|
||||||
|
setattr(
|
||||||
|
value[i],
|
||||||
|
attrdef.key,
|
||||||
|
from_param(attrdef.datatype, attrvalue)
|
||||||
|
)
|
||||||
|
return value
|
||||||
|
|
||||||
indexes = set()
|
indexes = set()
|
||||||
r = re.compile('^%s\[(?P<index>\d+)\]' % re.escape(path))
|
r = re.compile('^%s\[(?P<index>\d+)\]' % re.escape(path))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user