mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-24 00:07:02 -04:00
Add singular descriptions for libraries
This lets us write nice interface copy like ‘Choose a local authority from the local authorities library’.
This commit is contained in:
@@ -101,9 +101,10 @@ class BroadcastAreaLibrary(SerialisedModelCollection, SortableMixin, GetItemById
|
||||
model = BroadcastArea
|
||||
|
||||
def __init__(self, row):
|
||||
id, name, is_group = row
|
||||
id, name, name_singular, is_group = row
|
||||
self.id = id
|
||||
self.name = name
|
||||
self.name_singular = name_singular
|
||||
self.is_group = bool(is_group)
|
||||
self.items = BroadcastAreasRepository().get_all_areas_for_library(self.id)
|
||||
|
||||
|
||||
Binary file not shown.
@@ -69,15 +69,20 @@ repo.delete_db()
|
||||
repo.create_tables()
|
||||
|
||||
simple_datasets = [
|
||||
("Countries", "ctry19cd", "ctry19nm"),
|
||||
("Countries", "country", "ctry19cd", "ctry19nm"),
|
||||
]
|
||||
for dataset_name, id_field, name_field in simple_datasets:
|
||||
for dataset_name, dataset_name_singular, id_field, name_field in simple_datasets:
|
||||
filepath = package_path / "{}.geojson".format(dataset_name)
|
||||
|
||||
dataset_id = id_field[:-2]
|
||||
dataset_geojson = geojson.loads(filepath.read_text())
|
||||
|
||||
repo.insert_broadcast_area_library(dataset_id, dataset_name, False)
|
||||
repo.insert_broadcast_area_library(
|
||||
dataset_id,
|
||||
name=dataset_name,
|
||||
name_singular=dataset_name_singular,
|
||||
is_group=False,
|
||||
)
|
||||
|
||||
for feature in dataset_geojson["features"]:
|
||||
f_id = dataset_id + "-" + feature["properties"][id_field]
|
||||
@@ -111,8 +116,14 @@ ward_code_to_la_id_mapping = {
|
||||
}
|
||||
|
||||
dataset_name = "Local authorities"
|
||||
dataset_name_singular = "local authority"
|
||||
dataset_id = "wd20-lad20"
|
||||
repo.insert_broadcast_area_library(dataset_id, dataset_name, True)
|
||||
repo.insert_broadcast_area_library(
|
||||
dataset_id,
|
||||
name=dataset_name,
|
||||
name_singular=dataset_name_singular,
|
||||
is_group=True,
|
||||
)
|
||||
|
||||
areas_to_add = []
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ class BroadcastAreasRepository(object):
|
||||
CREATE TABLE broadcast_area_libraries (
|
||||
id TEXT PRIMARY KEY,
|
||||
name TEXT NOT NULL,
|
||||
name_singular TEXT NOT NULL,
|
||||
is_group BOOLEAN NOT NULL
|
||||
)""")
|
||||
|
||||
@@ -62,15 +63,15 @@ class BroadcastAreasRepository(object):
|
||||
ON broadcast_areas (broadcast_area_library_group_id);
|
||||
""")
|
||||
|
||||
def insert_broadcast_area_library(self, id, name, is_group):
|
||||
def insert_broadcast_area_library(self, id, *, name, name_singular, is_group):
|
||||
|
||||
q = """
|
||||
INSERT INTO broadcast_area_libraries (id, name, is_group)
|
||||
VALUES (?, ?, ?)
|
||||
INSERT INTO broadcast_area_libraries (id, name, name_singular, is_group)
|
||||
VALUES (?, ?, ?, ?)
|
||||
"""
|
||||
|
||||
with self.conn() as conn:
|
||||
conn.execute(q, (id, name, is_group))
|
||||
conn.execute(q, (id, name, name_singular, is_group))
|
||||
|
||||
def insert_broadcast_areas(self, areas):
|
||||
|
||||
@@ -106,9 +107,9 @@ class BroadcastAreasRepository(object):
|
||||
return cursor.fetchall()
|
||||
|
||||
def get_libraries(self):
|
||||
q = "SELECT id, name, is_group FROM broadcast_area_libraries"
|
||||
q = "SELECT id, name, name_singular, is_group FROM broadcast_area_libraries"
|
||||
results = self.query(q)
|
||||
libraries = [(row[0], row[1], row[2]) for row in results]
|
||||
libraries = [(row[0], row[1], row[2], row[3]) for row in results]
|
||||
return sorted(libraries)
|
||||
|
||||
def get_library_description(self, library_id):
|
||||
|
||||
@@ -126,6 +126,7 @@ def choose_broadcast_area(service_id, broadcast_message_id, library_slug):
|
||||
search_form=SearchByNameForm(),
|
||||
show_search_form=(len(library) > 7),
|
||||
library=library,
|
||||
page_title=f'Choose a {library.name_singular.lower()}',
|
||||
broadcast_message=broadcast_message,
|
||||
)
|
||||
|
||||
@@ -142,7 +143,7 @@ def choose_broadcast_area(service_id, broadcast_message_id, library_slug):
|
||||
form=form,
|
||||
search_form=SearchByNameForm(),
|
||||
show_search_form=(len(form.areas.choices) > 7),
|
||||
page_title=library.name,
|
||||
page_title=f'Choose {library.name.lower()}',
|
||||
broadcast_message=broadcast_message,
|
||||
)
|
||||
|
||||
|
||||
@@ -4,13 +4,13 @@
|
||||
{% extends "withnav_template.html" %}
|
||||
|
||||
{% block service_page_title %}
|
||||
{{ library.name }}
|
||||
{{ page_title }}
|
||||
{% endblock %}
|
||||
|
||||
{% block maincolumn_content %}
|
||||
|
||||
{{ page_header(
|
||||
library.name,
|
||||
page_title,
|
||||
back_link=url_for('.choose_broadcast_library', service_id=current_service.id, broadcast_message_id=broadcast_message.id),
|
||||
)}}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user