Skip to content

Instantly share code, notes, and snippets.

@hugowan
Last active June 5, 2017 10:38
Show Gist options
  • Save hugowan/84d2ced1fabed0400040f4a44ee19177 to your computer and use it in GitHub Desktop.
Save hugowan/84d2ced1fabed0400040f4a44ee19177 to your computer and use it in GitHub Desktop.
@staticmethod
def getArrayParam(request, key):
rs = {}
for k, v in request.POST.iteritems():
if re.match(key + '\[', k):
newKey = re.findall(r'\[(.*?)\]', k)
if len(newKey) == 1:
rs[newKey[0]] = v
else:
if newKey[0] not in rs:
rs[newKey[0]] = {}
else:
rs[newKey[0]].update({newKey[1]: v})
return rs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment