mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-21 07:55:00 +00:00
diagnostics: Use AppView for app page
Tests: - Enable/disable button is not present. - Diagnostics menu item is not present. - Page shows 'Running diagnostics' button when diagnostics are not running. - Page shows progress bar and results when diagnostics are running/completed. Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
2eca38299f
commit
b970b72bb0
@ -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__()
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
|
||||
{% block configuration %}
|
||||
|
||||
{% if not is_running %}
|
||||
{% if not is_task_running %}
|
||||
<form class="form form-run-diagnostics" method="post"
|
||||
action="{% url 'diagnostics:index' %}">
|
||||
{% csrf_token %}
|
||||
|
||||
@ -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<app_id>[1-9a-z\-_]+)/$', views.diagnose_app,
|
||||
name='app'),
|
||||
]
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user