alphagov/whitehall — pull request #1096 by tekin (2013-11-27 13:49:11+00:00)
Title: Fix the cause of a couple CSV preview exceptions

https://www.pivotaltracker.com/story/show/61539604

This fixes the cause of a couple CSV preview exceptions.

1) Because only the first 10 lines where sampled to guess the encoding, it was sometimes getting it wrong (i.e. when windows chars are not present until later in the file). Now the entirety of the preview is used to check the encoding, increasing its accuracy.

2) Some CSV files use a mixture of \r\n and \n (lolz), which confuses the CSV library and causes it to throw an exception when the offending row is reached. Instead of waiting for this to happen when the preview is rendered in the template, CsvPreview now raises the exception at the point it is initialized, allowing it to be handled more
gracefully.