django-rest-framework-csv
django-rest-framework-csv copied to clipboard
newline handling in restframework csv
Hi, As I understand csv parser removes newline characters here: https://github.com/mjumbewu/django-rest-framework-csv/blob/master/rest_framework_csv/parsers.py#L25-L26
Lets say there a cell in csv where value is something like: ''' Nature Foliage Trees '''
Now we want to parse this particular cell as ["Nature", "Foliage", "Trees"] But with current parser code we can't? because after splitlines() the cell becomes "NatureFoliageTrees"?
Is there a way to handle the issue I am facing?
I work with @drake01. Here's an example file, saved from Excel for Mac:
kingdom,keywords
plant,"leaves
roots
flowers"
In use:
>>> print(CSVParser().parse(data))
# expected/desired output
[{'kingdom': 'plant', 'keywords': 'leaves\nroots\nflowers'}]
# actual output
[{'kingdom': 'plant', 'keywords': 'leavesrootsflowers'}]
Thanks a lot for this example @cvn. This one is more detailed and covers more cases.
Looks like this is a duplicate of #24.
We were able to create new Parser class derived from rest_framework_csv.parsers.CSVParser and override parse method.
In parse method, stream data can be split using: stream.splitlines(keepends=True)
Anyone facing this issue can use it.