diff options
author | Francis Irving <francis@mysociety.org> | 2010-01-28 10:35:16 +0000 |
---|---|---|
committer | Francis Irving <francis@mysociety.org> | 2010-01-28 10:35:16 +0000 |
commit | 5a8661096b0a5ae6fac74a827f80e6d47d1995b5 (patch) | |
tree | 86e9953cf60877714ff8d32ce7b3da73df2334de /app/controllers/public_body_controller.rb | |
parent | 5f281051933391afc4bea07c449bd881e31b2704 (diff) |
Download CSV with list of all authorities:
Diffstat (limited to 'app/controllers/public_body_controller.rb')
-rw-r--r-- | app/controllers/public_body_controller.rb | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/app/controllers/public_body_controller.rb b/app/controllers/public_body_controller.rb index 5a591878f..192740217 100644 --- a/app/controllers/public_body_controller.rb +++ b/app/controllers/public_body_controller.rb @@ -6,6 +6,8 @@ # # $Id: public_body_controller.rb,v 1.8 2009-09-14 13:27:00 francis Exp $ +require 'csv' + class PublicBodyController < ApplicationController # XXX tidy this up with better error messages, and a more standard infrastructure for the redirect to canonical URL def show @@ -99,5 +101,42 @@ class PublicBodyController < ApplicationController @tag = params[:tag] redirect_to list_public_bodies_url(:tag => @tag) end + + def list_all_csv + public_bodies = PublicBody.find(:all) + report = StringIO.new + CSV::Writer.generate(report, ',') do |title| + title << [ + 'Name', + 'Short name', + 'URL name', + 'Tags', + 'Home page', + 'Publication scheme', + 'Charity number', + 'Created at', + 'Updated at', + 'Version', + ] + public_bodies.each do |public_body| + title << [ + public_body.name, + public_body.short_name, + public_body.url_name, + public_body.tag_string, + public_body.calculated_home_page, + public_body.publication_scheme, + public_body.charity_number, + public_body.created_at, + public_body.updated_at, + public_body.version, + ] + end + end + report.rewind + send_data(report.read, :type=> 'text/csv; charset=utf-8; header=present', + :filename => 'all-authorities.csv', + :disposition =>'attachment', :encoding => 'utf8') + end end |