aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/controllers/public_body_controller.rb15
-rw-r--r--app/models/info_request.rb2
-rw-r--r--app/models/public_body.rb11
3 files changed, 15 insertions, 13 deletions
diff --git a/app/controllers/public_body_controller.rb b/app/controllers/public_body_controller.rb
index 95d936e54..b8ea82a66 100644
--- a/app/controllers/public_body_controller.rb
+++ b/app/controllers/public_body_controller.rb
@@ -7,7 +7,7 @@
#
# $Id: public_body_controller.rb,v 1.8 2009-09-14 13:27:00 francis Exp $
-require 'csv'
+require 'fastercsv'
class PublicBodyController < ApplicationController
# XXX tidy this up with better error messages, and a more standard infrastructure for the redirect to canonical URL
@@ -148,10 +148,10 @@ class PublicBodyController < ApplicationController
end
def list_all_csv
- public_bodies = PublicBody.find(:all, :order => 'url_name')
- report = StringIO.new
- CSV::Writer.generate(report, ',') do |title|
- title << [
+ public_bodies = PublicBody.find(:all, :order => 'url_name',
+ :include => [:translations, :tags])
+ report = FasterCSV.generate() do |csv|
+ csv << [
'Name',
'Short name',
# deliberately not including 'Request email'
@@ -164,7 +164,7 @@ class PublicBodyController < ApplicationController
'Version',
]
public_bodies.each do |public_body|
- title << [
+ csv << [
public_body.name,
public_body.short_name,
# DO NOT include request_email (we don't want to make it
@@ -179,8 +179,7 @@ class PublicBodyController < ApplicationController
]
end
end
- report.rewind
- send_data(report.read, :type=> 'text/csv; charset=utf-8; header=present',
+ send_data(report, :type=> 'text/csv; charset=utf-8; header=present',
:filename => 'all-authorities.csv',
:disposition =>'attachment', :encoding => 'utf8')
end
diff --git a/app/models/info_request.rb b/app/models/info_request.rb
index f2d8929bc..ed54da840 100644
--- a/app/models/info_request.rb
+++ b/app/models/info_request.rb
@@ -35,7 +35,7 @@ class InfoRequest < ActiveRecord::Base
belongs_to :user
validate :must_be_internal_or_external
- belongs_to :public_body
+ belongs_to :public_body, :counter_cache => true
validates_presence_of :public_body_id
has_many :outgoing_messages, :order => 'created_at'
diff --git a/app/models/public_body.rb b/app/models/public_body.rb
index fb30da234..77da81d4c 100644
--- a/app/models/public_body.rb
+++ b/app/models/public_body.rb
@@ -45,6 +45,8 @@ class PublicBody < ActiveRecord::Base
has_many :censor_rules, :order => 'created_at desc'
has_tag_string
+ before_save :set_api_key, :set_default_publication_scheme
+
translates :name, :short_name, :request_email, :url_name, :notes, :first_letter, :publication_scheme
@@ -89,13 +91,13 @@ class PublicBody < ActiveRecord::Base
end
end
- def after_initialize
+ def set_default_publication_scheme
# Make sure publication_scheme gets the correct default value.
# (This would work automatically, were publication_scheme not a translated attribute)
self.publication_scheme = "" if self.publication_scheme.nil?
end
- def before_save
+ def set_api_key
self.api_key = SecureRandom.base64(33) if self.api_key.nil?
end
@@ -184,7 +186,7 @@ class PublicBody < ActiveRecord::Base
end
acts_as_versioned
- self.non_versioned_columns << 'created_at' << 'updated_at' << 'first_letter' << 'api_key'
+ self.non_versioned_columns << 'created_at' << 'updated_at' << 'first_letter' << 'api_key' << 'info_requests_count'
class Version
attr_accessor :created_at
@@ -549,9 +551,10 @@ class PublicBody < ActiveRecord::Base
def notes_as_html
self.notes
end
+
def notes_without_html
# assume notes are reasonably behaved HTML, so just use simple regexp on this
- self.notes.nil? ? '' : self.notes.gsub(/<\/?[^>]*>/, "")
+ @notes_without_html ||= (self.notes.nil? ? '' : self.notes.gsub(/<\/?[^>]*>/, ""))
end
def json_for_api