mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-21 07:55:00 +00:00
snapshot: Use AppView for app page
Tests: - Enable/disable button is not shown. - Diagnostics menu item is shown and works. - Both Configure and manage snapshots tabs are shown. - Changing configuration works, updated configuration is shown. - Deleting some snapshots works. Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
29bf55dedb
commit
9b6774f279
@ -44,6 +44,8 @@ class SnapshotApp(app_module.App):
|
||||
|
||||
_version = 4
|
||||
|
||||
can_be_disabled = False
|
||||
|
||||
def __init__(self):
|
||||
"""Create components for the app."""
|
||||
super().__init__()
|
||||
|
||||
@ -7,7 +7,8 @@
|
||||
{% load i18n %}
|
||||
|
||||
{% block configuration %}
|
||||
<form id="snapshot-configure" class="form-horizontal" method="post">
|
||||
<form id="snapshot-configure" class="form-horizontal form-configuration"
|
||||
method="post">
|
||||
{% csrf_token %}
|
||||
<h3>{% trans "Configuration" %}</h3>
|
||||
{{ form|bootstrap_horizontal:'col-md-4' }}
|
||||
|
||||
@ -4,6 +4,7 @@ Functional, browser based tests for snapshot app.
|
||||
"""
|
||||
|
||||
import pytest
|
||||
|
||||
from plinth.tests import functional
|
||||
|
||||
pytestmark = [pytest.mark.system, pytest.mark.snapshot]
|
||||
@ -73,7 +74,8 @@ def _delete_all(browser):
|
||||
|
||||
def _create_snapshot(browser):
|
||||
functional.visit(browser, '/plinth/sys/snapshot/manage/')
|
||||
functional.submit(browser) # Click on 'Create Snapshot'
|
||||
create_button = browser.find_by_name('create').first
|
||||
functional.submit(browser, create_button)
|
||||
|
||||
|
||||
def _get_count(browser):
|
||||
@ -102,7 +104,7 @@ def _set_configuration(browser, free_space, timeline_enabled, software_enabled,
|
||||
browser.find_by_name('weekly_limit').fill(weekly)
|
||||
browser.find_by_name('monthly_limit').fill(monthly)
|
||||
browser.find_by_name('yearly_limit').fill(yearly)
|
||||
functional.submit(browser)
|
||||
functional.submit(browser, form_class='form-configuration')
|
||||
|
||||
|
||||
def _get_configuration(browser):
|
||||
|
||||
@ -8,7 +8,7 @@ from django.urls import re_path
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
re_path(r'^sys/snapshot/$', views.index, name='index'),
|
||||
re_path(r'^sys/snapshot/$', views.SnapshotAppView.as_view(), name='index'),
|
||||
re_path(r'^sys/snapshot/manage/$', views.manage, name='manage'),
|
||||
re_path(r'^sys/snapshot/selected/delete$', views.delete_selected,
|
||||
name='delete-selected'),
|
||||
|
||||
@ -19,6 +19,7 @@ from plinth import app as app_module
|
||||
from plinth.errors import ActionError
|
||||
from plinth.modules import snapshot as snapshot_module
|
||||
from plinth.modules import storage
|
||||
from plinth.views import AppView
|
||||
|
||||
from . import get_configuration
|
||||
from .forms import SnapshotForm
|
||||
@ -55,29 +56,31 @@ def not_supported_view(request):
|
||||
template_data)
|
||||
|
||||
|
||||
def index(request):
|
||||
"""Show snapshot list."""
|
||||
if not snapshot_module.is_supported():
|
||||
return not_supported_view(request)
|
||||
class SnapshotAppView(AppView):
|
||||
"""Show snapshot app main page."""
|
||||
|
||||
status = get_configuration()
|
||||
if request.method == 'POST':
|
||||
form = SnapshotForm(request.POST)
|
||||
if 'update' in request.POST and form.is_valid():
|
||||
update_configuration(request, status, form.cleaned_data)
|
||||
status = get_configuration()
|
||||
form = SnapshotForm(initial=status)
|
||||
else:
|
||||
form = SnapshotForm(initial=status)
|
||||
app_id = 'snapshot'
|
||||
template_name = 'snapshot.html'
|
||||
form_class = SnapshotForm
|
||||
|
||||
app = app_module.App.get('snapshot')
|
||||
return TemplateResponse(
|
||||
request, 'snapshot.html', {
|
||||
'app_info': app.info,
|
||||
'title': app.info.name,
|
||||
'subsubmenu': subsubmenu,
|
||||
'form': form
|
||||
})
|
||||
def get_initial(self):
|
||||
"""Return the values to fill in the form."""
|
||||
initial = super().get_initial()
|
||||
initial.update(get_configuration())
|
||||
return initial
|
||||
|
||||
def get_context_data(self, *args, **kwargs):
|
||||
"""Add additional context data for template."""
|
||||
context = super().get_context_data(*args, **kwargs)
|
||||
context['subsubmenu'] = subsubmenu
|
||||
return context
|
||||
|
||||
def form_valid(self, form):
|
||||
"""Apply the changes submitted in the form."""
|
||||
if 'update' in self.request.POST:
|
||||
update_configuration(self.request, form.initial, form.cleaned_data)
|
||||
|
||||
return super().form_valid(form)
|
||||
|
||||
|
||||
def manage(request):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user