Browse Source

Added /scoreboard page

pull/3/head
Adrian Short 14 years ago
parent
commit
6a0fdb88a3
3 changed files with 58 additions and 0 deletions
  1. +9
    -0
      app.rb
  2. +23
    -0
      lib/models.rb
  3. +26
    -0
      views/scoreboard.haml

+ 9
- 0
app.rb View File

@@ -10,6 +10,10 @@ helpers do
def commify(amount)
amount.to_s.reverse.gsub(/(\d\d\d)(?=\d)(?!\d*\.)/,'\1,').reverse
end
def yesno(boolean)
boolean == true ? 'Yes' : 'No'
end
end

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

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

not_found do
haml :not_found
end

+ 23
- 0
lib/models.rb View File

@@ -88,5 +88,28 @@ class Supplier
end
end

class Council
include DataMapper::Resource
property :id, Serial
property :created_at, DateTime
property :updated_at, DateTime
property :name, String, :length => 255, :required => true
property :slug, String, :length => 255
property :url, String, :length => 255
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
before :save, :slugify

def slugify
@slug = @name.gsub(/[^\w\s-]/, '').gsub(/\s+/, '-').downcase
end
end

DataMapper.setup(:default, ENV['DATABASE_URL'] || "sqlite3://#{Dir.pwd}/db.sqlite3")
DataMapper.auto_upgrade!

+ 26
- 0
views/scoreboard.haml View File

@@ -0,0 +1,26 @@
.grid_12
%h2= @page_title = "Council Spending Data Scoreboard"
%table
%tr
%th Council
%th Data URL
%th Open licence?
%th Machine readable?
%th Start
%th End
%th Updated
- for council in @councils
%tr
%td
%a{ :href => council.url }
= council.name
%td
%a{ :href => council.data_url }
data
%td= yesno(council.open_licence)
%td= yesno(council.machine_readable)
%td= council.start_d.strftime("%b %Y")
%td= council.end_d.strftime("%b %Y")
%td= council.updated_at.strftime("%d %b %Y")

Loading…
Cancel
Save