Parsing of Editor POST data

Parsing of Editor POST data

stephanbstephanb Posts: 36Questions: 11Answers: 0
edited February 2021 in Free community support

The environment I am working in does not lend itself to using the pre-built backend libraries. My environment is in Python.
That said, what would be be an appropriate way to parse the edit data POSTed by the Editor?

('data[7][fields][fieldname]', 'newvalue')
('action', 'edit')

Obviously I need to isolate the "7" as it is the primary key of my record, the field, and the new data, before I can persist it in my database. Then I need to send back the json of the updated record.

I could parse this with all kinds of string operations but I feel like there probably is something more basic I could use to get the values. What am I not seeing here?

Stephan

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,743Questions: 1Answers: 10,111 Site admin
    Answer ✓

    I can’t help you with the Python aspect I’m afraid (as I don’t know Python), but what might be easier for you is having Editor submit the data as JSON so you can parse that (presumably Python has JSON parsing either built in or libraries available). You can do that using something like:

    editor.on(‘preSubmit’, function (e, data, action) {
      data.json = JSON.stringify(data);
    });
    

    Then you can just decode the JSON on the json property that is submitting.

    Allan

  • allanallan Posts: 61,743Questions: 1Answers: 10,111 Site admin

    I should also say that there are probably some Python libraries available to parse the kind of data that Editor sends by default - they are just http parameters with array syntax which many server-side environments will automatically parse into arrays / objects. Python obviously isn’t one that does...!

    Allan

  • kthorngrenkthorngren Posts: 20,322Questions: 26Answers: 4,773

    I ran into the same problem when I was first learning and didn't know about sending JSON from the Editor. I wrote a parser, probably not a good one, to parse the default format. It still works so I haven't changed but would suggest using JSON as Allan mentioned.

    I don't use any of the third party libraries but there are some for Django. Not sure if there are others but it would save you a lot of work if you can find one for Editor.

    Kevin

  • stephanbstephanb Posts: 36Questions: 11Answers: 0

    Thanks for the help guys. I'll use the JSON.stringify() method. Should work like a charm.

This discussion has been closed.