diff options
author | Seb Bacon <seb.bacon@gmail.com> | 2011-06-14 11:51:41 +0100 |
---|---|---|
committer | Seb Bacon <seb.bacon@gmail.com> | 2011-06-14 11:51:41 +0100 |
commit | 2ee3d07d49a28d7560329ba2c71e411b1f3afe74 (patch) | |
tree | a1a1c3d7df6b178b9eb904a0a8031f312f270eed | |
parent | c78e3b2aba67ad9844175e1e27016692759f498a (diff) |
allow search and publicbody examples to be provided in config file, falling back to a vaguely sensible default based on existing data if not present. Note that the fallback is a slow query on a large database!
-rw-r--r-- | app/controllers/general_controller.rb | 16 | ||||
-rw-r--r-- | app/views/general/frontpage.rhtml | 4 | ||||
-rw-r--r-- | config/general-example | 9 |
3 files changed, 25 insertions, 4 deletions
diff --git a/app/controllers/general_controller.rb b/app/controllers/general_controller.rb index cf28208a0..47962d60a 100644 --- a/app/controllers/general_controller.rb +++ b/app/controllers/general_controller.rb @@ -21,8 +21,22 @@ class GeneralController < ApplicationController # New, improved front page! def frontpage behavior_cache 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 = MySociety::Config.get('FRONTPAGE_PUBLICBODY_EXAMPLES', '').split(/\s*;\s*/).map{|s| "'%s'" % s.gsub(/'/, "''") }.join(", ") + if body_short_names.empty? # 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) + @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) + else + @popular_bodies = PublicBody.find(:all, :conditions => ["url_name in (" + body_short_names + ")"]) + end + @search_examples = MySociety::Config.get('FRONTPAGE_SEARCH_EXAMPLES', '').split(/\s*;\s*/) + if @search_examples.empty? + @search_examples = @popular_bodies.map { |body| body.name } + end + + # Get some successful requests # begin query = 'variety:response (status:successful OR status:partially_successful)' diff --git a/app/views/general/frontpage.rhtml b/app/views/general/frontpage.rhtml index 276ac70a7..f412a6964 100644 --- a/app/views/general/frontpage.rhtml +++ b/app/views/general/frontpage.rhtml @@ -16,8 +16,8 @@ <%= submit_tag _('Search') %> <br> <%= _('e.g.') %> - <% @popular_bodies.each_with_index do |body, i| %> - <%=link_to body.name, search_url(body.name, 'bodies')%><% if i < 2 %>, <% else %>. <% break %><% end %> + <% @search_examples.each_with_index do |name, i| %> + <%=link_to name, search_url(name, 'bodies')%><% if i < 2 %>, <% else %>. <% break %><% end %> <% end %> <br> diff --git a/config/general-example b/config/general-example index df27596ea..82489c333 100644 --- a/config/general-example +++ b/config/general-example @@ -55,5 +55,12 @@ define('OPTION_RECAPTCHA_PUBLIC_KEY', 'x'); define('OPTION_RECAPTCHA_PRIVATE_KEY', 'x'); // Locales we wish to support in this app -define('OPTION_AVAILABLE_LOCALES', 'en es') +define('OPTION_AVAILABLE_LOCALES', 'en es'); + +// example searches for the home page, semicolon delimited +define('OPTION_FRONTPAGE_SEARCH_EXAMPLES', 'Geraldine Quango; Department for Humpadinking'); + +// example public bodies for the home page, semicolon delimited - short_names +define('OPTION_FRONTPAGE_PUBLICBODY_EXAMPLES', 'tgq'); + ?> |