diff options
author | Matthew Somerville <matthew@mysociety.org> | 2011-06-10 14:40:30 +0100 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2011-06-10 14:40:30 +0100 |
commit | 40f13d3cc9dc903da5299901623677c205eff484 (patch) | |
tree | dc9ba86101496ef80ba9068cae83d7892e467dac | |
parent | b02e8e5e29aa1b7087b08d6d7eddccae516b171a (diff) |
Consolidate MaPit calls to call out to it less.
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Around.pm | 22 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Council.pm | 21 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/New.pm | 7 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Barnet.pm | 13 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Southampton.pm | 12 | ||||
-rw-r--r-- | t/app/controller/report_updates.t | 2 | ||||
-rw-r--r-- | templates/web/default/index.html | 4 |
7 files changed, 30 insertions, 51 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm index 2bfd52633..82d920b3e 100644 --- a/perllib/FixMyStreet/App/Controller/Around.pm +++ b/perllib/FixMyStreet/App/Controller/Around.pm @@ -220,24 +220,14 @@ sub check_location_is_acceptable : Private { my $lat = $c->stash->{latitude}; my $lon = $c->stash->{longitude}; - # Check this location is okay to be displayed for the cobrand - my ( $success, $error_msg ) = $c->cobrand->council_check( # - { lat => $lat, lon => $lon }, - 'submit_problem' - ); - # If in UK and we have a lat,lon coocdinate check it is in UK - if ( !$error_msg && $lat && $c->config->{COUNTRY} eq 'GB' ) { + if ( $lat && $c->config->{COUNTRY} eq 'GB' ) { eval { Utils::convert_latlon_to_en( $lat, $lon ); }; - $error_msg = - _( "We had a problem with the supplied co-ordinates - outside the UK?" - ) if $@; - } - - # show error - if ($error_msg) { - $c->stash->{location_error} = $error_msg; - return; + if ($@) { + $c->stash->{location_error} = + _( "We had a problem with the supplied co-ordinates - outside the UK?" ); + return; + } } # check that there are councils that can accept this location diff --git a/perllib/FixMyStreet/App/Controller/Council.pm b/perllib/FixMyStreet/App/Controller/Council.pm index 53f7e38d8..35e3d0d11 100644 --- a/perllib/FixMyStreet/App/Controller/Council.pm +++ b/perllib/FixMyStreet/App/Controller/Council.pm @@ -48,10 +48,23 @@ sub load_and_check_councils : Private { @area_types = $c->cobrand->area_types(); } - # TODO: I think we want in_gb_locale around the next line, needs testing - my $all_councils = - mySociety::MaPit::call( 'point', "4326/$longitude,$latitude", - type => \@area_types ); + # TODO: I think we want in_gb_locale around the MaPit line, needs testing + my $all_councils; + if ( $c->stash->{fetch_all_areas} ) { + my %area_types = map { $_ => 1 } @area_types; + my $all_areas = + mySociety::MaPit::call( 'point', "4326/$longitude,$latitude" ); + $c->stash->{all_areas} = $all_areas; + $all_councils = { + map { $_ => $all_areas->{$_} } + grep { $area_types{ $all_areas->{$_}->{type} } } + keys %$all_areas + }; + } else { + $all_councils = + mySociety::MaPit::call( 'point', "4326/$longitude,$latitude", + type => \@area_types ); + } # Let cobrand do a check my ( $success, $error_msg ) = diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index 46a90384c..375b36a51 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -341,6 +341,7 @@ could be found. sub determine_location : Private { my ( $self, $c ) = @_; + $c->stash->{fetch_all_areas} = 1; return 1 if # ( # @@ -618,11 +619,7 @@ sub process_report : Private { $report->name( Utils::trim_text( $params{name} ) ); $report->category( _ $params{category} ); - # FIXME: This is more inefficient than old FixMyStreet code, - # with 2 MaPit point calls per submission now rather than just one. - my $mapit_query = - sprintf( "4326/%s,%s", $report->longitude, $report->latitude ); - my $areas = mySociety::MaPit::call( 'point', $mapit_query ); + my $areas = $c->stash->{all_areas}; $report->areas( ',' . join( ',', sort keys %$areas ) . ',' ); # From earlier in the process. diff --git a/perllib/FixMyStreet/Cobrand/Barnet.pm b/perllib/FixMyStreet/Cobrand/Barnet.pm index e7bc67c5c..bccd27885 100644 --- a/perllib/FixMyStreet/Cobrand/Barnet.pm +++ b/perllib/FixMyStreet/Cobrand/Barnet.pm @@ -43,18 +43,7 @@ sub enter_postcode_text { sub council_check { my ( $self, $params, $context ) = @_; - my $councils; - if ( $params->{all_councils} ) { - $councils = $params->{all_councils}; - } - elsif ( defined $params->{lat} ) { - my $parent_types = $mySociety::VotingArea::council_parent_types; - $councils = mySociety::MaPit::call( - 'point', - "4326/$params->{lon},$params->{lat}", - type => $parent_types - ); - } + my $councils = $params->{all_councils}; my $council_match = defined $councils->{2489}; if ($council_match) { return 1; diff --git a/perllib/FixMyStreet/Cobrand/Southampton.pm b/perllib/FixMyStreet/Cobrand/Southampton.pm index d70d818be..6b4aae742 100644 --- a/perllib/FixMyStreet/Cobrand/Southampton.pm +++ b/perllib/FixMyStreet/Cobrand/Southampton.pm @@ -43,17 +43,7 @@ sub enter_postcode_text { sub council_check { my ( $self, $params, $context ) = @_; - my $councils; - if ($params->{all_councils}) { - $councils = $params->{all_councils}; - } elsif (defined $params->{lat}) { - my $parent_types = $mySociety::VotingArea::council_parent_types; - $councils = mySociety::MaPit::call( - 'point', - "4326/$params->{lon},$params->{lat}", - type => $parent_types - ); - } + my $councils = $params->{all_councils}; my $council_match = defined $councils->{2567}; if ($council_match) { return 1; diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t index 4f7d1628d..4dd1db737 100644 --- a/t/app/controller/report_updates.t +++ b/t/app/controller/report_updates.t @@ -363,7 +363,7 @@ for my $test ( is $add_alerts, $details->{add_alert} ? 1 : 0, 'do not sign up for alerts'; $mech->get_ok( $url . $url_token ); - $mech->content_contains("/report/$report_id#$update_id"); + $mech->content_contains("/report/$report_id#update_$update_id"); my $unreg_user = FixMyStreet::App->model( 'DB::User' )->find( { email => $details->{rznvy} } ); diff --git a/templates/web/default/index.html b/templates/web/default/index.html index 9c786459c..5dffb5f10 100644 --- a/templates/web/default/index.html +++ b/templates/web/default/index.html @@ -72,9 +72,9 @@ %] -[% IF probs.size || recent_photos %] +[% IF probs.size || recent_photos.size %] <div id="front_recent"> - [% IF recent_photos %] + [% IF recent_photos.size %] <h2>[% loc('Photos of recent reports') %]</h2> [% FOREACH p IN recent_photos %] <a href="/report/[% p.id %]"><img border="0" height="100" |