mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-05-20 10:34:30 +00:00
restore: Use common view for configuration
- Rename the template from restore_index.html to restore.html to avoid having to create a custom view.
This commit is contained in:
parent
1eae781e64
commit
07df62854b
@ -20,11 +20,12 @@ Plinth module to configure reStore.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
|
from plinth import actions
|
||||||
from plinth import action_utils, cfg
|
from plinth import action_utils, cfg
|
||||||
from plinth import service as service_module
|
from plinth import service as service_module
|
||||||
from plinth.utils import format_lazy
|
from plinth.utils import format_lazy
|
||||||
|
|
||||||
service = None
|
|
||||||
|
|
||||||
version = 1
|
version = 1
|
||||||
|
|
||||||
@ -45,6 +46,8 @@ description = [
|
|||||||
'<a href=\'/restore/\'>reStore web-interface</a>.')
|
'<a href=\'/restore/\'>reStore web-interface</a>.')
|
||||||
]
|
]
|
||||||
|
|
||||||
|
service = None
|
||||||
|
|
||||||
|
|
||||||
def init():
|
def init():
|
||||||
"""Initialize the reStore module."""
|
"""Initialize the reStore module."""
|
||||||
@ -62,6 +65,18 @@ def setup(helper, old_version=None):
|
|||||||
helper.install(['node-restore'])
|
helper.install(['node-restore'])
|
||||||
|
|
||||||
|
|
||||||
|
def get_status():
|
||||||
|
"""Get the current settings."""
|
||||||
|
return {'enabled': is_enabled()}
|
||||||
|
|
||||||
|
|
||||||
def is_enabled():
|
def is_enabled():
|
||||||
"""Return whether the module is enabled."""
|
"""Return whether the module is enabled."""
|
||||||
return action_utils.service_is_enabled('node-restore')
|
return action_utils.service_is_enabled('node-restore')
|
||||||
|
|
||||||
|
|
||||||
|
def enable(should_enable):
|
||||||
|
"""Enable/disable the module."""
|
||||||
|
sub_command = 'enable' if should_enable else 'disable'
|
||||||
|
actions.superuser_run('restore', [sub_command])
|
||||||
|
service.notify_enabled(None, should_enable)
|
||||||
|
|||||||
@ -1,30 +0,0 @@
|
|||||||
#
|
|
||||||
# This file is part of Plinth.
|
|
||||||
#
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU Affero General Public License as
|
|
||||||
# published by the Free Software Foundation, either version 3 of the
|
|
||||||
# License, or (at your option) any later version.
|
|
||||||
#
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU Affero General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
#
|
|
||||||
|
|
||||||
"""
|
|
||||||
Forms for configuring reStore.
|
|
||||||
"""
|
|
||||||
|
|
||||||
from django import forms
|
|
||||||
from django.utils.translation import ugettext_lazy as _
|
|
||||||
|
|
||||||
|
|
||||||
class ReStoreForm(forms.Form):
|
|
||||||
"""reStore configuration form."""
|
|
||||||
enabled = forms.BooleanField(
|
|
||||||
label=_('Enable reStore'),
|
|
||||||
required=False)
|
|
||||||
@ -21,9 +21,10 @@ URLs for the reStore module.
|
|||||||
|
|
||||||
from django.conf.urls import url
|
from django.conf.urls import url
|
||||||
|
|
||||||
from . import views
|
from plinth.views import ConfigurationView
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^apps/restore/$', views.index, name='index'),
|
url(r'^apps/restore/$', ConfigurationView.as_view(module_name='restore'),
|
||||||
|
name='index'),
|
||||||
]
|
]
|
||||||
|
|||||||
@ -1,70 +0,0 @@
|
|||||||
#
|
|
||||||
# This file is part of Plinth.
|
|
||||||
#
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU Affero General Public License as
|
|
||||||
# published by the Free Software Foundation, either version 3 of the
|
|
||||||
# License, or (at your option) any later version.
|
|
||||||
#
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU Affero General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
#
|
|
||||||
|
|
||||||
"""
|
|
||||||
Plinth module for configuring reStore.
|
|
||||||
"""
|
|
||||||
|
|
||||||
from django.contrib import messages
|
|
||||||
from django.template.response import TemplateResponse
|
|
||||||
from django.utils.translation import ugettext as _
|
|
||||||
|
|
||||||
from .forms import ReStoreForm
|
|
||||||
from plinth import actions
|
|
||||||
from plinth.modules import restore
|
|
||||||
|
|
||||||
|
|
||||||
def index(request):
|
|
||||||
"""Serve configuration page."""
|
|
||||||
status = get_status()
|
|
||||||
|
|
||||||
if request.method == 'POST':
|
|
||||||
form = ReStoreForm(request.POST, prefix='restore')
|
|
||||||
if form.is_valid():
|
|
||||||
_apply_changes(request, status, form.cleaned_data)
|
|
||||||
status = get_status()
|
|
||||||
form = ReStoreForm(initial=status, prefix='restore')
|
|
||||||
else:
|
|
||||||
form = ReStoreForm(initial=status, prefix='restore')
|
|
||||||
|
|
||||||
return TemplateResponse(request, 'restore_index.html',
|
|
||||||
{'title': restore.title,
|
|
||||||
'description': restore.description,
|
|
||||||
'status': status,
|
|
||||||
'form': form})
|
|
||||||
|
|
||||||
|
|
||||||
def get_status():
|
|
||||||
"""Get the current settings."""
|
|
||||||
status = {'enabled': restore.is_enabled()}
|
|
||||||
return status
|
|
||||||
|
|
||||||
|
|
||||||
def _apply_changes(request, old_status, new_status):
|
|
||||||
"""Apply the changes."""
|
|
||||||
modified = False
|
|
||||||
|
|
||||||
if old_status['enabled'] != new_status['enabled']:
|
|
||||||
sub_command = 'enable' if new_status['enabled'] else 'disable'
|
|
||||||
actions.superuser_run('restore', [sub_command])
|
|
||||||
restore.service.notify_enabled(None, new_status['enabled'])
|
|
||||||
modified = True
|
|
||||||
|
|
||||||
if modified:
|
|
||||||
messages.success(request, _('Configuration updated'))
|
|
||||||
else:
|
|
||||||
messages.info(request, _('Setting unchanged'))
|
|
||||||
Loading…
x
Reference in New Issue
Block a user