소스 검색

Added CSV download to /scoreboard

pull/3/head
Adrian Short 14 년 전
부모
커밋
baf15c8e8f
4개의 변경된 파일48개의 추가작업 그리고 3개의 파일을 삭제
  1. +24
    -0
      app.rb
  2. +0
    -1
      lib/models.rb
  3. +6
    -0
      public/style.css
  4. +18
    -2
      views/scoreboard.haml

+ 24
- 0
app.rb 파일 보기

@@ -147,6 +147,30 @@ get '/about' do
haml :about
end

get '/scoreboard.csv' do
@councils = Council.all( :order => ['name'] )
labels = %w[
id
created_at
updated_at
name
slug
url
data_url
open_licence
machine_readable
start_d
end_d
]
headers "Content-Disposition" => "attachment;filename=armchair-auditor-scoreboard.csv",
"Content-Type" => "text/csv"
output = ""
for council in @councils
output += council.to_csv
end
labels.join(',') + "\n" + output
end

get '/scoreboard' do
@councils = Council.all( :order => ['name'] )
haml :scoreboard


+ 0
- 1
lib/models.rb 파일 보기

@@ -100,7 +100,6 @@ class Council
property :data_url, String, :length => 512
property :open_licence, Boolean, :default => false
property :machine_readable, Boolean, :default => false
property :grade, String, :length => 1
property :start_d, Date
property :end_d, Date


+ 6
- 0
public/style.css 파일 보기

@@ -104,6 +104,12 @@ strong
color: #000;
}

.strong
{
color: #000;
font-weight: bold;
}

table
{
border-collapse: collapse;


+ 18
- 2
views/scoreboard.haml 파일 보기

@@ -1,6 +1,10 @@
.grid_12
%h2= @page_title = "Council Spending Data Scoreboard"

%p.noprint.download
%a{ :href => "/scoreboard.csv" }
Download data as CSV

%table
%tr
%th Council
@@ -24,7 +28,19 @@
%td= council.start_d.strftime("%b %Y")
%td= council.end_d.strftime("%b %Y")
%td= council.updated_at.strftime("%d %b %Y")
%p.highlight.noprint
This scoreboard data is free for you to use according to the
%a{ :href => "http://creativecommons.org/licenses/by/3.0/"}<
Creative Commons Attribution 3.0 Unported Licence.
Please credit to
%strong
Adrian Short/Armchair Auditor
and link back to
%a{ :href => "http://armchairauditor.co.uk/scoreboard" }<
http://armchairauditor.co.uk/scoreboard
where possible.
%h3 Notes
%p


불러오는 중...
취소
저장