From 0d0c417bcd09219c7fff33aff71821a3a52beca7 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Fri, 19 Aug 2022 16:42:14 -0700 Subject: [PATCH] networks: Use AppView for app page Tests: - Enable/disable button is not shown. - Diagnostics button is shown and works. - Connections list, internet connection type and connectivity are shown properly. Signed-off-by: Sunil Mohan Adapa Reviewed-by: James Valleroy --- plinth/modules/networks/__init__.py | 2 ++ plinth/modules/networks/urls.py | 2 +- plinth/modules/networks/views.py | 35 +++++++++++++++-------------- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/plinth/modules/networks/__init__.py b/plinth/modules/networks/__init__.py index df6485ae3..3e7252428 100644 --- a/plinth/modules/networks/__init__.py +++ b/plinth/modules/networks/__init__.py @@ -48,6 +48,8 @@ class NetworksApp(app_module.App): _version = 1 + can_be_disabled = False + def __init__(self): """Create components for the app.""" super().__init__() diff --git a/plinth/modules/networks/urls.py b/plinth/modules/networks/urls.py index e185181e5..b32f8f715 100644 --- a/plinth/modules/networks/urls.py +++ b/plinth/modules/networks/urls.py @@ -8,7 +8,7 @@ from django.urls import re_path from . import views urlpatterns = [ - re_path(r'^sys/networks/$', views.index, name='index'), + re_path(r'^sys/networks/$', views.NetworksAppView.as_view(), name='index'), re_path(r'^sys/networks/(?P[\w.@+-]+)/show/$', views.show, name='show'), re_path(r'^sys/networks/(?P[\w.@+-]+)/edit/$', views.edit, diff --git a/plinth/modules/networks/views.py b/plinth/modules/networks/views.py index c799dadb0..81c00f84d 100644 --- a/plinth/modules/networks/views.py +++ b/plinth/modules/networks/views.py @@ -12,9 +12,9 @@ from django.utils.translation import gettext_lazy from django.views.decorators.http import require_POST from django.views.generic.edit import FormView -from plinth import app as app_module from plinth import network from plinth.modules import first_boot, networks +from plinth.views import AppView from .forms import (ConnectionTypeSelectForm, EthernetForm, GenericForm, InternetConnectionTypeForm, NetworkTopologyForm, PPPoEForm, @@ -115,23 +115,24 @@ WIRELESS_MODE_STRINGS = { } -def index(request): - """Show connection list.""" - connections = network.get_connection_list() +class NetworksAppView(AppView): + """Show networks app main page.""" - network_topology_type = networks.get_network_topology_type() - internet_connection_type = networks.get_internet_connection_type() - return TemplateResponse( - request, 'networks_configuration.html', { - 'app_id': 'networks', - 'app_info': app_module.App.get('networks').info, - 'title': _('Network Connections'), - 'has_diagnostics': True, - 'is_enabled': True, - 'connections': connections, - 'network_topology': network_topology_type, - 'internet_connectivity_type': internet_connection_type, - }) + app_id = 'networks' + template_name = 'networks_configuration.html' + + def get_context_data(self, *args, **kwargs): + """Add additional context data for template.""" + connections = network.get_connection_list() + + network_topology_type = networks.get_network_topology_type() + internet_connection_type = networks.get_internet_connection_type() + + context = super().get_context_data(*args, **kwargs) + context['connections'] = connections + context['network_topology'] = network_topology_type + context['internet_connectivity_type'] = internet_connection_type + return context def show(request, uuid):