diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/info_request.rb | 7 | ||||
-rw-r--r-- | app/models/info_request_event.rb | 55 | ||||
-rw-r--r-- | app/models/public_body.rb | 60 | ||||
-rw-r--r-- | app/models/request_mailer.rb | 10 |
4 files changed, 66 insertions, 66 deletions
diff --git a/app/models/info_request.rb b/app/models/info_request.rb index c667e1499..67ebd01b0 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -779,8 +779,7 @@ public # Display version of status - def display_status - status = self.calculate_status + def InfoRequest.get_status_description(status) if status == 'waiting_classification' _("Awaiting classification.") elsif status == 'waiting_response' @@ -818,6 +817,10 @@ public end end + def display_status + InfoRequest.get_status_description(self.calculate_status) + end + # Completely delete this request and all objects depending on it def fully_destroy self.track_things.each do |track_thing| diff --git a/app/models/info_request_event.rb b/app/models/info_request_event.rb index d79647c98..5ae1f5b2d 100644 --- a/app/models/info_request_event.rb +++ b/app/models/info_request_event.rb @@ -57,22 +57,7 @@ class InfoRequestEvent < ActiveRecord::Base ] # user described state (also update in info_request) - validates_inclusion_of :described_state, :in => [ - nil, - 'waiting_response', - 'waiting_clarification', - 'gone_postal', - 'deadline_extended', - 'wrong_response', - 'not_held', - 'rejected', - 'successful', - 'partially_successful', - 'internal_review', - 'error_message', - 'requires_admin', - 'user_withdrawn' - ] + validate :must_be_valid_state # whether event is publicly visible validates_inclusion_of :prominence, :in => [ @@ -81,6 +66,12 @@ class InfoRequestEvent < ActiveRecord::Base 'requester_only' ] + def must_be_valid_state + if !described_state.nil? and !InfoRequest.enumerate_states.include?(described_state) + errors.add(described_state, "is not a valid state") + end + end + def user_can_view?(user) if !self.info_request.user_can_view?(user) raise "internal error, called user_can_view? on event when there is not permission to view entire request" @@ -288,37 +279,7 @@ class InfoRequestEvent < ActiveRecord::Base def display_status if is_incoming_message? status = self.calculated_state - if !status.nil? - if status == 'waiting_response' - return _("Acknowledgement") - elsif status == 'waiting_clarification' - return _("Clarification required") - elsif status == 'gone_postal' - return _("Handled by post") - elsif status == 'deadline_extended' - return _("Deadline Extended") - elsif status == 'wrong_response' - return _("Wrong Response") - elsif status == 'not_held' - return _("Information not held") - elsif status == 'rejected' - return _("Refused") - elsif status == 'partially_successful' - return _("Some information sent") - elsif status == 'successful' - return _("All information sent") - elsif status == 'internal_review' - return _("Internal review acknowledgement") - elsif status == 'user_withdrawn' - return _("Withdrawn by requester") - elsif status == 'error_message' - return _("Delivery error") - elsif status == 'requires_admin' - return _("Unusual response") - end - raise "unknown status " + status - end - return "Response" + return status.nil? ? _("Response") : InfoRequest.get_status_description(status) end if is_outgoing_message? diff --git a/app/models/public_body.rb b/app/models/public_body.rb index b75da4331..b4d1b6704 100644 --- a/app/models/public_body.rb +++ b/app/models/public_body.rb @@ -38,7 +38,7 @@ class PublicBody < ActiveRecord::Base validates_uniqueness_of :short_name, :message => N_("Short name is already taken"), :if => Proc.new { |pb| pb.short_name != "" } validates_uniqueness_of :name, :message => N_("Name is already taken") - + has_many :info_requests, :order => 'created_at desc' has_many :track_things, :order => 'created_at desc' @@ -46,6 +46,40 @@ class PublicBody < ActiveRecord::Base translates :name, :short_name, :request_email, :url_name, :notes, :first_letter, :publication_scheme + # Convenience methods for creating/editing translations via forms + def translation(locale) + self.translations.find_by_locale(locale) + end + + # XXX - Don't like repeating this! + def calculate_cached_fields(t) + t.first_letter = t.name.scan(/^./mu)[0].upcase unless t.name.nil? or t.name.empty? + short_long_name = t.name + short_long_name = t.short_name if t.short_name and !t.short_name.empty? + t.url_name = MySociety::Format.simplify_url_part(short_long_name, 'body') + end + + def translated_versions + translations + end + + def translated_versions=(translation_attrs) + if translation_attrs.respond_to? :each_value # Hash => updating + translation_attrs.each_value do |attrs| + t = translation(attrs[:locale]) || PublicBody::Translation.new + t.attributes = attrs + calculate_cached_fields(t) + t.save! + end + else # Array => creating + translation_attrs.each do |attrs| + new_translation = PublicBody::Translation.new(attrs) + calculate_cached_fields(new_translation) + translations << new_translation + end + end + end + # Make sure publication_scheme gets the correct default value. # (This would work automatically, were publication_scheme not a translated attribute) def after_initialize @@ -191,7 +225,6 @@ class PublicBody < ActiveRecord::Base # When name or short name is changed, also change the url name def short_name=(short_name) - globalize.write(self.class.locale || I18n.locale, :short_name, short_name) self[:short_name] = short_name self.update_url_name @@ -204,15 +237,15 @@ class PublicBody < ActiveRecord::Base end def update_url_name - url_name = MySociety::Format.simplify_url_part(self.short_or_long_name, 'body') - self.url_name = url_name + self.url_name = MySociety::Format.simplify_url_part(self.short_or_long_name, 'body') end + # Return the short name if present, or else long name def short_or_long_name - if self.short_name.nil? # can happen during construction + if self.short_name.nil? || self.short_name.empty? # 'nil' can happen during construction self.name else - self.short_name.empty? ? self.name : self.short_name + self.short_name end end @@ -341,9 +374,12 @@ class PublicBody < ActiveRecord::Base row.each_with_index {|field, i| field_names[field] = i} next end + + fields = {} + field_names.each{|name, i| fields[name] = row[i]} - name = row[field_names['name']] - email = row[field_names['email']] + name = fields['name'] + email = fields['email'] next if name.nil? if email.nil? email = '' # unknown/bad contact is empty string @@ -356,7 +392,7 @@ class PublicBody < ActiveRecord::Base errors.push "error: line " + line.to_s + ": invalid email " + email + " for authority '" + name + "'" next end - + if bodies_by_name[name] # Already have the public body, just update email public_body = bodies_by_name[name] @@ -367,9 +403,9 @@ class PublicBody < ActiveRecord::Base public_body.last_edit_comment = 'Updated from spreadsheet' public_body.save! end - + additional_locales.each do |locale| - localized_name = field_names["name.#{locale}"] && row[field_names["name.#{locale}"]] + localized_name = fields["name.#{locale}"] PublicBody.with_locale(locale) do if !localized_name.nil? and public_body.name != localized_name notes.push "line " + line.to_s + ": updating name for '#{name}' from '#{public_body.name}' to '#{localized_name}' (locale: #{locale})." @@ -386,7 +422,7 @@ class PublicBody < ActiveRecord::Base public_body.save! additional_locales.each do |locale| - localized_name = field_names["name.#{locale}"] && row[field_names["name.#{locale}"]] + localized_name = fields["name.#{locale}"] if !localized_name.nil? PublicBody.with_locale(locale) do notes.push "line " + line.to_s + ": (aka '#{localized_name}' in locale #{locale})" diff --git a/app/models/request_mailer.rb b/app/models/request_mailer.rb index fc317d20d..e244aaac9 100644 --- a/app/models/request_mailer.rb +++ b/app/models/request_mailer.rb @@ -266,12 +266,12 @@ class RequestMailer < ApplicationMailer end end - # Send email alerts for new responses which haven't been classified. Goes - # out 3 days after last update of event, then after 7, then after 24. + # Send email alerts for new responses which haven't been classified. By default, + # it goes out 3 days after last update of event, then after 10, then after 24. def self.alert_new_response_reminders - self.alert_new_response_reminders_internal(3, 'new_response_reminder_1') - self.alert_new_response_reminders_internal(10, 'new_response_reminder_2') - self.alert_new_response_reminders_internal(24, 'new_response_reminder_3') + MySociety::Config.get("NEW_RESPONSE_REMINDER_AFTER_DAYS", [3, 10, 24]).each_with_index do |days, i| + self.alert_new_response_reminders_internal(days, "new_response_reminder_#{i+1}") + end end def self.alert_new_response_reminders_internal(days_since, type_code) info_requests = InfoRequest.find_old_unclassified(:order => 'info_requests.id', |