diff --git a/plinth/modules/deluge/__init__.py b/plinth/modules/deluge/__init__.py
index f5c1b6f37..794817b36 100644
--- a/plinth/modules/deluge/__init__.py
+++ b/plinth/modules/deluge/__init__.py
@@ -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 = []
diff --git a/plinth/modules/deluge/forms.py b/plinth/modules/deluge/forms.py
deleted file mode 100644
index 3ae1271d9..000000000
--- a/plinth/modules/deluge/forms.py
+++ /dev/null
@@ -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 .
-#
-
-"""
-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)
diff --git a/plinth/modules/deluge/urls.py b/plinth/modules/deluge/urls.py
index a36941271..4aa3712fd 100644
--- a/plinth/modules/deluge/urls.py
+++ b/plinth/modules/deluge/urls.py
@@ -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'),
]
diff --git a/plinth/modules/deluge/views.py b/plinth/modules/deluge/views.py
deleted file mode 100644
index 0b48b2333..000000000
--- a/plinth/modules/deluge/views.py
+++ /dev/null
@@ -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 .
-#
-
-"""
-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'))