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 | |
parent | 5f281051933391afc4bea07c449bd881e31b2704 (diff) |
Download CSV with list of all authorities:
-rw-r--r-- | app/controllers/public_body_controller.rb | 39 | ||||
-rw-r--r-- | app/views/public_body/list.rhtml | 53 | ||||
-rw-r--r-- | config/routes.rb | 1 |
3 files changed, 69 insertions, 24 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 diff --git a/app/views/public_body/list.rhtml b/app/views/public_body/list.rhtml index 9b03e65d0..b1be9272a 100644 --- a/app/views/public_body/list.rhtml +++ b/app/views/public_body/list.rhtml @@ -1,32 +1,37 @@ <div id="body_sidebar"> -<h1>Show only...</h1> - -<h2>Alphabet</h2> -<ul><li> - <%= render :partial => 'alphabet' %> -</li></ul> - -<% first_row = true %> -<% for row in PublicBodyCategories::CATEGORIES_WITH_HEADINGS %> - <% if row.instance_of?(Array) %> - <li> - <%= link_to_unless (@tag == row[0]), row[1], list_public_bodies_url(:tag => row[0]) %> - </li> - <% else %> - <% if not first_row %> - </ul> + <h1>Show only...</h1> + + <h2>Alphabet</h2> + <ul><li> + <%= render :partial => 'alphabet' %> + </li></ul> + + <% first_row = true %> + <% for row in PublicBodyCategories::CATEGORIES_WITH_HEADINGS %> + <% if row.instance_of?(Array) %> + <li> + <%= link_to_unless (@tag == row[0]), row[1], list_public_bodies_url(:tag => row[0]) %> + </li> <% else %> - <% first_row = false %> + <% if not first_row %> + </ul> + <% else %> + <% first_row = false %> + <% end %> + <h2><%=h row%></h2> + <ul> <% end %> - <h2><%=h row%></h2> - <ul> <% end %> -<% end %> -</ul> -<p> -<a href="/help/about#missing_body">Are we missing a public authority?</a> -</p> + </ul> + + <p> + <a href="/help/about#missing_body">Are we missing a public authority?</a> + </p> + <p> + <%= link_to "List of all authorities (CSV)", all_public_bodies_csv_url() %> + </p> + </div> <% @title = "Public authorities - " + @description %> diff --git a/config/routes.rb b/config/routes.rb index 81739b803..754d67da1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -69,6 +69,7 @@ ActionController::Routing::Routes.draw do |map| body.list_public_bodies_redirect "/local/:tag", :action => 'list_redirect' body.show_public_body "/body/:url_name", :action => 'show' body.view_public_body_email "/body/:url_name/view_email", :action => 'view_email' + body.all_public_bodies_csv "/body/all-authorities.csv", :action => 'list_all_csv' end map.with_options :controller => 'comment' do |comment| |