mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-07 00:08:25 -04:00
Merge pull request #3919 from alphagov/refactor-broadcast-settings
Refactor broadcast settings forms
This commit is contained in:
@@ -321,25 +321,27 @@ def service_set_permission(service_id, permission):
|
||||
@main.route("/services/<uuid:service_id>/service-settings/broadcasts", methods=["GET", "POST"])
|
||||
@user_is_platform_admin
|
||||
def service_set_broadcast_channel(service_id):
|
||||
form = ServiceBroadcastChannelForm(
|
||||
channel=(
|
||||
current_service.live,
|
||||
current_service.broadcast_channel,
|
||||
'all',
|
||||
)
|
||||
)
|
||||
if current_service.has_permission('broadcast'):
|
||||
if current_service.live:
|
||||
channel = current_service.broadcast_channel
|
||||
else:
|
||||
channel = 'training'
|
||||
else:
|
||||
channel = None
|
||||
|
||||
form = ServiceBroadcastChannelForm(channel=channel)
|
||||
|
||||
if form.validate_on_submit():
|
||||
if form.channel.service_mode == 'training':
|
||||
if form.channel.data == 'training':
|
||||
return redirect(url_for(
|
||||
'.service_confirm_broadcast_account_type',
|
||||
service_id=current_service.id,
|
||||
account_type=form.channel.data,
|
||||
account_type='training-test-all'
|
||||
))
|
||||
return redirect(url_for(
|
||||
'.service_set_broadcast_network',
|
||||
service_id=current_service.id,
|
||||
broadcast_channel=form.channel.broadcast_channel,
|
||||
broadcast_channel=form.channel.data,
|
||||
))
|
||||
|
||||
return render_template(
|
||||
@@ -353,25 +355,13 @@ def service_set_broadcast_channel(service_id):
|
||||
def service_set_broadcast_network(service_id, broadcast_channel):
|
||||
# only populate old settings when the channel is unchanged
|
||||
if current_service.broadcast_channel == broadcast_channel:
|
||||
if current_service.allowed_broadcast_provider == 'all':
|
||||
form = ServiceBroadcastNetworkForm(
|
||||
broadcast_channel=broadcast_channel,
|
||||
network_variant=(
|
||||
current_service.live,
|
||||
current_service.broadcast_channel,
|
||||
current_service.allowed_broadcast_provider,
|
||||
),
|
||||
)
|
||||
else:
|
||||
form = ServiceBroadcastNetworkForm(
|
||||
broadcast_channel=broadcast_channel,
|
||||
network_variant='',
|
||||
network=(
|
||||
current_service.live,
|
||||
current_service.broadcast_channel,
|
||||
current_service.allowed_broadcast_provider
|
||||
)
|
||||
)
|
||||
provider = current_service.allowed_broadcast_provider
|
||||
|
||||
form = ServiceBroadcastNetworkForm(
|
||||
broadcast_channel=broadcast_channel,
|
||||
all_networks=provider == 'all',
|
||||
network=provider if provider != 'all' else None,
|
||||
)
|
||||
else:
|
||||
form = ServiceBroadcastNetworkForm(
|
||||
broadcast_channel=broadcast_channel
|
||||
@@ -381,7 +371,7 @@ def service_set_broadcast_network(service_id, broadcast_channel):
|
||||
return redirect(url_for(
|
||||
'.service_confirm_broadcast_account_type',
|
||||
service_id=current_service.id,
|
||||
account_type=form.network_variant.data or form.network.data,
|
||||
account_type=form.account_type,
|
||||
))
|
||||
|
||||
return render_template(
|
||||
|
||||
Reference in New Issue
Block a user