I decided to try writing a generic array converter as a middleware:

import re
class ParamsMiddleware:
        patt = re.compile("^([a-zA-Z_]\w*)\[\(d*)\]$")
        LARGE_INT = 2**30

        def process_request(self, request):
                if(request.POST):
                        post = request.POST.copy()
                        new_vals = {}
                        for name, value in post.items():
                                match =
ParamsMiddleware.patt.match(name)
                                if not match:
                                        continue
                                value = post[name]
                                del post.data[name]
                                new_name = match.group(1)
                                try:
                                        idx = int(match.group(2))
                                except ValueError:
                                        # just append it to the end
                                        # se use the largest number for
sorting
                                        idx =
ParamsMiddleware.LARGE_INT
                                vals = new_vals.setdefault(new_name,
[])
                                vals.append((idx, value))
                        if(new_vals):
                                for name, vals in new_vals.items():
                                        vals.sort(key=lambda x: x[0])
                                        post[name] = [x[1] for x in
vals]
                                post._mutable = False
                                request._post = post
                return None

Reply via email to