aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStruan Donald <struan@exo.org.uk>2011-05-04 18:49:39 +0100
committerStruan Donald <struan@exo.org.uk>2011-05-04 18:49:39 +0100
commitb55733c9614b2f8ebd09d31f3c2750959942effa (patch)
tree06371db8845a49c9d5429567a8b6f1bcec287fc7
parent2ae642787ab73073eca0af7c494e00bff946441c (diff)
add in prettyfication of postcode
-rw-r--r--perllib/FixMyStreet/App/Controller/Alert.pm39
-rw-r--r--t/app/controller/alert.t9
2 files changed, 38 insertions, 10 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm
index d11c6adf7..596aeff76 100644
--- a/perllib/FixMyStreet/App/Controller/Alert.pm
+++ b/perllib/FixMyStreet/App/Controller/Alert.pm
@@ -85,16 +85,9 @@ sub list :Path('list') :Args(0) {
#
# return FixMyStreet::Geocode::list_choices($error, '/alert', $q) if ref($error) eq 'ARRAY';
# return alert_front_page($q, $error) if $error;
-#
-# my $pretty_pc = $input_h{pc};
-# my $pretty_pc_text;# This one isnt't getting the nbsp.
-# if (mySociety::PostcodeUtil::is_valid_postcode($input{pc})) {
-# $pretty_pc = mySociety::PostcodeUtil::canonicalise_postcode($input{pc});
-# $pretty_pc_text = $pretty_pc;
-# $pretty_pc_text =~ s/ //g;
-# $pretty_pc =~ s/ /&nbsp;/;
-# }
-#
+
+ $c->forward('prettify_pc');
+
# # truncate the lat,lon for nicer urls
# ( $lat, $lon ) = map { Utils::truncate_coordinate($_) } ( $lat, $lon );
#
@@ -338,6 +331,32 @@ sub list :Path('list') :Args(0) {
# return $out;
}
+=head2 prettify_pc
+
+This will canonicalise and prettify the postcode and stick a pretty_pc and pretty_pc_text in the stash.
+
+=cut
+
+sub prettify_pc : Private {
+ my ( $self, $c ) = @_;
+
+ # FIXME previously this had been run through ent so need to do similar here or in template
+ my $pretty_pc = $c->req->params->{'pc'};
+
+# my $pretty_pc = $input_h{pc};
+# my $pretty_pc_text;# This one isnt't getting the nbsp.
+ if (mySociety::PostcodeUtil::is_valid_postcode($c->req->params->{'pc'})) {
+ $pretty_pc = mySociety::PostcodeUtil::canonicalise_postcode($c->req->params->{'pc'});
+ my $pretty_pc_text = $pretty_pc;
+ $pretty_pc_text =~ s/ //g;
+ $c->stash->{pretty_pc_text} = $pretty_pc_text;
+ # this may be better done in template
+ $pretty_pc =~ s/ /&nbsp;/;
+ }
+
+ $c->stash->{pretty_pc} = $pretty_pc;
+}
+
=head1 AUTHOR
diff --git a/t/app/controller/alert.t b/t/app/controller/alert.t
index 77ed63ea7..4f5ee818c 100644
--- a/t/app/controller/alert.t
+++ b/t/app/controller/alert.t
@@ -13,4 +13,13 @@ $mech->get_ok('/alert');
$mech->content_contains('Local RSS feeds and email alerts');
$mech->content_contains('html lang="en-gb"');
+# check that we can get list page
+$mech->get_ok('/alert/list');
+$mech->content_contains('Local RSS feeds and email alerts');
+$mech->content_contains('html lang="en-gb"');
+
+$mech->get_ok('/alert/list?pc=ZZ99ZY');
+$mech->content_contains('RSS feeds and email alerts for ZZ9&nbsp;9ZY');
+$mech->content_contains('html lang="en-gb"');
+
done_testing();