diff options
-rw-r--r-- | app/models/public_body.rb | 60 | ||||
-rwxr-xr-x | script/import-public-body-csv | 10 | ||||
-rw-r--r-- | todo.txt | 13 |
3 files changed, 46 insertions, 37 deletions
diff --git a/app/models/public_body.rb b/app/models/public_body.rb index df09ba2be..3f083d15a 100644 --- a/app/models/public_body.rb +++ b/app/models/public_body.rb @@ -22,7 +22,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: public_body.rb,v 1.25 2008-02-28 12:29:43 francis Exp $ +# $Id: public_body.rb,v 1.26 2008-02-28 15:17:46 francis Exp $ require 'csv' @@ -96,39 +96,41 @@ class PublicBody < ActiveRecord::Base # Import from CSV def self.import_csv(csv, tag) - existing_bodies = PublicBody.find_by_tag(tag) + ActiveRecord::Base.transaction do + existing_bodies = PublicBody.find_by_tag(tag) - bodies_by_name = {} - for existing_body in existing_bodies - bodies_by_name[existing_body.name] = existing_body - end + bodies_by_name = {} + for existing_body in existing_bodies + bodies_by_name[existing_body.name] = existing_body + end - CSV::Reader.parse(csv) do |row| - name = row[1] - email = row[2] - next if name.nil? or email.nil? - - name.strip! - email.strip! - print name, " ", email, "\n" - - if bodies_by_name[name] - public_body = bodies_by_name[name] - if public_body.request_email != email - public_body.request_email = email - public_body.last_edit_editor = 'import_csv' - public_body.last_edit_comment = 'Updated from spreadsheet' - public_body.save + CSV::Reader.parse(csv) do |row| + name = row[1] + email = row[2] + next if name.nil? or email.nil? + + name.strip! + email.strip! + print name, " ", email, "\n" + + if bodies_by_name[name] + public_body = bodies_by_name[name] + if public_body.request_email != email + public_body.request_email = email + public_body.last_edit_editor = 'import_csv' + public_body.last_edit_comment = 'Updated from spreadsheet' + public_body.save + end + else + public_body = PublicBody.new(:name => name, :request_email => email, :complaint_email => "", :short_name => "", :last_edit_editor => "import_csv", :last_edit_comment => 'Created from spreadsheet') + public_body.save! # XXX shouldn't need this save, but without it the PublicBodyTag doesn't validate as no PublicBody id, and there is no harm cause we're in a transaction + public_body.tag_string = tag + public_body.save! end - else - public_body = PublicBody.new(:name => name, :request_email => email, :complaint_email => "", :short_name => "", :last_edit_editor => "import_csv", :last_edit_comment => 'Created from spreadsheet') - public_body.tag_string = tag - raise public_body.public_body_tags.to_yaml - public_body.save! end - end - # XXX what about if they are deleted? + # XXX what about if they are deleted? + end end end diff --git a/script/import-public-body-csv b/script/import-public-body-csv new file mode 100755 index 000000000..d29e52770 --- /dev/null +++ b/script/import-public-body-csv @@ -0,0 +1,10 @@ +#!/bin/bash + +LOC=`dirname $0` + +# Arguments are: +# - tag to use for public bodies from this spreadsheet + +$LOC/runner 'PublicBody.import_csv(STDIN.read, "'$1'")' + + @@ -20,10 +20,6 @@ Next Update test code -Make it link to other similar requests by same person to same place - http://foi.mysociety.org/request/team_foundation_server_backup_pr - http://foi.mysociety.org/request/all_computer_software_source_cod - Search and replace text "FOI" and "Freedom of Information" out the way more - but put it in the title tag "public body" --> "public authority"? @@ -57,10 +53,10 @@ Add lots more UNIQUE indices Merge workflow into one stream - find information, if you can't find it then request it. so just search is on front page, with popular stuff below a la Google Directory -Link to WriteToThem in sidebar of request - according to level of Government -send to appropriate representative? -Start a petition about this request -Share this request on Facebook +in sidebar of request + Link to WriteToThem - according to level of Government of body + Start a petition about this request + Share this request on Facebook Successful requests should have success date as date in search results. @@ -146,6 +142,7 @@ http://www.parliament.uk/parliamentary_publications_and_archives/freedom_of_info Including 'Request for information' in the subject line of your e-mail will assist us in prioritising your request. http://www.parliament.uk/parliamentary_publications_and_archives/freedom_of_information_in_the_house_of_lords/lords__foi___how_to_obtain_information.cfm +Medway also hint at this with subject= on mailto link Consider putting the requesting user's name in the request's magic email address |