Note that there are some explanatory texts on larger screens.

plurals
  1. POParsing dictionary-like URL parameters in Python
    primarykey
    data
    text
    <p>I'm working on implementing server-side filtering to serve KendoUI's Grid component, using Python.</p> <p>The problem I'm facing is that the AJAX call that it generates by default seems to be incompatible with both Flask's built-in URL parser and Python's <code>urlparse</code> module.</p> <p>Here's a contrived sample of the type of query string I'm having trouble with: <code>a=b&amp;c=d&amp;foo[bar]=baz&amp;foo[baz]=qis&amp;foo[qis]=bar</code></p> <p>Here's the result I'm going for:</p> <pre><code>{ 'a': 'b', 'c': 'd', 'foo': { 'bar': 'baz', 'baz': 'qis', 'qis': bar' } } </code></pre> <p>Unfortunately, here's the <code>request.args</code> you get from this, if passed to a Flask endpoint:</p> <pre><code>{ 'a': 'b', 'c': 'd', 'foo[bar]': 'baz' 'foo[baz]': 'qis' 'foo[qis]': 'bar' } </code></pre> <p>Worse yet, in practice, the structure can be several layers deep. A basic call where you're filtering the column <code>foo</code> to only rows where the value is equal to <code>'bar'</code> will produce the following:</p> <pre><code>{ 'filter[logic]': 'and', 'filter[filters][0][value]': 'bar', 'filter[filters][0][field]': 'foo', 'filter[filters][0][operator]': 'eq' } </code></pre> <p>I checked the RFC, and it requires that the query string contain only "non-hierarchical" data. While I believe it's referring to the object the URI represents, there is no provision for this type of data structure in the specification that I can find.</p> <p>I begin to write a function that would take a dictionary of params and return the nested construct they represented, but I soon realized that it was nuanced problem, and that surely someone out there has had this trouble before.</p> <p>Is anyone aware of either a module that will parse these parameters in the way I'm wanting, or an elegant way to parse them that I've perhaps overlooked?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload