power: Use AppView for app page

Tests:

- Enable/disable button is not shown.

- Diagnostics menu item is not shown.

- If apt is busy a warning message is shown.

- Restart and Shutdown buttons are shown and work.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa 2022-08-19 16:46:54 -07:00 committed by James Valleroy
parent 0d0c417bcd
commit a7eb5e8f0e
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808
3 changed files with 15 additions and 10 deletions

View File

@ -21,6 +21,8 @@ class PowerApp(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__()

View File

@ -8,7 +8,7 @@ from django.urls import re_path
from . import views from . import views
urlpatterns = [ urlpatterns = [
re_path(r'^sys/power/$', views.index, name='index'), re_path(r'^sys/power/$', views.PowerAppView.as_view(), name='index'),
re_path(r'^sys/power/restart$', views.restart, name='restart'), re_path(r'^sys/power/restart$', views.restart, name='restart'),
re_path(r'^sys/power/shutdown$', views.shutdown, name='shutdown'), re_path(r'^sys/power/shutdown$', views.shutdown, name='shutdown'),
] ]

View File

@ -11,17 +11,20 @@ from django.urls import reverse
from plinth import actions from plinth import actions
from plinth import app as app_module from plinth import app as app_module
from plinth import package from plinth import package
from plinth.views import AppView
def index(request): class PowerAppView(AppView):
"""Serve power controls page.""" """Show power app main page."""
app = app_module.App.get('power')
return TemplateResponse( app_id = 'power'
request, 'power.html', { template_name = 'power.html'
'title': app.info.name,
'app_info': app.info, def get_context_data(self, *args, **kwargs):
'pkg_manager_is_busy': package.is_package_manager_busy() """Add additional context data for template."""
}) context = super().get_context_data(*args, **kwargs)
context['pkg_manager_is_busy'] = package.is_package_manager_busy()
return context
def restart(request): def restart(request):