mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-14 23:08:07 -04:00
add counties page
What was previously ward -> local authority is now a ward -> local authority -> county. County only covers rural counties and not metropolitan boroughs and other unitary authorities. Previously, there was a page full of local authorities (unitary authorities and districts), and each one of those would have a list of electoral wards. However, now there are counties that contain a list of districts - so this needs a new page - a checkbox for "select the county" and then a list of links to district pages. If you want to select multiple districts, you'll need to go into each one of those sub-sections in turn and click select all. Needed to tweak the query to retrieve the list of areas in a list for a library. Previously, it just returned anything at top level (ie: didn't have a parent). However, rural districts now have parents (the rural counties themselves). So the query now returns "everything that isn't a leaf node", or in more specific terms, everything that has at least other row referring to it as a parent. So no electoral wards, since they dont have any children, but yes to districts and counties.
This commit is contained in:
@@ -44,7 +44,7 @@ class BroadcastArea(SortableMixin):
|
|||||||
BroadcastAreasRepository().get_simple_polygons_for_area(self.id)
|
BroadcastAreasRepository().get_simple_polygons_for_area(self.id)
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
@cached_property
|
||||||
def sub_areas(self):
|
def sub_areas(self):
|
||||||
return [
|
return [
|
||||||
BroadcastArea(row)
|
BroadcastArea(row)
|
||||||
|
|||||||
@@ -166,11 +166,16 @@ class BroadcastAreasRepository(object):
|
|||||||
return areas
|
return areas
|
||||||
|
|
||||||
def get_all_areas_for_library(self, library_id):
|
def get_all_areas_for_library(self, library_id):
|
||||||
|
# only interested in areas with children - local authorities, counties, unitary authorities. not wards.
|
||||||
q = """
|
q = """
|
||||||
SELECT id, name
|
SELECT id, name
|
||||||
FROM broadcast_areas
|
FROM broadcast_areas
|
||||||
|
JOIN (
|
||||||
|
SELECT DISTINCT broadcast_area_library_group_id
|
||||||
|
FROM broadcast_areas
|
||||||
|
WHERE broadcast_area_library_group_id IS NOT NULL
|
||||||
|
) AS parent_broadcast_areas ON parent_broadcast_areas.broadcast_area_library_group_id = broadcast_areas.id
|
||||||
WHERE broadcast_area_library_id = ?
|
WHERE broadcast_area_library_id = ?
|
||||||
AND broadcast_area_library_group_id IS NULL
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
results = self.query(q, library_id)
|
results = self.query(q, library_id)
|
||||||
|
|||||||
@@ -160,8 +160,10 @@ def choose_broadcast_sub_area(service_id, broadcast_message_id, library_slug, ar
|
|||||||
)
|
)
|
||||||
area = BroadcastMessage.libraries.get_areas(area_slug)[0]
|
area = BroadcastMessage.libraries.get_areas(area_slug)[0]
|
||||||
|
|
||||||
|
is_county = any(sub_area.sub_areas for sub_area in area.sub_areas)
|
||||||
|
|
||||||
form = BroadcastAreaFormWithSelectAll.from_library(
|
form = BroadcastAreaFormWithSelectAll.from_library(
|
||||||
area.sub_areas,
|
[] if is_county else area.sub_areas,
|
||||||
select_all_choice=(area.id, f'All of {area.name}'),
|
select_all_choice=(area.id, f'All of {area.name}'),
|
||||||
)
|
)
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
@@ -171,6 +173,20 @@ def choose_broadcast_sub_area(service_id, broadcast_message_id, library_slug, ar
|
|||||||
service_id=current_service.id,
|
service_id=current_service.id,
|
||||||
broadcast_message_id=broadcast_message.id,
|
broadcast_message_id=broadcast_message.id,
|
||||||
))
|
))
|
||||||
|
|
||||||
|
if is_county:
|
||||||
|
# area = county. sub_areas = districts. they have wards, so link to individual district pages
|
||||||
|
return render_template(
|
||||||
|
'views/broadcast/counties.html',
|
||||||
|
form=form,
|
||||||
|
search_form=SearchByNameForm(),
|
||||||
|
show_search_form=(len(area.sub_areas) > 7),
|
||||||
|
library_slug=library_slug,
|
||||||
|
page_title=f'Choose an area of {area.name}',
|
||||||
|
broadcast_message=broadcast_message,
|
||||||
|
county=area,
|
||||||
|
)
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
'views/broadcast/sub-areas.html',
|
'views/broadcast/sub-areas.html',
|
||||||
form=form,
|
form=form,
|
||||||
|
|||||||
42
app/templates/views/broadcast/counties.html
Normal file
42
app/templates/views/broadcast/counties.html
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
{% from "components/page-header.html" import page_header %}
|
||||||
|
{% from "components/live-search.html" import live_search %}
|
||||||
|
{% from "components/page-footer.html" import sticky_page_footer %}
|
||||||
|
{% from "components/form.html" import form_wrapper %}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
{% extends "withnav_template.html" %}
|
||||||
|
|
||||||
|
{% block service_page_title %}
|
||||||
|
{{ page_title }}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block maincolumn_content %}
|
||||||
|
|
||||||
|
{{ page_header(
|
||||||
|
page_title,
|
||||||
|
back_link=url_for('.choose_broadcast_library', service_id=current_service.id, broadcast_message_id=broadcast_message.id),
|
||||||
|
)}}
|
||||||
|
|
||||||
|
{% call form_wrapper() %}
|
||||||
|
|
||||||
|
<div class="form-group govuk-!-margin-bottom-4">
|
||||||
|
{{ form.select_all }}
|
||||||
|
</div>
|
||||||
|
{{ live_search(target_selector='.file-list-item', show=show_search_form, form=search_form, label='Or by district') }}
|
||||||
|
|
||||||
|
{% for area in county.sub_areas|sort %}
|
||||||
|
<div class="file-list-item">
|
||||||
|
{# these are districts within a county#}
|
||||||
|
<a
|
||||||
|
class="file-list-filename-large govuk-link govuk-link--no-visited-state"
|
||||||
|
href="{{ url_for('.choose_broadcast_sub_area', service_id=current_service.id, broadcast_message_id=broadcast_message.id, library_slug=library_slug, area_slug=area.id) }}"
|
||||||
|
>{{ area.name }}</a>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
{{ sticky_page_footer('Add to broadcast') }}
|
||||||
|
|
||||||
|
{% endcall %}
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
@@ -16,7 +16,7 @@ def test_loads_libraries():
|
|||||||
False,
|
False,
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
'wd20-lad20',
|
'wd20-lad20-ctyua19',
|
||||||
'Local authorities',
|
'Local authorities',
|
||||||
True,
|
True,
|
||||||
),
|
),
|
||||||
@@ -40,7 +40,7 @@ def test_examples():
|
|||||||
countries = broadcast_area_libraries.get('ctry19').get_examples()
|
countries = broadcast_area_libraries.get('ctry19').get_examples()
|
||||||
assert countries == 'England, Northern Ireland, Scotland, and Wales'
|
assert countries == 'England, Northern Ireland, Scotland, and Wales'
|
||||||
|
|
||||||
wards = broadcast_area_libraries.get('wd20-lad20').get_examples()
|
wards = broadcast_area_libraries.get('wd20-lad20-ctyua19').get_examples()
|
||||||
assert wards == 'Aberdeen City, Aberdeenshire, Adur, and 375 more…'
|
assert wards == 'Aberdeen City, Aberdeenshire, Adur, and 375 more…'
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -412,7 +412,7 @@ def test_choose_broadcast_area_page_for_area_with_sub_areas(
|
|||||||
'.choose_broadcast_area',
|
'.choose_broadcast_area',
|
||||||
service_id=SERVICE_ONE_ID,
|
service_id=SERVICE_ONE_ID,
|
||||||
broadcast_message_id=fake_uuid,
|
broadcast_message_id=fake_uuid,
|
||||||
library_slug='wd20-lad20',
|
library_slug='wd20-lad20-ctyua19',
|
||||||
)
|
)
|
||||||
assert normalize_spaces(page.select_one('h1').text) == (
|
assert normalize_spaces(page.select_one('h1').text) == (
|
||||||
'Choose a local authority'
|
'Choose a local authority'
|
||||||
@@ -425,7 +425,7 @@ def test_choose_broadcast_area_page_for_area_with_sub_areas(
|
|||||||
'main.choose_broadcast_sub_area',
|
'main.choose_broadcast_sub_area',
|
||||||
service_id=SERVICE_ONE_ID,
|
service_id=SERVICE_ONE_ID,
|
||||||
broadcast_message_id=fake_uuid,
|
broadcast_message_id=fake_uuid,
|
||||||
library_slug='wd20-lad20',
|
library_slug='wd20-lad20-ctyua19',
|
||||||
)
|
)
|
||||||
choices = [
|
choices = [
|
||||||
(
|
(
|
||||||
@@ -453,7 +453,7 @@ def test_choose_broadcast_area_page_for_area_with_sub_areas(
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def test_choose_broadcast_sub_area_page(
|
def test_choose_broadcast_sub_area_page_for_district_shows_checkboxes_for_wards(
|
||||||
client_request,
|
client_request,
|
||||||
service_one,
|
service_one,
|
||||||
mock_get_draft_broadcast_message,
|
mock_get_draft_broadcast_message,
|
||||||
@@ -464,7 +464,7 @@ def test_choose_broadcast_sub_area_page(
|
|||||||
'main.choose_broadcast_sub_area',
|
'main.choose_broadcast_sub_area',
|
||||||
service_id=SERVICE_ONE_ID,
|
service_id=SERVICE_ONE_ID,
|
||||||
broadcast_message_id=fake_uuid,
|
broadcast_message_id=fake_uuid,
|
||||||
library_slug='wd20-lad20',
|
library_slug='wd20-lad20-ctyua19',
|
||||||
area_slug='lad20-S12000033',
|
area_slug='lad20-S12000033',
|
||||||
)
|
)
|
||||||
assert normalize_spaces(page.select_one('h1').text) == (
|
assert normalize_spaces(page.select_one('h1').text) == (
|
||||||
@@ -502,6 +502,62 @@ def test_choose_broadcast_sub_area_page(
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def test_choose_broadcast_sub_area_page_for_county_shows_links_for_districts(
|
||||||
|
client_request,
|
||||||
|
service_one,
|
||||||
|
mock_get_draft_broadcast_message,
|
||||||
|
fake_uuid,
|
||||||
|
):
|
||||||
|
service_one['permissions'] += ['broadcast']
|
||||||
|
page = client_request.get(
|
||||||
|
'main.choose_broadcast_sub_area',
|
||||||
|
service_id=SERVICE_ONE_ID,
|
||||||
|
broadcast_message_id=fake_uuid,
|
||||||
|
library_slug='wd20-lad20-ctyua19',
|
||||||
|
area_slug='ctyua19-E10000016', # Kent
|
||||||
|
)
|
||||||
|
assert normalize_spaces(page.select_one('h1').text) == (
|
||||||
|
'Choose an area of Kent'
|
||||||
|
)
|
||||||
|
live_search = page.select_one("[data-module=live-search]")
|
||||||
|
assert live_search['data-targets'] == '.file-list-item'
|
||||||
|
assert live_search.select_one('input')['type'] == 'search'
|
||||||
|
all_choices_checkbox = [
|
||||||
|
(
|
||||||
|
choice.select_one('input')['value'],
|
||||||
|
normalize_spaces(choice.select_one('label').text),
|
||||||
|
)
|
||||||
|
for choice in page.select('form[method=post] .govuk-checkboxes__item')
|
||||||
|
]
|
||||||
|
districts = [
|
||||||
|
(
|
||||||
|
district['href'],
|
||||||
|
district.text,
|
||||||
|
)
|
||||||
|
for district in page.select('form[method=post] a')
|
||||||
|
]
|
||||||
|
assert all_choices_checkbox == [
|
||||||
|
('y', 'All of Kent'),
|
||||||
|
]
|
||||||
|
assert len(districts) == 12
|
||||||
|
assert districts[0][0] == url_for(
|
||||||
|
'main.choose_broadcast_sub_area',
|
||||||
|
service_id=SERVICE_ONE_ID,
|
||||||
|
broadcast_message_id=fake_uuid,
|
||||||
|
library_slug='wd20-lad20-ctyua19',
|
||||||
|
area_slug='lad20-E07000105'
|
||||||
|
)
|
||||||
|
assert districts[0][1] == 'Ashford'
|
||||||
|
assert districts[-1][0] == url_for(
|
||||||
|
'main.choose_broadcast_sub_area',
|
||||||
|
service_id=SERVICE_ONE_ID,
|
||||||
|
broadcast_message_id=fake_uuid,
|
||||||
|
library_slug='wd20-lad20-ctyua19',
|
||||||
|
area_slug='lad20-E07000116'
|
||||||
|
)
|
||||||
|
assert districts[-1][1] == 'Tunbridge Wells'
|
||||||
|
|
||||||
|
|
||||||
def test_add_broadcast_area(
|
def test_add_broadcast_area(
|
||||||
client_request,
|
client_request,
|
||||||
service_one,
|
service_one,
|
||||||
@@ -554,7 +610,7 @@ def test_add_broadcast_area(
|
|||||||
'wd20-S13002836',
|
'wd20-S13002836',
|
||||||
]),
|
]),
|
||||||
))
|
))
|
||||||
def test_add_broadcast_sub_area(
|
def test_add_broadcast_sub_area_district_view(
|
||||||
client_request,
|
client_request,
|
||||||
service_one,
|
service_one,
|
||||||
mock_get_draft_broadcast_message,
|
mock_get_draft_broadcast_message,
|
||||||
@@ -574,7 +630,7 @@ def test_add_broadcast_sub_area(
|
|||||||
'.choose_broadcast_sub_area',
|
'.choose_broadcast_sub_area',
|
||||||
service_id=SERVICE_ONE_ID,
|
service_id=SERVICE_ONE_ID,
|
||||||
broadcast_message_id=fake_uuid,
|
broadcast_message_id=fake_uuid,
|
||||||
library_slug='wd20-lad20',
|
library_slug='wd20-lad20-ctyua19',
|
||||||
area_slug='lad20-S12000033',
|
area_slug='lad20-S12000033',
|
||||||
_data=post_data,
|
_data=post_data,
|
||||||
)
|
)
|
||||||
@@ -592,6 +648,44 @@ def test_add_broadcast_sub_area(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_add_broadcast_sub_area_county_view(
|
||||||
|
client_request,
|
||||||
|
service_one,
|
||||||
|
mock_get_draft_broadcast_message,
|
||||||
|
mock_update_broadcast_message,
|
||||||
|
fake_uuid,
|
||||||
|
mocker,
|
||||||
|
):
|
||||||
|
service_one['permissions'] += ['broadcast']
|
||||||
|
polygon_class = namedtuple("polygon_class", ["as_coordinate_pairs_lat_long"])
|
||||||
|
coordinates = [[50.1, 0.1], [50.2, 0.2], [50.3, 0.2]]
|
||||||
|
polygons = polygon_class(as_coordinate_pairs_lat_long=coordinates)
|
||||||
|
mocker.patch('app.models.broadcast_message.BroadcastMessage.get_simple_polygons', return_value=polygons)
|
||||||
|
|
||||||
|
client_request.post(
|
||||||
|
'.choose_broadcast_sub_area',
|
||||||
|
service_id=SERVICE_ONE_ID,
|
||||||
|
broadcast_message_id=fake_uuid,
|
||||||
|
library_slug='wd20-lad20-ctyua19',
|
||||||
|
area_slug='ctyua19-E10000016', # Kent
|
||||||
|
_data={'select_all': 'y'},
|
||||||
|
)
|
||||||
|
mock_update_broadcast_message.assert_called_once_with(
|
||||||
|
service_id=SERVICE_ONE_ID,
|
||||||
|
broadcast_message_id=fake_uuid,
|
||||||
|
data={
|
||||||
|
'simple_polygons': coordinates,
|
||||||
|
'areas': [
|
||||||
|
# These two areas are on the broadcast already
|
||||||
|
'ctry19-E92000001',
|
||||||
|
'ctry19-S92000003',
|
||||||
|
] + [
|
||||||
|
'ctyua19-E10000016'
|
||||||
|
]
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_remove_broadcast_area_page(
|
def test_remove_broadcast_area_page(
|
||||||
client_request,
|
client_request,
|
||||||
service_one,
|
service_one,
|
||||||
|
|||||||
Reference in New Issue
Block a user