diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/info_request.rb | 1 | ||||
-rw-r--r-- | app/models/public_body.rb | 82 |
2 files changed, 45 insertions, 38 deletions
diff --git a/app/models/info_request.rb b/app/models/info_request.rb index 8d455e488..814057ef4 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -748,7 +748,6 @@ public # This is a long stop - even with UK public interest test extensions, 40 # days is a very long time. def date_very_overdue_after - last_sent = last_event_forming_initial_request if self.public_body.is_school? # schools have 60 working days maximum (even over a long holiday) Holiday.due_date_from(self.date_initial_request_last_sent_at, AlaveteliConfiguration::special_reply_very_late_after_days, AlaveteliConfiguration::working_or_calendar_days) diff --git a/app/models/public_body.rb b/app/models/public_body.rb index 6c2e0d04b..c023b436c 100644 --- a/app/models/public_body.rb +++ b/app/models/public_body.rb @@ -64,6 +64,7 @@ class PublicBody < ActiveRecord::Base } translates :name, :short_name, :request_email, :url_name, :notes, :first_letter, :publication_scheme + accepts_nested_attributes_for :translations # Default fields available for importing from CSV, in the format # [field_name, 'short description of field (basic html allowed)'] @@ -151,12 +152,11 @@ class PublicBody < ActiveRecord::Base translations end - def translated_versions=(translation_attrs) + def translations_attributes=(translation_attrs) def empty_translation?(attrs) - attrs_with_values = attrs.select{ |key, value| value != '' and key != 'locale' } + attrs_with_values = attrs.select{ |key, value| value != '' and key.to_s != 'locale' } attrs_with_values.empty? end - if translation_attrs.respond_to? :each_value # Hash => updating translation_attrs.each_value do |attrs| next if empty_translation?(attrs) @@ -166,6 +166,13 @@ class PublicBody < ActiveRecord::Base t.save! end else # Array => creating + warn "[DEPRECATION] PublicBody#translations_attributes= " \ + "will no longer accept an Array as of release 0.22. " \ + "Use Hash arguments instead. See " \ + "spec/models/public_body_spec.rb and " \ + "app/views/admin_public_body/_form.html.erb for more " \ + "details." + translation_attrs.each do |attrs| next if empty_translation?(attrs) new_translation = PublicBody::Translation.new(attrs) @@ -175,6 +182,12 @@ class PublicBody < ActiveRecord::Base end end + def translated_versions=(translation_attrs) + warn "[DEPRECATION] PublicBody#translated_versions= will be replaced " \ + "by PublicBody#translations_attributes= as of release 0.22" + self.translations_attributes = translation_attrs + end + 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) @@ -222,39 +235,38 @@ class PublicBody < ActiveRecord::Base return self.has_tag?('defunct') end - # Can an FOI (etc.) request be made to this body, and if not why not? + # Can an FOI (etc.) request be made to this body? def is_requestable? - if self.defunct? - return false - end - if self.not_apply? - return false - end - if self.request_email.nil? - return false - end - return !self.request_email.empty? && self.request_email != 'blank' + has_request_email? && !defunct? && !not_apply? end + # Strict superset of is_requestable? def is_followupable? - if self.request_email.nil? - return false - end - return !self.request_email.empty? && self.request_email != 'blank' + has_request_email? + end + + def has_request_email? + !request_email.blank? && request_email != 'blank' end + # Also used as not_followable_reason def not_requestable_reason if self.defunct? return 'defunct' elsif self.not_apply? return 'not_apply' - elsif self.request_email.nil? or self.request_email.empty? or self.request_email == 'blank' + elsif !has_request_email? return 'bad_contact' else - raise "requestable_failure_reason called with type that has no reason" + raise "not_requestable_reason called with type that has no reason" end end + def special_not_requestable_reason? + self.defunct? || self.not_apply? + end + + class Version def last_edit_comment_for_html_display @@ -336,33 +348,29 @@ class PublicBody < ActiveRecord::Base # Use tags to describe what type of thing this is def type_of_authority(html = false) - types = [] - first = true - for tag in self.tags + types = tags.each_with_index.map do |tag, index| if PublicBodyCategory.get().by_tag().include?(tag.name) desc = PublicBodyCategory.get().singular_by_tag()[tag.name] - if first - # terrible that Ruby/Rails doesn't have an equivalent of ucfirst - # (capitalize shockingly converts later characters to lowercase) - desc = desc[0,1].capitalize + desc[1,desc.size] - first = false + + if index.zero? + desc = desc.sub(/\S/) { |m| Unicode.upcase(m) } end + if html # TODO: this should call proper route helpers, but is in model sigh desc = '<a href="/body/list/' + tag.name + '">' + desc + '</a>' end - types.push(desc) + + desc end end - if types.size > 0 - ret = types[0, types.size - 1].join(", ") - if types.size > 1 - ret = ret + " and " - end - ret = ret + types[-1] - return ret.html_safe + + types.compact! + + if types.any? + types.to_sentence(:last_word_connector => ' and ').html_safe else - return _("A public authority") + _("A public authority") end end |