Now supports non-indexed arrays of objects as GET parameters

This commit is contained in:
Christophe de Vienne 2012-12-18 10:26:17 +01:00
parent 9aa7055f55
commit e68c9e99b6

@ -86,24 +86,50 @@ def array_from_params(datatype, params, path, hit_paths):
return [
from_param(datatype.item_type, value)
for value in params.getall(path)]
else:
indexes = set()
r = re.compile('^%s\[(?P<index>\d+)\]' % re.escape(path))
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:
indexes.add(int(m.group('index')))
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
if not indexes:
return Unset
indexes = set()
r = re.compile('^%s\[(?P<index>\d+)\]' % re.escape(path))
indexes = list(indexes)
indexes.sort()
for p in params.keys():
m = r.match(p)
if m:
indexes.add(int(m.group('index')))
return [from_params(datatype.item_type, params,
'%s[%s]' % (path, index), hit_paths)
for index in indexes]
if not indexes:
return Unset
indexes = list(indexes)
indexes.sort()
return [from_params(datatype.item_type, params,
'%s[%s]' % (path, index), hit_paths)
for index in indexes]
@from_params.when_type(DictType)