diff options
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/admin_public_body_categories_controller.rb | 44 | ||||
-rw-r--r-- | app/controllers/admin_public_body_controller.rb | 12 | ||||
-rw-r--r-- | app/controllers/admin_public_body_headings_controller.rb | 63 | ||||
-rw-r--r-- | app/controllers/general_controller.rb | 5 | ||||
-rw-r--r-- | app/controllers/public_body_controller.rb | 10 |
5 files changed, 77 insertions, 57 deletions
diff --git a/app/controllers/admin_public_body_categories_controller.rb b/app/controllers/admin_public_body_categories_controller.rb index 5e305dde3..a86171c76 100644 --- a/app/controllers/admin_public_body_categories_controller.rb +++ b/app/controllers/admin_public_body_categories_controller.rb @@ -7,17 +7,39 @@ class AdminPublicBodyCategoriesController < AdminController def new @category = PublicBodyCategory.new - render :formats => [:html] + @category.build_all_translations + end + + def create + I18n.with_locale(I18n.default_locale) do + @category = PublicBodyCategory.new(params[:public_body_category]) + if @category.save + # FIXME: This can't handle failure (e.g. if a PublicBodyHeading + # doesn't exist) + if params[:headings] + params[:headings].values.each do |heading_id| + PublicBodyHeading.find(heading_id).add_category(@category) + end + end + flash[:notice] = 'Category was successfully created.' + redirect_to admin_categories_path + else + @category.build_all_translations + render :action => 'new' + end + end end def edit @category = PublicBodyCategory.find(params[:id]) + @category.build_all_translations @tagged_public_bodies = PublicBody.find_by_tag(@category.category_tag) end def update @category = PublicBodyCategory.find(params[:id]) @tagged_public_bodies = PublicBody.find_by_tag(@category.category_tag) + heading_ids = [] I18n.with_locale(I18n.default_locale) do @@ -43,6 +65,8 @@ class AdminPublicBodyCategoriesController < AdminController end added_headings.each do |heading_id| + # FIXME: This can't handle failure (e.g. if a + # PublicBodyHeading doesn't exist) PublicBodyHeading.find(heading_id).add_category(@category) end end @@ -51,29 +75,13 @@ class AdminPublicBodyCategoriesController < AdminController flash[:notice] = 'Category was successfully updated.' redirect_to edit_admin_category_path(@category) else + @category.build_all_translations render :action => 'edit' end end end end - def create - I18n.with_locale(I18n.default_locale) do - @category = PublicBodyCategory.new(params[:public_body_category]) - if @category.save - if params[:headings] - params[:headings].values.each do |heading_id| - PublicBodyHeading.find(heading_id).add_category(@category) - end - end - flash[:notice] = 'Category was successfully created.' - redirect_to admin_categories_path - else - render :action => 'new' - end - end - end - def destroy @locale = self.locale_from_params I18n.with_locale(@locale) do diff --git a/app/controllers/admin_public_body_controller.rb b/app/controllers/admin_public_body_controller.rb index d188f109d..7de27121a 100644 --- a/app/controllers/admin_public_body_controller.rb +++ b/app/controllers/admin_public_body_controller.rb @@ -23,10 +23,7 @@ class AdminPublicBodyController < AdminController def new @public_body = PublicBody.new - - I18n.available_locales.each do |locale| - @public_body.translations.build(:locale => locale) - end + @public_body.build_all_translations if params[:change_request_id] @change_request = PublicBodyChangeRequest.find(params[:change_request_id]) @@ -58,6 +55,7 @@ class AdminPublicBodyController < AdminController flash[:notice] = 'PublicBody was successfully created.' redirect_to admin_body_url(@public_body) else + @public_body.build_all_translations render :action => 'new' end end @@ -65,10 +63,7 @@ class AdminPublicBodyController < AdminController def edit @public_body = PublicBody.find(params[:id]) - - I18n.available_locales.each do |locale| - @public_body.translations.find_or_initialize_by_locale(locale) - end + @public_body.build_all_translations if params[:change_request_id] @change_request = PublicBodyChangeRequest.find(params[:change_request_id]) @@ -99,6 +94,7 @@ class AdminPublicBodyController < AdminController flash[:notice] = 'PublicBody was successfully updated.' redirect_to admin_body_url(@public_body) else + @public_body.build_all_translations render :action => 'edit' end end diff --git a/app/controllers/admin_public_body_headings_controller.rb b/app/controllers/admin_public_body_headings_controller.rb index e893e760d..a7fe27390 100644 --- a/app/controllers/admin_public_body_headings_controller.rb +++ b/app/controllers/admin_public_body_headings_controller.rb @@ -1,22 +1,52 @@ class AdminPublicBodyHeadingsController < AdminController + def new + @heading = PublicBodyHeading.new + @heading.build_all_translations + end + + def create + I18n.with_locale(I18n.default_locale) do + @heading = PublicBodyHeading.new(params[:public_body_heading]) + if @heading.save + flash[:notice] = 'Heading was successfully created.' + redirect_to admin_categories_url + else + @heading.build_all_translations + render :action => 'new' + end + end + end + def edit @heading = PublicBodyHeading.find(params[:id]) - render :formats => [:html] + @heading.build_all_translations end def update + @heading = PublicBodyHeading.find(params[:id]) + I18n.with_locale(I18n.default_locale) do - @heading = PublicBodyHeading.find(params[:id]) if @heading.update_attributes(params[:public_body_heading]) - flash[:notice] = 'Category heading was successfully updated.' + flash[:notice] = 'Heading was successfully updated.' redirect_to edit_admin_heading_path(@heading) else + @heading.build_all_translations render :action => 'edit' end end end + def destroy + @locale = self.locale_from_params + I18n.with_locale(@locale) do + heading = PublicBodyHeading.find(params[:id]) + heading.destroy + flash[:notice] = "Heading was successfully destroyed." + redirect_to admin_categories_url + end + end + def reorder transaction = reorder_headings(params[:headings]) if transaction[:success] @@ -35,33 +65,6 @@ class AdminPublicBodyHeadingsController < AdminController end end - def new - @heading = PublicBodyHeading.new - render :formats => [:html] - end - - def create - I18n.with_locale(I18n.default_locale) do - @heading = PublicBodyHeading.new(params[:public_body_heading]) - if @heading.save - flash[:notice] = 'Category heading was successfully created.' - redirect_to admin_categories_url - else - render :action => 'new' - end - end - end - - def destroy - @locale = self.locale_from_params() - I18n.with_locale(@locale) do - heading = PublicBodyHeading.find(params[:id]) - heading.destroy - flash[:notice] = "Category heading was successfully destroyed." - redirect_to admin_categories_url - end - end - protected def reorder_headings(headings) diff --git a/app/controllers/general_controller.rb b/app/controllers/general_controller.rb index 438bbfd3f..380da285e 100644 --- a/app/controllers/general_controller.rb +++ b/app/controllers/general_controller.rb @@ -15,6 +15,11 @@ class GeneralController < ApplicationController def frontpage medium_cache @locale = self.locale_from_params() + successful_query = InfoRequestEvent.make_query_from_params( :latest_status => ['successful'] ) + @track_thing = TrackThing.create_track_for_search_query(successful_query) + @feed_autodetect = [ { :url => do_track_url(@track_thing, 'feed'), + :title => _('Successful requests'), + :has_json => true } ] end # Display blog entries diff --git a/app/controllers/public_body_controller.rb b/app/controllers/public_body_controller.rb index cc3d0b64a..854e79a19 100644 --- a/app/controllers/public_body_controller.rb +++ b/app/controllers/public_body_controller.rb @@ -9,9 +9,17 @@ require 'confidence_intervals' require 'tempfile' class PublicBodyController < ApplicationController + + MAX_RESULTS = 500 # TODO: tidy this up with better error messages, and a more standard infrastructure for the redirect to canonical URL def show 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 @@ -45,7 +53,7 @@ class PublicBodyController < ApplicationController # TODO: really should just use SQL query here rather than Xapian. sortby = "described" begin - @xapian_requests = perform_search([InfoRequestEvent], query, sortby, 'request_collapse') + @xapian_requests = perform_search([InfoRequestEvent], query, sortby, 'request_collapse', requests_per_page) if (@page > 1) @page_desc = " (page " + @page.to_s + ")" else |