aboutsummaryrefslogtreecommitdiffstats
path: root/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rw-r--r--app/models/foi_attachment.rb2
-rw-r--r--app/models/incoming_message.rb8
-rw-r--r--app/models/public_body.rb31
3 files changed, 28 insertions, 13 deletions
diff --git a/app/models/foi_attachment.rb b/app/models/foi_attachment.rb
index 914420a2b..acbfc8a34 100644
--- a/app/models/foi_attachment.rb
+++ b/app/models/foi_attachment.rb
@@ -69,7 +69,7 @@ class FoiAttachment < ActiveRecord::Base
tries = 0
delay = 1
begin
- binary_data = File.open(self.filepath, "rb" ).read
+ binary_data = File.open(self.filepath, "rb" ){ |file| file.read }
if self.content_type =~ /^text/
@cached_body = convert_string_to_utf8_or_binary(binary_data, 'UTF-8')
else
diff --git a/app/models/incoming_message.rb b/app/models/incoming_message.rb
index 8b2aa87e7..bcf0b6ec9 100644
--- a/app/models/incoming_message.rb
+++ b/app/models/incoming_message.rb
@@ -129,15 +129,15 @@ class IncomingMessage < ActiveRecord::Base
if (!force.nil? || self.last_parsed.nil?)
ActiveRecord::Base.transaction do
self.extract_attachments!
- self.sent_at = self.mail.date || self.created_at
- self.subject = self.mail.subject
- self.mail_from = MailHandler.get_from_name(self.mail)
+ write_attribute(:sent_at, self.mail.date || self.created_at)
+ write_attribute(:subject, self.mail.subject)
+ write_attribute(:mail_from, MailHandler.get_from_name(self.mail))
if self.from_email
self.mail_from_domain = PublicBody.extract_domain_from_email(self.from_email)
else
self.mail_from_domain = ""
end
- self.valid_to_reply_to = self._calculate_valid_to_reply_to
+ write_attribute(:valid_to_reply_to, self._calculate_valid_to_reply_to)
self.last_parsed = Time.now
self.foi_attachments reload=true
self.save!
diff --git a/app/models/public_body.rb b/app/models/public_body.rb
index d2cfc4b8b..933825d2a 100644
--- a/app/models/public_body.rb
+++ b/app/models/public_body.rb
@@ -199,7 +199,6 @@ class PublicBody < ActiveRecord::Base
self.non_versioned_columns << 'info_requests_overdue_count'
class Version
- attr_accessor :created_at
def last_edit_comment_for_html_display
text = self.last_edit_comment.strip
@@ -261,13 +260,13 @@ class PublicBody < ActiveRecord::Base
# When name or short name is changed, also change the url name
def short_name=(short_name)
- globalize.write(I18n.locale, :short_name, short_name)
+ globalize.write(Globalize.locale, :short_name, short_name)
self[:short_name] = short_name
self.update_url_name
end
def name=(name)
- globalize.write(I18n.locale, :name, name)
+ globalize.write(Globalize.locale, :name, name)
self[:name] = name
self.update_url_name
end
@@ -370,10 +369,24 @@ class PublicBody < ActiveRecord::Base
class ImportCSVDryRun < StandardError
end
- # Import from CSV. Just tests things and returns messages if dry_run is true.
- # Returns an array of [array of errors, array of notes]. If there are errors,
- # always rolls back (as with dry_run).
+ # Import from a string in CSV format.
+ # Just tests things and returns messages if dry_run is true.
+ # Returns an array of [array of errors, array of notes]. If there
+ # are errors, always rolls back (as with dry_run).
def self.import_csv(csv, tag, tag_behaviour, dry_run, editor, available_locales = [])
+ tmp_csv = nil
+ Tempfile.open('alaveteli') do |f|
+ f.write csv
+ tmp_csv = f
+ end
+ PublicBody.import_csv_from_file(tmp_csv.path, tag, tag_behaviour, dry_run, editor, available_locales)
+ end
+
+ # Import from a CSV file.
+ # Just tests things and returns messages if dry_run is true.
+ # Returns an array of [array of errors, array of notes]. If there
+ # are errors, always rolls back (as with dry_run).
+ def self.import_csv_from_file(csv_filename, tag, tag_behaviour, dry_run, editor, available_locales = [])
errors = []
notes = []
available_locales = [I18n.default_locale] if available_locales.empty?
@@ -399,7 +412,8 @@ class PublicBody < ActiveRecord::Base
set_of_importing = Set.new()
field_names = { 'name'=>1, 'request_email'=>2 } # Default values in case no field list is given
line = 0
- CSV.parse(csv) do |row|
+
+ CSV.foreach(csv_filename) do |row|
line = line + 1
# Parse the first line as a field list if it starts with '#'
@@ -728,7 +742,8 @@ class PublicBody < ActiveRecord::Base
# either from config, or based on a (slow!) query if not set
body_short_names = AlaveteliConfiguration::frontpage_publicbody_examples.split(/\s*;\s*/)
locale_condition = 'public_body_translations.locale = ?'
- conditions = [locale_condition, locale]
+ underscore_locale = locale.gsub '-', '_'
+ conditions = [locale_condition, underscore_locale]
bodies = []
I18n.with_locale(locale) do
if body_short_names.empty?