mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-07-14 02:09:44 -04:00
make sure countries library still returns values
to recap the previous commit, in the ward->local authority->county library we want to return all local authorities and counties. We do this by excluding anything that doesn't have children. However, in the countries library, all four countries don't have children. I can't think of a generic way to separate these so just filter on the library id
This commit is contained in:
@@ -166,17 +166,34 @@ 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
|
||||
is_multi_tier_library = self.query("""
|
||||
SELECT exists(
|
||||
SELECT 1
|
||||
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 NOT NULL
|
||||
)
|
||||
""", library_id)[0][0]
|
||||
|
||||
if is_multi_tier_library:
|
||||
# only interested in areas with children - eg 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 = ?
|
||||
"""
|
||||
else:
|
||||
# Countries don't have any children, so the above query wouldn't return anything.
|
||||
q = """
|
||||
SELECT id, name
|
||||
FROM broadcast_areas
|
||||
WHERE broadcast_area_library_id = ?
|
||||
"""
|
||||
|
||||
results = self.query(q, library_id)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user