From 33f51142411bfb1b3866e6bbae9fb8b57e9926e6 Mon Sep 17 00:00:00 2001 From: Nektarios Katakis Date: Fri, 10 Jan 2020 12:22:13 +0000 Subject: [PATCH] networks: modify as first boot wizard step Signed-off-by: Nektarios Katakis Reviewed-by: James Valleroy --- plinth/modules/networks/networks.py | 31 ++++++++++++--- ...html => router_configuration_content.html} | 14 ------- .../router_configuration_firstboot.html | 38 +++++++++++++++++++ .../router_configuration_update.html | 37 ++++++++++++++++++ 4 files changed, 100 insertions(+), 20 deletions(-) rename plinth/modules/networks/templates/{router_configuration.html => router_configuration_content.html} (90%) create mode 100644 plinth/modules/networks/templates/router_configuration_firstboot.html create mode 100644 plinth/modules/networks/templates/router_configuration_update.html diff --git a/plinth/modules/networks/networks.py b/plinth/modules/networks/networks.py index 66a1c6ab4..0adc732c5 100644 --- a/plinth/modules/networks/networks.py +++ b/plinth/modules/networks/networks.py @@ -25,7 +25,7 @@ from django.utils.translation import ugettext as _ from django.views.decorators.http import require_POST from plinth import network -from plinth.modules import networks +from plinth.modules import networks, first_boot from .forms import (ConnectionTypeSelectForm, EthernetForm, GenericForm, PPPoEForm, WifiForm, RouterConfigurationWizardForm) @@ -423,15 +423,34 @@ def router_configuration_help_page(request): Show the router configuration wizard page/form. Used both for fistboot step and same networks page. """ + is_firstboot = True \ + if 'firstboot' in request.build_absolute_uri() else False + if request.method == "POST": - resp = reverse_lazy('networks:index') + if is_firstboot: + resp = reverse_lazy(first_boot.next_step()) + else: + resp = reverse_lazy('networks:index') + messages.success(request, _('Router configuration type saved.')) return redirect(resp) else: - template_kwargs = { - 'form': RouterConfigurationWizardForm, + html = "router_configuration_update.html" + initial = { + "router_config": kvstore.get_default( + networks.ROUTER_CONFIGURATION_TYPE_KEY, 'dmz'), } + template_kwargs = { + 'form': RouterConfigurationWizardForm(initial=initial), + } + if is_firstboot: + html = "router_configuration_firstboot.html" - return TemplateResponse(request, 'router_configuration.html', - template_kwargs) + # mark step done on firstboot visit to get the next_step + first_boot.mark_step_done('router_setup_wizard') + template_kwargs.update({ + 'first_boot_next_step': reverse_lazy(first_boot.next_step()), + }) + + return TemplateResponse(request, html, template_kwargs) diff --git a/plinth/modules/networks/templates/router_configuration.html b/plinth/modules/networks/templates/router_configuration_content.html similarity index 90% rename from plinth/modules/networks/templates/router_configuration.html rename to plinth/modules/networks/templates/router_configuration_content.html index 82afc3427..da72708cb 100644 --- a/plinth/modules/networks/templates/router_configuration.html +++ b/plinth/modules/networks/templates/router_configuration_content.html @@ -1,4 +1,3 @@ -{% extends "base.html" %} {% comment %} # # This file is part of FreedomBox. @@ -22,7 +21,6 @@ {% load i18n %} {% load static %} -{% block content %}

{% trans "Setup FreedomBox Behind a Router" %}

{% blocktrans trimmed %} @@ -61,15 +59,3 @@ how to perform this task. {% endblocktrans %}

- -
- {% csrf_token %} - - {{ form|bootstrap }} - - - -
- -{% endblock %} diff --git a/plinth/modules/networks/templates/router_configuration_firstboot.html b/plinth/modules/networks/templates/router_configuration_firstboot.html new file mode 100644 index 000000000..f3b6ba607 --- /dev/null +++ b/plinth/modules/networks/templates/router_configuration_firstboot.html @@ -0,0 +1,38 @@ +{% extends "base_firstboot.html" %} +{% comment %} +# +# This file is part of FreedomBox. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +{% endcomment %} + +{% load bootstrap %} +{% load i18n %} +{% load static %} + +{% block content %} + {% include "router_configuration_content.html" %} + +
+ {% csrf_token %} + + {{ form|bootstrap }} + + {% trans "skip this step" %} + +
+ +{% endblock %} diff --git a/plinth/modules/networks/templates/router_configuration_update.html b/plinth/modules/networks/templates/router_configuration_update.html new file mode 100644 index 000000000..4983ef15d --- /dev/null +++ b/plinth/modules/networks/templates/router_configuration_update.html @@ -0,0 +1,37 @@ +{% extends "base.html" %} +{% comment %} +# +# This file is part of FreedomBox. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +{% endcomment %} + +{% load bootstrap %} +{% load i18n %} +{% load static %} + +{% block content %} + {% include "router_configuration_content.html" %} + +
+ {% csrf_token %} + + {{ form|bootstrap }} + + +
+ +{% endblock %}