mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-02-04 08:13:38 +00:00
deluge: Use common view for configuration
This commit is contained in:
parent
fa8c2cf6ff
commit
96ca09d59d
@ -63,6 +63,12 @@ def setup(helper, old_version=None):
|
||||
helper.call('post', service.notify_enabled, None, True)
|
||||
|
||||
|
||||
def get_status():
|
||||
"""Get the current settings."""
|
||||
return {'enabled': is_enabled(),
|
||||
'is_running': is_running()}
|
||||
|
||||
|
||||
def is_enabled():
|
||||
"""Return whether the module is enabled."""
|
||||
return (action_utils.webserver_is_enabled('deluge-plinth') and
|
||||
@ -74,6 +80,13 @@ def is_running():
|
||||
return action_utils.service_is_running('deluge-web')
|
||||
|
||||
|
||||
def enable(should_enable):
|
||||
"""Enable/disable the module."""
|
||||
sub_command = 'enable' if should_enable else 'disable'
|
||||
actions.superuser_run('deluge', [sub_command])
|
||||
service.notify_enabled(None, should_enable)
|
||||
|
||||
|
||||
def diagnose():
|
||||
"""Run diagnostics and return the results."""
|
||||
results = []
|
||||
|
||||
@ -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 Deluge web client.
|
||||
"""
|
||||
|
||||
from django import forms
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
|
||||
class DelugeForm(forms.Form):
|
||||
"""Deluge configuration form."""
|
||||
enabled = forms.BooleanField(
|
||||
label=_('Enable Deluge'),
|
||||
required=False)
|
||||
@ -21,9 +21,10 @@ URLs for the Deluge module.
|
||||
|
||||
from django.conf.urls import url
|
||||
|
||||
from . import views
|
||||
from plinth.views import ConfigurationView
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^apps/deluge/$', views.index, name='index'),
|
||||
url(r'^apps/deluge/$', ConfigurationView.as_view(module_name='deluge'),
|
||||
name='index'),
|
||||
]
|
||||
|
||||
@ -1,75 +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 to configure a Deluge web client.
|
||||
"""
|
||||
|
||||
from django.contrib import messages
|
||||
from django.template.response import TemplateResponse
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
from .forms import DelugeForm
|
||||
from plinth import actions
|
||||
from plinth.modules import deluge
|
||||
|
||||
|
||||
def index(request):
|
||||
"""Serve configuration page."""
|
||||
status = get_status()
|
||||
|
||||
form = None
|
||||
|
||||
if request.method == 'POST':
|
||||
form = DelugeForm(request.POST, prefix='deluge')
|
||||
# pylint: disable=E1101
|
||||
if form.is_valid():
|
||||
_apply_changes(request, status, form.cleaned_data)
|
||||
status = get_status()
|
||||
form = DelugeForm(initial=status, prefix='deluge')
|
||||
else:
|
||||
form = DelugeForm(initial=status, prefix='deluge')
|
||||
|
||||
return TemplateResponse(request, 'deluge.html',
|
||||
{'title': deluge.title,
|
||||
'description': deluge.description,
|
||||
'status': status,
|
||||
'form': form})
|
||||
|
||||
|
||||
def get_status():
|
||||
"""Get the current settings."""
|
||||
status = {'enabled': deluge.is_enabled(),
|
||||
'is_running': deluge.is_running()}
|
||||
|
||||
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('deluge', [sub_command])
|
||||
deluge.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