diff --git a/plinth/modules/diagnostics/__init__.py b/plinth/modules/diagnostics/__init__.py index 169f917de..97dad9efa 100644 --- a/plinth/modules/diagnostics/__init__.py +++ b/plinth/modules/diagnostics/__init__.py @@ -41,6 +41,8 @@ class DiagnosticsApp(app_module.App): _version = 1 + can_be_disabled = False + def __init__(self): """Create components for the app.""" super().__init__() diff --git a/plinth/modules/diagnostics/templates/diagnostics.html b/plinth/modules/diagnostics/templates/diagnostics.html index 624e39102..a6e4703f1 100644 --- a/plinth/modules/diagnostics/templates/diagnostics.html +++ b/plinth/modules/diagnostics/templates/diagnostics.html @@ -8,7 +8,7 @@ {% block configuration %} - {% if not is_running %} + {% if not is_task_running %}
{% csrf_token %} diff --git a/plinth/modules/diagnostics/urls.py b/plinth/modules/diagnostics/urls.py index 202d34db1..26ddc4df6 100644 --- a/plinth/modules/diagnostics/urls.py +++ b/plinth/modules/diagnostics/urls.py @@ -8,7 +8,8 @@ from django.urls import re_path from . import views urlpatterns = [ - re_path(r'^sys/diagnostics/$', views.index, name='index'), + re_path(r'^sys/diagnostics/$', views.DiagnosticsView.as_view(), + name='index'), re_path(r'^sys/diagnostics/(?P[1-9a-z\-_]+)/$', views.diagnose_app, name='app'), ] diff --git a/plinth/modules/diagnostics/views.py b/plinth/modules/diagnostics/views.py index 3f2d66146..c9fb247eb 100644 --- a/plinth/modules/diagnostics/views.py +++ b/plinth/modules/diagnostics/views.py @@ -5,33 +5,44 @@ FreedomBox app for running diagnostics. import logging -from django.http import Http404 +from django.http import Http404, HttpResponseRedirect from django.template.response import TemplateResponse +from django.urls import reverse from django.utils.translation import gettext_lazy as _ from django.views.decorators.http import require_POST from plinth.app import App from plinth.modules import diagnostics +from plinth.views import AppView logger = logging.getLogger(__name__) -def index(request): - """Serve the index page""" - if request.method == 'POST' and not diagnostics.running_task: - diagnostics.start_task() +class DiagnosticsView(AppView): + """Diagnostics app page.""" - is_running = diagnostics.running_task is not None - with diagnostics.results_lock: - results = diagnostics.current_results + app_id = 'diagnostics' + template_name = 'diagnostics.html' - return TemplateResponse( - request, 'diagnostics.html', { - 'app_info': App.get('diagnostics').info, - 'is_running': is_running, - 'results': results, - 'refresh_page_sec': 3 if is_running else None - }) + def post(self, request): + """Start diagnostics.""" + if not diagnostics.running_task: + diagnostics.start_task() + + return HttpResponseRedirect(reverse('diagnostics:index')) + + def get_context_data(self, **kwargs): + """Return additional context for rendering the template.""" + is_task_running = diagnostics.running_task is not None + with diagnostics.results_lock: + results = diagnostics.current_results + + context = super().get_context_data(**kwargs) + context['has_diagnostics'] = False + context['is_task_running'] = is_task_running + context['results'] = results + context['refresh_page_sec'] = 3 if is_task_running else None + return context @require_POST