aboutsummaryrefslogtreecommitdiffstats
path: root/app/controllers/public_body_controller.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers/public_body_controller.rb')
-rw-r--r--app/controllers/public_body_controller.rb33
1 files changed, 25 insertions, 8 deletions
diff --git a/app/controllers/public_body_controller.rb b/app/controllers/public_body_controller.rb
index 854e79a19..376b2024a 100644
--- a/app/controllers/public_body_controller.rb
+++ b/app/controllers/public_body_controller.rb
@@ -1,4 +1,4 @@
-# -*- coding: utf-8 -*-
+# -*- encoding : utf-8 -*-
# app/controllers/public_body_controller.rb:
# Show information about a public body.
#
@@ -16,22 +16,28 @@ class PublicBodyController < ApplicationController
long_cache
@page = get_search_page_from_params
requests_per_page = 25
+
# Later pages are very expensive to load
if @page > MAX_RESULTS / requests_per_page
raise ActiveRecord::RecordNotFound.new("Sorry. No pages after #{MAX_RESULTS / requests_per_page}.")
end
+
if MySociety::Format.simplify_url_part(params[:url_name], 'body') != params[:url_name]
redirect_to :url_name => MySociety::Format.simplify_url_part(params[:url_name], 'body'), :status => :moved_permanently
return
end
- @locale = self.locale_from_params()
+
+ @locale = locale_from_params
+
I18n.with_locale(@locale) do
@public_body = PublicBody.find_by_url_name_with_historic(params[:url_name])
raise ActiveRecord::RecordNotFound.new("None found") if @public_body.nil?
+
if @public_body.url_name.nil?
redirect_to :back
return
end
+
# If found by historic name, or alternate locale name, redirect to new name
if @public_body.url_name != params[:url_name]
redirect_to :url_name => @public_body.url_name
@@ -40,22 +46,27 @@ class PublicBodyController < ApplicationController
set_last_body(@public_body)
- top_url = frontpage_url
+ @number_of_visible_requests = @public_body.info_requests.visible.count
+
@searched_to_send_request = false
referrer = request.env['HTTP_REFERER']
- if !referrer.nil? && referrer.match(%r{^#{top_url}search/.*/bodies$})
+
+ if !referrer.nil? && referrer.match(%r{^#{frontpage_url}search/.*/bodies$})
@searched_to_send_request = true
end
+
@view = params[:view]
+
query = InfoRequestEvent.make_query_from_params(params.merge(:latest_status => @view))
query += " requested_from:#{@public_body.url_name}"
+
# Use search query for this so can collapse and paginate easily
# TODO: really should just use SQL query here rather than Xapian.
sortby = "described"
begin
@xapian_requests = perform_search([InfoRequestEvent], query, sortby, 'request_collapse', requests_per_page)
if (@page > 1)
- @page_desc = " (page " + @page.to_s + ")"
+ @page_desc = " (page #{ @page })"
else
@page_desc = ""
end
@@ -66,10 +77,16 @@ class PublicBodyController < ApplicationController
flash.keep(:search_params)
@track_thing = TrackThing.create_track_for_public_body(@public_body)
+
if @user
@existing_track = TrackThing.find_existing(@user, @track_thing)
end
- @feed_autodetect = [ { :url => do_track_url(@track_thing, 'feed'), :title => @track_thing.params[:title_in_rss], :has_json => true } ]
+
+ @follower_count = TrackThing.where(:public_body_id => @public_body.id).count
+
+ @feed_autodetect = [ { :url => do_track_url(@track_thing, 'feed'),
+ :title => @track_thing.params[:title_in_rss],
+ :has_json => true } ]
respond_to do |format|
format.html { @has_json = true; render :template => "public_body/show"}
@@ -83,7 +100,7 @@ class PublicBodyController < ApplicationController
@public_body = PublicBody.find_by_url_name_with_historic(params[:url_name])
raise ActiveRecord::RecordNotFound.new("None found") if @public_body.nil?
- I18n.with_locale(self.locale_from_params()) do
+ I18n.with_locale(locale_from_params) do
if params[:submitted_view_email]
if verify_recaptcha
flash.discard(:error)
@@ -106,7 +123,7 @@ class PublicBodyController < ApplicationController
@tag = params[:tag]
- @locale = self.locale_from_params
+ @locale = locale_from_params
underscore_locale = @locale.gsub '-', '_'
underscore_default_locale = I18n.default_locale.to_s.gsub '-', '_'