networks: Save to kvstore internet connectivity type

Signed-off-by: Nektarios Katakis <iam@nektarioskatakis.xyz>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
Nektarios Katakis 2020-02-16 00:14:14 +00:00 committed by Sunil Mohan Adapa
parent a95e59460e
commit a8cd9c0b4a
No known key found for this signature in database
GPG Key ID: 43EA1CFF0AA7C5F2
2 changed files with 20 additions and 9 deletions

View File

@ -43,6 +43,7 @@ logger = Logger(__name__)
app = None
ROUTER_CONFIGURATION_TYPE_KEY = 'networks_router_configuration_type'
INTERNET_CONNECTION_TYPE_KEY = 'networks_internet_type'
class NetworksApp(app_module.App):

View File

@ -460,24 +460,34 @@ def internet_connection_type_help_page(request):
is_firstboot = True \
if 'firstboot' in request.build_absolute_uri() else False
if request.method == 'POST':
if request.method == 'POST' and request.POST['internet_connection_type']:
form = InternetConnectionTypeForm(request.POST)
if form.is_valid():
logger.info('Updating internet connectivity type with value: %s' %
request.POST['internet_connection_type'])
kvstore.set(
networks.INTERNET_CONNECTION_TYPE_KEY,
request.POST['internet_connection_type'],
)
if is_firstboot:
resp = reverse_lazy(first_boot.next_step())
return redirect(reverse_lazy(first_boot.next_step()))
else:
resp = reverse_lazy('networks:index')
messages.success(request, _('Internet connection type saved.'))
return redirect(reverse_lazy('networks:index'))
else:
html = "internet_connectivity_type.html"
template_kwargs = {'form': InternetConnectionTypeForm}
initial = {
"internet_connection_type": kvstore.get_default(
networks.INTERNET_CONNECTION_TYPE_KEY, 'dynamic_public_ip'),
}
template_kwargs = {'form': InternetConnectionTypeForm(initial=initial)}
if is_firstboot:
html = "internet_connectivity_type_firstboot.html"
html = "internet_connectivity_firstboot.html"
# mark step done on firstboot visit to get the next_step
first_boot.mark_step_done('router_setup_wizard')
first_boot.mark_step_done('internet_connectivity_type')
template_kwargs.update({
'first_boot_next_step': reverse_lazy(first_boot.next_step()),
})
resp = TemplateResponse(request, html, template_kwargs)
return resp
return TemplateResponse(request, html, template_kwargs)