mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-05-27 10:44:33 +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
|
_version = 1
|
||||||
|
|
||||||
|
can_be_disabled = False
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
"""Create components for the app."""
|
"""Create components for the app."""
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
{% block configuration %}
|
{% block configuration %}
|
||||||
|
|
||||||
{% if not is_running %}
|
{% if not is_task_running %}
|
||||||
<form class="form form-run-diagnostics" method="post"
|
<form class="form form-run-diagnostics" method="post"
|
||||||
action="{% url 'diagnostics:index' %}">
|
action="{% url 'diagnostics:index' %}">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
|
|||||||
@ -8,7 +8,8 @@ from django.urls import re_path
|
|||||||
from . import views
|
from . import views
|
||||||
|
|
||||||
urlpatterns = [
|
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,
|
re_path(r'^sys/diagnostics/(?P<app_id>[1-9a-z\-_]+)/$', views.diagnose_app,
|
||||||
name='app'),
|
name='app'),
|
||||||
]
|
]
|
||||||
|
|||||||
@ -5,33 +5,44 @@ FreedomBox app for running diagnostics.
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from django.http import Http404
|
from django.http import Http404, HttpResponseRedirect
|
||||||
from django.template.response import TemplateResponse
|
from django.template.response import TemplateResponse
|
||||||
|
from django.urls import reverse
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from django.views.decorators.http import require_POST
|
from django.views.decorators.http import require_POST
|
||||||
|
|
||||||
from plinth.app import App
|
from plinth.app import App
|
||||||
from plinth.modules import diagnostics
|
from plinth.modules import diagnostics
|
||||||
|
from plinth.views import AppView
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def index(request):
|
class DiagnosticsView(AppView):
|
||||||
"""Serve the index page"""
|
"""Diagnostics app page."""
|
||||||
if request.method == 'POST' and not diagnostics.running_task:
|
|
||||||
diagnostics.start_task()
|
|
||||||
|
|
||||||
is_running = diagnostics.running_task is not None
|
app_id = 'diagnostics'
|
||||||
with diagnostics.results_lock:
|
template_name = 'diagnostics.html'
|
||||||
results = diagnostics.current_results
|
|
||||||
|
|
||||||
return TemplateResponse(
|
def post(self, request):
|
||||||
request, 'diagnostics.html', {
|
"""Start diagnostics."""
|
||||||
'app_info': App.get('diagnostics').info,
|
if not diagnostics.running_task:
|
||||||
'is_running': is_running,
|
diagnostics.start_task()
|
||||||
'results': results,
|
|
||||||
'refresh_page_sec': 3 if is_running else None
|
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
|
@require_POST
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user