mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-09 01:23:11 -04:00
Let users select electoral wards of local authorities
If a library has groups, we should show a link instead of selecting the group directly. Then we can give the user the choice of selecting the whole of that group, or specific areas within the group. For now the only libraries we have with groups are local authorities, which group electoral wards.
This commit is contained in:
@@ -12,6 +12,7 @@ from app import current_service
|
||||
from app.main import main
|
||||
from app.main.forms import (
|
||||
BroadcastAreaForm,
|
||||
BroadcastAreaFormWithSelectAll,
|
||||
ChooseBroadcastDurationForm,
|
||||
SearchByNameForm,
|
||||
)
|
||||
@@ -118,6 +119,16 @@ def choose_broadcast_area(service_id, broadcast_message_id, library_slug):
|
||||
service_id=current_service.id,
|
||||
)
|
||||
library = BroadcastMessage.libraries.get(library_slug)
|
||||
|
||||
if library.is_group:
|
||||
return render_template(
|
||||
'views/broadcast/areas-with-sub-areas.html',
|
||||
search_form=SearchByNameForm(),
|
||||
show_search_form=(len(library) > 7),
|
||||
library=library,
|
||||
broadcast_message=broadcast_message,
|
||||
)
|
||||
|
||||
form = BroadcastAreaForm.from_library(library)
|
||||
if form.validate_on_submit():
|
||||
broadcast_message.add_areas(*form.areas.data)
|
||||
@@ -136,6 +147,41 @@ def choose_broadcast_area(service_id, broadcast_message_id, library_slug):
|
||||
)
|
||||
|
||||
|
||||
@main.route(
|
||||
'/services/<uuid:service_id>/broadcast/<uuid:broadcast_message_id>/libraries/<library_slug>/<area_slug>',
|
||||
methods=['GET', 'POST'],
|
||||
)
|
||||
@user_has_permissions('send_messages')
|
||||
@service_has_permission('broadcast')
|
||||
def choose_broadcast_sub_area(service_id, broadcast_message_id, library_slug, area_slug):
|
||||
broadcast_message = BroadcastMessage.from_id(
|
||||
broadcast_message_id,
|
||||
service_id=current_service.id,
|
||||
)
|
||||
area = BroadcastMessage.libraries.get_areas(area_slug)[0]
|
||||
|
||||
form = BroadcastAreaFormWithSelectAll.from_library(
|
||||
area.sub_areas,
|
||||
select_all_choice=(area.id, f'All of {area.name}'),
|
||||
)
|
||||
if form.validate_on_submit():
|
||||
broadcast_message.add_areas(*form.selected_areas)
|
||||
return redirect(url_for(
|
||||
'.preview_broadcast_areas',
|
||||
service_id=current_service.id,
|
||||
broadcast_message_id=broadcast_message.id,
|
||||
))
|
||||
return render_template(
|
||||
'views/broadcast/sub-areas.html',
|
||||
form=form,
|
||||
search_form=SearchByNameForm(),
|
||||
show_search_form=(len(form.areas.choices) > 7),
|
||||
library_slug=library_slug,
|
||||
page_title=f'Choose an area of {area.name}',
|
||||
broadcast_message=broadcast_message,
|
||||
)
|
||||
|
||||
|
||||
@main.route('/services/<uuid:service_id>/broadcast/<uuid:broadcast_message_id>/remove/<area_slug>')
|
||||
@user_has_permissions('send_messages')
|
||||
@service_has_permission('broadcast')
|
||||
|
||||
Reference in New Issue
Block a user