diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/admin_public_body_controller.rb | 12 | ||||
-rw-r--r-- | app/controllers/general_controller.rb | 15 | ||||
-rw-r--r-- | app/controllers/public_body_controller.rb | 2 | ||||
-rw-r--r-- | app/helpers/link_to_helper.rb | 2 | ||||
-rw-r--r-- | app/models/public_body.rb | 12 | ||||
-rw-r--r-- | app/views/general/exception_caught.rhtml | 5 |
6 files changed, 33 insertions, 15 deletions
diff --git a/app/controllers/admin_public_body_controller.rb b/app/controllers/admin_public_body_controller.rb index 3e0613a1f..98d4c1044 100644 --- a/app/controllers/admin_public_body_controller.rb +++ b/app/controllers/admin_public_body_controller.rb @@ -23,11 +23,13 @@ class AdminPublicBodyController < AdminController if @page == "" @page = nil end - @public_bodies = PublicBody.paginate :order => "name", :page => @page, :per_page => 100, - :conditions => @query.nil? ? nil : ["lower(name) like lower('%'||?||'%') or - lower(short_name) like lower('%'||?||'%') or - lower(request_email) like lower('%'||?||'%')", @query, @query, @query] - @public_bodies_by_tag = PublicBody.find_by_tag(@query) + @public_bodies = PublicBody.paginate :order => "public_body_translations.name", :page => @page, :per_page => 100, + :conditions => @query.nil? ? "public_body_translations.locale = '#{@locale}'" : + ["(lower(public_body_translations.name) like lower('%'||?||'%') or + lower(public_body_translations.short_name) like lower('%'||?||'%') or + lower(public_body_translations.request_email) like lower('%'||?||'%' )) AND (public_body_translations.locale = '#{@locale}')", @query, @query, @query], + :joins => :translations + @public_bodies_by_tag = PublicBody::Translation.find_by_tag(@query) end end diff --git a/app/controllers/general_controller.rb b/app/controllers/general_controller.rb index cf28208a0..bdbcfcdd4 100644 --- a/app/controllers/general_controller.rb +++ b/app/controllers/general_controller.rb @@ -20,9 +20,19 @@ class GeneralController < ApplicationController # New, improved front page! def frontpage - behavior_cache do # This is too slow - @popular_bodies = PublicBody.find(:all, :select => "*, (select count(*) from info_requests where info_requests.public_body_id = public_bodies.id) as c", :order => "c desc", :limit => 32) + @locale = self.locale_from_params() + locale_condition = 'public_body_translations.locale = ?' + conditions = [locale_condition, @locale] + PublicBody.with_locale(@locale) do + @popular_bodies = PublicBody.find(:all, + :select => "public_bodies.*, (select count(*) from info_requests where info_requests.public_body_id = public_bodies.id) as c", + :order => "c desc", + :limit => 32, + :conditions => conditions, + :joins => :translations + ) + end # Get some successful requests # begin query = 'variety:response (status:successful OR status:partially_successful)' @@ -34,7 +44,6 @@ class GeneralController < ApplicationController rescue @successful_request_events = [] end - end end # Display WhatDoTheyKnow category from mySociety blog diff --git a/app/controllers/public_body_controller.rb b/app/controllers/public_body_controller.rb index e790b042f..2d1577600 100644 --- a/app/controllers/public_body_controller.rb +++ b/app/controllers/public_body_controller.rb @@ -20,7 +20,7 @@ class PublicBodyController < ApplicationController PublicBody.with_locale(@locale) do @public_body = PublicBody.find_by_url_name_with_historic(params[:url_name]) raise "None found" if @public_body.nil? # XXX proper 404 - + return redirect_to :back if @public_body.url_name.nil? # If found by historic name, redirect to new name redirect_to show_public_body_url(:url_name => @public_body.url_name) if @public_body.url_name != params[:url_name] diff --git a/app/helpers/link_to_helper.rb b/app/helpers/link_to_helper.rb index 85913b12e..20d4223a2 100644 --- a/app/helpers/link_to_helper.rb +++ b/app/helpers/link_to_helper.rb @@ -162,7 +162,7 @@ module LinkToHelper # Admin pages def admin_url(relative_path) - admin_url_prefix = MySociety::Config.get("ADMIN_BASE_URL", "/admin/") + admin_url_prefix = admin_general_index_path+"/" return admin_url_prefix + relative_path end diff --git a/app/models/public_body.rb b/app/models/public_body.rb index d7c3a3de6..3d2b180b8 100644 --- a/app/models/public_body.rb +++ b/app/models/public_body.rb @@ -48,7 +48,11 @@ class PublicBody < ActiveRecord::Base # like find_by_url_name but also search historic url_name if none found def self.find_by_url_name_with_historic(name) - found = PublicBody.find_all_by_url_name(name) + @localer = I18n.locale.to_s + PublicBody.with_locale(@locale) do + found = PublicBody.find(:all, + :conditions => ["public_body_translations.url_name='#{name}' AND public_body_translations.locale = '#{@localer}'"], + :joins => :translations) return found.first if found.size == 1 # Shouldn't we just make url_name unique? raise "Two bodies with the same URL name: #{name}" if found.size > 1 @@ -64,7 +68,10 @@ class PublicBody < ActiveRecord::Base # does acts_as_versioned provide a method that returns the current version? return PublicBody.find(old.first) end + end + + load "public_body_categories_#{I18n.locale.to_s}.rb" # Set the first letter, which is used for faster queries before_save(:set_first_letter) @@ -272,6 +279,7 @@ class PublicBody < ActiveRecord::Base :request_email => MySociety::Config.get("CONTACT_EMAIL", 'contact@localhost'), :home_page => "", :notes => "", + :publication_scheme => "", :last_edit_editor => "internal_admin", :last_edit_comment => "Made by PublicBody.internal_admin_body" ) @@ -337,7 +345,7 @@ class PublicBody < ActiveRecord::Base else # New public body notes.push "line " + line.to_s + ": new authority '" + name + "' with email " + email - public_body = PublicBody.new(:name => name, :request_email => email, :short_name => "", :home_page => "", :notes => "", :last_edit_editor => editor, :last_edit_comment => 'Created from spreadsheet') + public_body = PublicBody.new(:name => name, :request_email => email, :short_name => "", :home_page => "", :publication_scheme => "", :notes => "", :last_edit_editor => editor, :last_edit_comment => 'Created from spreadsheet') public_body.tag_string = tag public_body.save! end diff --git a/app/views/general/exception_caught.rhtml b/app/views/general/exception_caught.rhtml index 61337494d..ca36b592b 100644 --- a/app/views/general/exception_caught.rhtml +++ b/app/views/general/exception_caught.rhtml @@ -10,9 +10,8 @@ <%= submit_tag _("Search") %> <% end %> </li> -<li><a href="/help/contact">Contact us</a> to tell us about - the problem</li> -<li>Go to our <a href="/">front page</a></li> +<li><%= _('<a href="%s">Contact us</a> to tell us about the problem</li>') % [help_contact_path] %> +<li><%= _('Go to our <a href="%s">front page</a></li>') % ["/"] %> </ul> <p id="error_technical_details"><%= _("<strong>Technical details:</strong>")%> <%=@exception_class ? @exception_class : _("Unknown")%></p> |