Extract and improve CSV report generation. Fixes #347

* Unified structure should make sure we always convert ActiveRecord
  objects to string somehow (fixing a commonly reoccurring bug), and
  that we strip out newlines.
* Moving CSV generation out of the template layer avoids the
  HTML-escaping problem reported here. Also, more testable.