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:
Leo Hemsted
2020-09-04 15:22:32 +01:00
parent c421e14d69
commit 256d2b2b60
6 changed files with 168 additions and 11 deletions

View File

@@ -166,11 +166,16 @@ class BroadcastAreasRepository(object):
return areas
def get_all_areas_for_library(self, library_id):
# only interested in areas with children - local authorities, counties, unitary authorities. not wards.
q = """
SELECT id, name
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 = ?
AND broadcast_area_library_group_id IS NULL
"""
results = self.query(q, library_id)