Friday, February 26, 2016

Parsing PHP-style GET parameters for lists and dicts in Django

I need to work with DataTables, a jQuery-plugin for sortable HTML tables.

It sends Ajax GET requests with parameters like the following (but urlencoded, of course):

columns[0][data]=0
columns[0][name]=
columns[0][searchable]=true
columns[0][orderable]=true
columns[0][search][value]=
columns[0][search][regex]=false
columns[1][data]=1
columns[1][name]=
columns[1][searchable]=true
columns[1][orderable]=true
columns[1][search][value]=
columns[1][search][regex]=false
columns[2][data]=2
columns[2][name]=
columns[2][searchable]=true
columns[2][orderable]=true
columns[2][search][value]=
columns[2][search][regex]=false

I think this plugin was written with PHP in mind, and that PHP can automatically convert that into a list of dicts that would in Python look something like

columns = [
    {"data": 0, "name": '', "searchable": True, "orderable": True, "search": {"value": '', "regex": False}},
    {"data": 1, "name": '', "searchable": True, "orderable": True, "search": {"value": '', "regex": False}},
    {"data": 2, "name": '', "searchable": True, "orderable": True, "search": {"value": '', "regex": False}},
]

Does anybody know of any Python or Django app / library that does this?

Would it be possible to do this in a FormField? (convert many GET parameters into one field)

Does anybody know what this technique is called? My Google-fu is failing, and if I'm going write a field for this I need to name it.

Thanks,
Remco Gerlich

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAFAGLK3rG6mEGaNf4QHQ3xffhtkyDm9QrwmfNxTr%3DQpeqkBNTA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment