From 0d533ce1d56e1ec1446774cc6fff52451a844f3f Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Sun, 9 Dec 2012 18:35:39 +1100 Subject: Switch to new method name --- app/controllers/general_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/controllers/general_controller.rb') diff --git a/app/controllers/general_controller.rb b/app/controllers/general_controller.rb index 3ba636e29..dc6fc5de5 100644 --- a/app/controllers/general_controller.rb +++ b/app/controllers/general_controller.rb @@ -26,7 +26,7 @@ class GeneralController < ApplicationController @locale = self.locale_from_params() locale_condition = 'public_body_translations.locale = ?' conditions = [locale_condition, @locale] - PublicBody.with_locale(@locale) do + PublicBody.with_locales(@locale) do if body_short_names.empty? # This is too slow @popular_bodies = PublicBody.visible.find(:all, -- cgit v1.2.3 From 64a93911ebae4eaa2a1bc2b9e09d1468d77aadb9 Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Sun, 9 Dec 2012 19:08:59 +1100 Subject: Remove interlock as it's not compatible with Rails 3 and is unmaintained --- app/controllers/general_controller.rb | 88 +++++++++++++++++------------------ 1 file changed, 43 insertions(+), 45 deletions(-) (limited to 'app/controllers/general_controller.rb') diff --git a/app/controllers/general_controller.rb b/app/controllers/general_controller.rb index dc6fc5de5..8cf4ba6b7 100644 --- a/app/controllers/general_controller.rb +++ b/app/controllers/general_controller.rb @@ -19,53 +19,51 @@ class GeneralController < ApplicationController # New, improved front page! def frontpage medium_cache - behavior_cache :tag => [session[:user_id], request.url] do - # get some example searches and public bodies to display - # either from config, or based on a (slow!) query if not set - body_short_names = Configuration::frontpage_publicbody_examples.split(/\s*;\s*/).map{|s| "'%s'" % s.gsub(/'/, "''") }.join(", ") - @locale = self.locale_from_params() - locale_condition = 'public_body_translations.locale = ?' - conditions = [locale_condition, @locale] - PublicBody.with_locales(@locale) do - if body_short_names.empty? - # This is too slow - @popular_bodies = PublicBody.visible.find(:all, - :order => "info_requests_count desc", - :limit => 32, - :conditions => conditions, - :joins => :translations - ) - else - conditions[0] += " and public_bodies.url_name in (" + body_short_names + ")" - @popular_bodies = PublicBody.find(:all, - :conditions => conditions, - :joins => :translations) - end + # get some example searches and public bodies to display + # either from config, or based on a (slow!) query if not set + body_short_names = Configuration::frontpage_publicbody_examples.split(/\s*;\s*/).map{|s| "'%s'" % s.gsub(/'/, "''") }.join(", ") + @locale = self.locale_from_params() + locale_condition = 'public_body_translations.locale = ?' + conditions = [locale_condition, @locale] + PublicBody.with_locales(@locale) do + if body_short_names.empty? + # This is too slow + @popular_bodies = PublicBody.visible.find(:all, + :order => "info_requests_count desc", + :limit => 32, + :conditions => conditions, + :joins => :translations + ) + else + conditions[0] += " and public_bodies.url_name in (" + body_short_names + ")" + @popular_bodies = PublicBody.find(:all, + :conditions => conditions, + :joins => :translations) end - # Get some successful requests - begin - query = 'variety:response (status:successful OR status:partially_successful)' - sortby = "newest" - max_count = 5 - xapian_object = perform_search([InfoRequestEvent], query, sortby, 'request_title_collapse', max_count) - @request_events = xapian_object.results.map { |r| r[:model] } - - # If there are not yet enough successful requests, fill out the list with - # other requests - if @request_events.count < max_count - @request_events_all_successful = false - query = 'variety:sent' - xapian_object = perform_search([InfoRequestEvent], query, sortby, 'request_title_collapse', max_count-@request_events.count) - more_events = xapian_object.results.map { |r| r[:model] } - @request_events += more_events - # Overall we still want the list sorted with the newest first - @request_events.sort!{|e1,e2| e2.created_at <=> e1.created_at} - else - @request_events_all_successful = true - end - rescue - @request_events = [] + end + # Get some successful requests + begin + query = 'variety:response (status:successful OR status:partially_successful)' + sortby = "newest" + max_count = 5 + xapian_object = perform_search([InfoRequestEvent], query, sortby, 'request_title_collapse', max_count) + @request_events = xapian_object.results.map { |r| r[:model] } + + # If there are not yet enough successful requests, fill out the list with + # other requests + if @request_events.count < max_count + @request_events_all_successful = false + query = 'variety:sent' + xapian_object = perform_search([InfoRequestEvent], query, sortby, 'request_title_collapse', max_count-@request_events.count) + more_events = xapian_object.results.map { |r| r[:model] } + @request_events += more_events + # Overall we still want the list sorted with the newest first + @request_events.sort!{|e1,e2| e2.created_at <=> e1.created_at} + else + @request_events_all_successful = true end + rescue + @request_events = [] end end -- cgit v1.2.3 From 1f8bc6560b5240a7aa84ac8d6bdc47eea5d2d781 Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Mon, 10 Dec 2012 00:09:55 +1100 Subject: The with_locale has been removed in Globalize3 I think Globalize is supposed to pick up the locale from I18n anyway so I don't know if these are needed. I think I still haven't done the right thing but it's time to move on. --- app/controllers/general_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/controllers/general_controller.rb') diff --git a/app/controllers/general_controller.rb b/app/controllers/general_controller.rb index 8cf4ba6b7..faf34aa04 100644 --- a/app/controllers/general_controller.rb +++ b/app/controllers/general_controller.rb @@ -25,7 +25,7 @@ class GeneralController < ApplicationController @locale = self.locale_from_params() locale_condition = 'public_body_translations.locale = ?' conditions = [locale_condition, @locale] - PublicBody.with_locales(@locale) do + I18n.with_locale(@locale) do if body_short_names.empty? # This is too slow @popular_bodies = PublicBody.visible.find(:all, -- cgit v1.2.3 From 5f6a7a29bc1ea3784728a9c57edfa4be73d4196f Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Thu, 17 Jan 2013 05:26:54 +1100 Subject: Set locale with I18n rather than through globalize --- app/controllers/general_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/controllers/general_controller.rb') diff --git a/app/controllers/general_controller.rb b/app/controllers/general_controller.rb index 3ba636e29..e9d51a59d 100644 --- a/app/controllers/general_controller.rb +++ b/app/controllers/general_controller.rb @@ -26,7 +26,7 @@ class GeneralController < ApplicationController @locale = self.locale_from_params() locale_condition = 'public_body_translations.locale = ?' conditions = [locale_condition, @locale] - PublicBody.with_locale(@locale) do + I18n.with_locale(@locale) do if body_short_names.empty? # This is too slow @popular_bodies = PublicBody.visible.find(:all, -- cgit v1.2.3 From d5327fc2fe691ee2bc427dc5f25af47508044be0 Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Thu, 31 Jan 2013 11:36:04 +1100 Subject: Change that should have been merged in from develop when one form of caching was removed --- app/controllers/general_controller.rb | 42 +++++++++++++++++------------------ 1 file changed, 20 insertions(+), 22 deletions(-) (limited to 'app/controllers/general_controller.rb') diff --git a/app/controllers/general_controller.rb b/app/controllers/general_controller.rb index 003b815d3..faf34aa04 100644 --- a/app/controllers/general_controller.rb +++ b/app/controllers/general_controller.rb @@ -19,28 +19,26 @@ class GeneralController < ApplicationController # New, improved front page! def frontpage medium_cache - behavior_cache :tag => [session[:user_id], request.url] do - # get some example searches and public bodies to display - # either from config, or based on a (slow!) query if not set - body_short_names = Configuration::frontpage_publicbody_examples.split(/\s*;\s*/).map{|s| "'%s'" % s.gsub(/'/, "''") }.join(", ") - @locale = self.locale_from_params() - locale_condition = 'public_body_translations.locale = ?' - conditions = [locale_condition, @locale] - I18n.with_locale(@locale) do - if body_short_names.empty? - # This is too slow - @popular_bodies = PublicBody.visible.find(:all, - :order => "info_requests_count desc", - :limit => 32, - :conditions => conditions, - :joins => :translations - ) - else - conditions[0] += " and public_bodies.url_name in (" + body_short_names + ")" - @popular_bodies = PublicBody.find(:all, - :conditions => conditions, - :joins => :translations) - end + # get some example searches and public bodies to display + # either from config, or based on a (slow!) query if not set + body_short_names = Configuration::frontpage_publicbody_examples.split(/\s*;\s*/).map{|s| "'%s'" % s.gsub(/'/, "''") }.join(", ") + @locale = self.locale_from_params() + locale_condition = 'public_body_translations.locale = ?' + conditions = [locale_condition, @locale] + I18n.with_locale(@locale) do + if body_short_names.empty? + # This is too slow + @popular_bodies = PublicBody.visible.find(:all, + :order => "info_requests_count desc", + :limit => 32, + :conditions => conditions, + :joins => :translations + ) + else + conditions[0] += " and public_bodies.url_name in (" + body_short_names + ")" + @popular_bodies = PublicBody.find(:all, + :conditions => conditions, + :joins => :translations) end end # Get some successful requests -- cgit v1.2.3 From 13495a891581ac1864edaf226126e76e257d78d9 Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Thu, 31 Jan 2013 14:01:57 +1100 Subject: Globbing in routes is slightly different in Rails 3 --- app/controllers/general_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/controllers/general_controller.rb') diff --git a/app/controllers/general_controller.rb b/app/controllers/general_controller.rb index faf34aa04..34870bd42 100644 --- a/app/controllers/general_controller.rb +++ b/app/controllers/general_controller.rb @@ -109,7 +109,7 @@ class GeneralController < ApplicationController def search # XXX Why is this so complicated with arrays and stuff? Look at the route # in config/routes.rb for comments. - combined = params[:combined] + combined = params[:combined].split("/") @sortby = nil @bodies = @requests = @users = true if combined.size > 0 && (['advanced'].include?(combined[-1])) -- cgit v1.2.3 From 2c00d9b1a4bf42bba92def1ee8e0f750db9b4905 Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Fri, 1 Feb 2013 14:52:34 +1100 Subject: Handling of globbed parameters in routes has changed --- app/controllers/general_controller.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'app/controllers/general_controller.rb') diff --git a/app/controllers/general_controller.rb b/app/controllers/general_controller.rb index 34870bd42..ecf865543 100644 --- a/app/controllers/general_controller.rb +++ b/app/controllers/general_controller.rb @@ -110,6 +110,7 @@ class GeneralController < ApplicationController # XXX Why is this so complicated with arrays and stuff? Look at the route # in config/routes.rb for comments. combined = params[:combined].split("/") + p params[:combined] @sortby = nil @bodies = @requests = @users = true if combined.size > 0 && (['advanced'].include?(combined[-1])) -- cgit v1.2.3 From cbdff06aa95a7987b54c712dc6729e138f608eca Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Sun, 3 Mar 2013 14:52:30 +1100 Subject: Rename Configuration class to avoid conflict with ActiveSupport::Configurable --- app/controllers/general_controller.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'app/controllers/general_controller.rb') diff --git a/app/controllers/general_controller.rb b/app/controllers/general_controller.rb index 34870bd42..e52be7cf8 100644 --- a/app/controllers/general_controller.rb +++ b/app/controllers/general_controller.rb @@ -21,7 +21,7 @@ class GeneralController < ApplicationController medium_cache # get some example searches and public bodies to display # either from config, or based on a (slow!) query if not set - body_short_names = Configuration::frontpage_publicbody_examples.split(/\s*;\s*/).map{|s| "'%s'" % s.gsub(/'/, "''") }.join(", ") + body_short_names = AlaveteliConfiguration::frontpage_publicbody_examples.split(/\s*;\s*/).map{|s| "'%s'" % s.gsub(/'/, "''") }.join(", ") @locale = self.locale_from_params() locale_condition = 'public_body_translations.locale = ?' conditions = [locale_condition, @locale] @@ -71,7 +71,7 @@ class GeneralController < ApplicationController def blog medium_cache @feed_autodetect = [] - @feed_url = Configuration::blog_feed + @feed_url = AlaveteliConfiguration::blog_feed separator = @feed_url.include?('?') ? '&' : '?' @feed_url = "#{@feed_url}#{separator}lang=#{self.locale_from_params()}" @blog_items = [] @@ -84,7 +84,7 @@ class GeneralController < ApplicationController @feed_autodetect = [{:url => @feed_url, :title => "#{site_name} blog"}] end end - @twitter_user = Configuration::twitter_username + @twitter_user = AlaveteliConfiguration::twitter_username end # Just does a redirect from ?query= search to /query -- cgit v1.2.3 From 44ec166b8691743e0ffbcc108eaf41ab0d2ef3cd Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Tue, 26 Mar 2013 09:47:06 +1100 Subject: Change email address in header of source code to hello@mysociety.org --- app/controllers/general_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/controllers/general_controller.rb') diff --git a/app/controllers/general_controller.rb b/app/controllers/general_controller.rb index 6f79c50cb..075d35ba0 100644 --- a/app/controllers/general_controller.rb +++ b/app/controllers/general_controller.rb @@ -3,7 +3,7 @@ # particular model. # # Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved. -# Email: francis@mysociety.org; WWW: http://www.mysociety.org/ +# Email: hello@mysociety.org; WWW: http://www.mysociety.org/ begin require 'xmlsimple' -- cgit v1.2.3 From a8f925a87075c8cc36d3ed29f7f64f51bc820b1e Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Tue, 30 Apr 2013 16:09:10 +0100 Subject: Remove debian-specific require clause and use Gemfile to specify non-standard require - bundler should be supplying the gem now. --- app/controllers/general_controller.rb | 7 ------- 1 file changed, 7 deletions(-) (limited to 'app/controllers/general_controller.rb') diff --git a/app/controllers/general_controller.rb b/app/controllers/general_controller.rb index 075d35ba0..0df685829 100644 --- a/app/controllers/general_controller.rb +++ b/app/controllers/general_controller.rb @@ -5,13 +5,6 @@ # Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved. # Email: hello@mysociety.org; WWW: http://www.mysociety.org/ -begin - require 'xmlsimple' -rescue LoadError - # Debian maintainers put their xmlsimple in a different location :( - require 'lib/xmlsimple' -end - require 'open-uri' class GeneralController < ApplicationController -- cgit v1.2.3 From 106bbf1976406b9bb212944131758d797f516682 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Thu, 2 May 2013 10:29:39 +0100 Subject: Handle routing errors with our custom template too. --- app/controllers/general_controller.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'app/controllers/general_controller.rb') diff --git a/app/controllers/general_controller.rb b/app/controllers/general_controller.rb index 0df685829..9d0f91dda 100644 --- a/app/controllers/general_controller.rb +++ b/app/controllers/general_controller.rb @@ -222,5 +222,11 @@ class GeneralController < ApplicationController @locale = self.locale_from_params() render(:layout => false, :content_type => 'text/css') end + + # Handle requests for non-existent URLs - will be handled by ApplicationController::render_exception + def not_found + raise RouteNotFound + end + end -- cgit v1.2.3