Added template helpers functions to encode and decode special charact…#6747
Conversation
…ers in the filters for datatables view.
amercader
left a comment
There was a problem hiding this comment.
Thanks @JVickery-TBS, see comment below.
Also we should a small test for this. Something in ckan/tests/lib/test_helpers.py that checks that the output of the functions is the expected one.
Cheers
|
|
||
| def get_helpers(self): | ||
| return{ | ||
| 'encode_datatables_request_filters': helpers.encode_datatables_request_filters |
There was a problem hiding this comment.
@JVickery-TBS This sounds like a valuable helper for other view plugins as well. Shall we rename them to encode/decode_view_request_filters move it to ckan/lib/helpers.py so it's available to everybody?
| def encode_datatables_request_filters(): | ||
| if 'filters' not in request.params: | ||
| return '' | ||
| return escape(quote(str(request.params['filters'].encode('utf-8')).encode('ascii'))) |
There was a problem hiding this comment.
Use request.args instead, as that's the Flask supported name. Same in the function below
…n global helpers. Modified the encoding function. Wrote tests for the two new helpers. Modified ckanext/datatablesview templates and methods to use new global helpers.
…and colons prior to decoding, returning a dictionary now. Added todo comments.
amercader
left a comment
There was a problem hiding this comment.
This looks good @JVickery-TBS, see a small comment and can you fix the conflicts with master before we merge? cheers
|
|
||
| function _appendDropdowns(dropdowns, resourceId, template, fields, filters) { | ||
| //TODO: handle decoding the filters object to be able to properly available in the current filter dropdowns | ||
| console.log(filters); |
There was a problem hiding this comment.
Maybe remove this to avoid noise
| console.log(filters); | |
| console.log(filters); |
…alues of the filters. Modified the remove filter event to remove the correct index. Modified the decode_view_request_filters method, fixing nested arrays. Modified datatables views blueprint merge_filters method to work with the new filters helper. Modified the test for the new helper method return.
|
@amercader Hey! Okay I believe I have accomplished the desired affect here with the view filters. There were cases in which users may have colons (:) and/or pipes (|) in their data. This would break the filters because the filters are flattened. The filter names and values are separated by colons and multiple filters are separated by pipes. So what will be done now is that the filter names and values will be URI encoded in JS before they are flattened into the colon and pipe string. The new helper now does the separation of the colons and pipes, THEN decodes the filter names and values. The helper now returns a dictionary, the properties being the filter names, and the values being arrays containing the filter values. Ultimately this will allows for special accented characters in filter names and values. It will also allow for colons and pipes in the filter names and values. |
|
Thanks @JVickery-TBS, can you add a |
|
@amercader |
|
Thanks @JVickery-TBS |
…ers in the filters for datatables view.
Fixes #
Proposed fixes:
Encoding and decoding special characters for the datatables view filters. Special characters in fanstatic throw ansii encoding errors.
Features:
Please [X] all the boxes above that apply