diff --git a/plinth/modules/owncloud/forms.py b/plinth/forms.py
similarity index 83%
rename from plinth/modules/owncloud/forms.py
rename to plinth/forms.py
index 3ea4c6f8c..f554bcfc8 100644
--- a/plinth/modules/owncloud/forms.py
+++ b/plinth/forms.py
@@ -16,15 +16,15 @@
#
"""
-Forms for configuring ownCloud.
+Common forms for use by modules.
"""
from django import forms
from django.utils.translation import ugettext_lazy as _
-class OwnCloudForm(forms.Form): # pylint: disable-msg=W0232
- """ownCloud configuration form"""
+class ConfigurationForm(forms.Form):
+ """Generic configuration form for simple modules."""
enabled = forms.BooleanField(
- label=_('Enable ownCloud'),
+ label=_('Enable application'),
required=False)
diff --git a/plinth/modules/apps/apps.py b/plinth/modules/apps/apps.py
index 39c77c43f..9d90af549 100644
--- a/plinth/modules/apps/apps.py
+++ b/plinth/modules/apps/apps.py
@@ -23,8 +23,8 @@ from plinth import cfg
def init():
"""Initailize the apps module"""
- cfg.main_menu.add_urlname(_('Apps'), 'glyphicon-download-alt', 'apps:index',
- 80)
+ cfg.main_menu.add_urlname(_('Apps'), 'glyphicon-download-alt',
+ 'apps:index', 80)
def index(request):
diff --git a/plinth/modules/avahi/__init__.py b/plinth/modules/avahi/__init__.py
index d3da6fc45..1e07bc9aa 100644
--- a/plinth/modules/avahi/__init__.py
+++ b/plinth/modules/avahi/__init__.py
@@ -21,6 +21,7 @@ Plinth module for service discovery.
from django.utils.translation import ugettext_lazy as _
+from plinth import actions
from plinth import action_utils
from plinth import cfg
from plinth import service as service_module
@@ -65,6 +66,12 @@ def setup(helper, old_version=False):
helper.install(['avahi-daemon'])
+def get_status():
+ """Get the current settings from server."""
+ return {'enabled': is_enabled(),
+ 'is_running': is_running()}
+
+
def is_enabled():
"""Return whether the module is enabled."""
return action_utils.service_is_enabled('avahi-daemon')
@@ -73,3 +80,10 @@ def is_enabled():
def is_running():
"""Return whether the service is running."""
return action_utils.service_is_running('avahi-daemon')
+
+
+def enable(should_enable):
+ """Enable/disable the module."""
+ sub_command = 'enable' if should_enable else 'disable'
+ actions.superuser_run('avahi', [sub_command])
+ service.notify_enabled(None, should_enable)
diff --git a/plinth/modules/avahi/forms.py b/plinth/modules/avahi/forms.py
deleted file mode 100644
index 66776d0c0..000000000
--- a/plinth/modules/avahi/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 .
-#
-
-"""
-Plinth module for service discovery forms.
-"""
-
-from django import forms
-from django.utils.translation import ugettext_lazy as _
-
-
-class ServiceDiscoveryForm(forms.Form):
- """Service discovery form."""
- enabled = forms.BooleanField(
- label=_('Enable service discovery'),
- required=False)
diff --git a/plinth/modules/avahi/urls.py b/plinth/modules/avahi/urls.py
index d9f84d89d..9a86c45f6 100644
--- a/plinth/modules/avahi/urls.py
+++ b/plinth/modules/avahi/urls.py
@@ -21,9 +21,10 @@ URLs for the service discovery module.
from django.conf.urls import url
-from . import views
+from plinth.views import ConfigurationView
urlpatterns = [
- url(r'^sys/avahi/$', views.index, name='index'),
+ url(r'^sys/avahi/$', ConfigurationView.as_view(module_name='avahi'),
+ name='index'),
]
diff --git a/plinth/modules/avahi/views.py b/plinth/modules/avahi/views.py
deleted file mode 100644
index 77751abca..000000000
--- a/plinth/modules/avahi/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 for service discovery views.
-"""
-
-from django.contrib import messages
-from django.template.response import TemplateResponse
-from django.utils.translation import ugettext as _
-import logging
-
-from .forms import ServiceDiscoveryForm
-from plinth import actions
-from plinth.modules import avahi
-
-
-logger = logging.getLogger(__name__) # pylint: disable=C0103
-
-
-def index(request):
- """Serve configuration page."""
- status = get_status()
-
- form = None
-
- if request.method == 'POST':
- form = ServiceDiscoveryForm(request.POST, prefix='avahi')
- if form.is_valid():
- _apply_changes(request, status, form.cleaned_data)
- status = get_status()
- form = ServiceDiscoveryForm(initial=status, prefix='avahi')
- else:
- form = ServiceDiscoveryForm(initial=status, prefix='avahi')
-
- return TemplateResponse(request, 'avahi.html',
- {'title': avahi.title,
- 'description': avahi.description,
- 'status': status,
- 'form': form})
-
-
-def get_status():
- """Get the current settings from server."""
- return {'enabled': avahi.is_enabled(),
- 'is_running': avahi.is_running()}
-
-
-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'
- modified = True
- actions.superuser_run('avahi', [sub_command])
- avahi.service.notify_enabled(None, new_status['enabled'])
- messages.success(request, _('Configuration updated'))
-
- if not modified:
- messages.info(request, _('Setting unchanged'))
diff --git a/plinth/modules/config/config.py b/plinth/modules/config/config.py
index 4957589bd..8f75bca2a 100644
--- a/plinth/modules/config/config.py
+++ b/plinth/modules/config/config.py
@@ -226,7 +226,7 @@ def _apply_changes(request, old_status, new_status):
request.session[translation.LANGUAGE_SESSION_KEY] = language
except Exception as exception:
messages.error(request, _('Error setting language: {exception}')
- .format(exception=exception))
+ .format(exception=exception))
else:
messages.success(request, _('Language changed'))
diff --git a/plinth/modules/datetime/__init__.py b/plinth/modules/datetime/__init__.py
index 0c200169a..b82a92169 100644
--- a/plinth/modules/datetime/__init__.py
+++ b/plinth/modules/datetime/__init__.py
@@ -59,6 +59,19 @@ def setup(helper, old_version=None):
helper.call('post', service.notify_enabled, None, True)
+def get_status():
+ """Get the current settings from server."""
+ return {'enabled': is_enabled(),
+ 'is_running': is_running(),
+ 'time_zone': get_current_time_zone()}
+
+
+def get_current_time_zone():
+ """Get current time zone."""
+ time_zone = open('/etc/timezone').read().rstrip()
+ return time_zone or 'none'
+
+
def is_enabled():
"""Return whether the module is enabled."""
return action_utils.service_is_enabled('ntp')
diff --git a/plinth/modules/datetime/urls.py b/plinth/modules/datetime/urls.py
index 080e3e103..8840eb403 100644
--- a/plinth/modules/datetime/urls.py
+++ b/plinth/modules/datetime/urls.py
@@ -21,8 +21,10 @@ URLs for the date and time module
from django.conf.urls import url
-from . import views
+from .views import ConfigurationView
+
urlpatterns = [
- url(r'^sys/datetime/$', views.index, name='index'),
+ url(r'^sys/datetime/$', ConfigurationView.as_view(module_name='datetime'),
+ name='index'),
]
diff --git a/plinth/modules/datetime/views.py b/plinth/modules/datetime/views.py
index f687e1506..cb2ac9a90 100644
--- a/plinth/modules/datetime/views.py
+++ b/plinth/modules/datetime/views.py
@@ -20,74 +20,43 @@ Plinth module for configuring date and time
"""
from django.contrib import messages
-from django.template.response import TemplateResponse
from django.utils.translation import ugettext as _
import logging
from .forms import DateTimeForm
from plinth import actions
+from plinth import views
from plinth.modules import datetime
logger = logging.getLogger(__name__)
-def index(request):
+class ConfigurationView(views.ConfigurationView):
"""Serve configuration page."""
- status = get_status()
+ form_class = DateTimeForm
- form = None
+ def apply_changes(self, old_status, new_status):
+ """Apply the changes."""
+ modified = False
- if request.method == 'POST':
- form = DateTimeForm(request.POST, prefix='datetime')
- # pylint: disable=E1101
- if form.is_valid():
- _apply_changes(request, status, form.cleaned_data)
- status = get_status()
- form = DateTimeForm(initial=status, prefix='datetime')
- else:
- form = DateTimeForm(initial=status, prefix='datetime')
+ if old_status['enabled'] != new_status['enabled']:
+ sub_command = 'enable' if new_status['enabled'] else 'disable'
+ modified = True
+ actions.superuser_run('datetime', [sub_command])
+ datetime.service.notify_enabled(None, new_status['enabled'])
+ messages.success(self.request, _('Configuration updated'))
- return TemplateResponse(request, 'datetime.html',
- {'title': datetime.title,
- 'description': datetime.description,
- 'status': status,
- 'form': form})
+ if old_status['time_zone'] != new_status['time_zone'] and \
+ new_status['time_zone'] != 'none':
+ modified = True
+ try:
+ actions.superuser_run(
+ 'timezone-change', [new_status['time_zone']])
+ except Exception as exception:
+ messages.error(
+ self.request, _('Error setting time zone: {exception}')
+ .format(exception=exception))
+ else:
+ messages.success(self.request, _('Time zone set'))
-
-def get_status():
- """Get the current settings from server."""
- return {'enabled': datetime.is_enabled(),
- 'is_running': datetime.is_running(),
- 'time_zone': get_current_time_zone()}
-
-
-def get_current_time_zone():
- """Get current time zone."""
- time_zone = open('/etc/timezone').read().rstrip()
- return time_zone or 'none'
-
-
-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'
- modified = True
- actions.superuser_run('datetime', [sub_command])
- datetime.service.notify_enabled(None, new_status['enabled'])
- messages.success(request, _('Configuration updated'))
-
- if old_status['time_zone'] != new_status['time_zone'] and \
- new_status['time_zone'] != 'none':
- modified = True
- try:
- actions.superuser_run('timezone-change', [new_status['time_zone']])
- except Exception as exception:
- messages.error(request, _('Error setting time zone: {exception}')
- .format(exception=exception))
- else:
- messages.success(request, _('Time zone set'))
-
- if not modified:
- messages.info(request, _('Setting unchanged'))
+ return modified
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'))
diff --git a/plinth/modules/firewall/views.py b/plinth/modules/firewall/views.py
index 3dab988ab..8ed984741 100644
--- a/plinth/modules/firewall/views.py
+++ b/plinth/modules/firewall/views.py
@@ -26,7 +26,7 @@ import plinth.service as service_module
def index(request):
- """Serve introcution page"""
+ """Serve introduction page"""
if not firewall.get_enabled_status():
return TemplateResponse(request, 'firewall.html',
{'title': firewall.title,
diff --git a/plinth/modules/help/help.py b/plinth/modules/help/help.py
index 0f8aa3f52..1db714089 100644
--- a/plinth/modules/help/help.py
+++ b/plinth/modules/help/help.py
@@ -20,7 +20,6 @@ Help module for Plinth.
"""
import os
-from gettext import gettext as _
from django.http import Http404
from django.template.response import TemplateResponse
from django.utils.translation import ugettext as _, ugettext_lazy
diff --git a/plinth/modules/ikiwiki/__init__.py b/plinth/modules/ikiwiki/__init__.py
index 05f105743..f6bc67ce3 100644
--- a/plinth/modules/ikiwiki/__init__.py
+++ b/plinth/modules/ikiwiki/__init__.py
@@ -65,11 +65,23 @@ def setup(helper, old_version=None):
helper.call('post', service.notify_enabled, None, True)
+def get_status():
+ """Get the current setting."""
+ return {'enabled': is_enabled()}
+
+
def is_enabled():
"""Return whether the module is enabled."""
return action_utils.webserver_is_enabled('ikiwiki-plinth')
+def enable(should_enable):
+ """Enable/disable the module."""
+ sub_command = 'enable' if should_enable else 'disable'
+ actions.superuser_run('ikiwiki', [sub_command])
+ service.notify_enabled(None, should_enable)
+
+
def diagnose():
"""Run diagnostics and return the results."""
results = []
diff --git a/plinth/modules/ikiwiki/forms.py b/plinth/modules/ikiwiki/forms.py
index 11d3c8020..a5c4a7f27 100644
--- a/plinth/modules/ikiwiki/forms.py
+++ b/plinth/modules/ikiwiki/forms.py
@@ -23,13 +23,6 @@ from django import forms
from django.utils.translation import ugettext_lazy as _
-class IkiwikiForm(forms.Form):
- """ikiwiki configuration form."""
- enabled = forms.BooleanField(
- label=_('Enable ikiwiki'),
- required=False)
-
-
class IkiwikiCreateForm(forms.Form):
"""Form to create a wiki or blog."""
site_type = forms.ChoiceField(
diff --git a/plinth/modules/ikiwiki/urls.py b/plinth/modules/ikiwiki/urls.py
index 59bf30236..65854ae88 100644
--- a/plinth/modules/ikiwiki/urls.py
+++ b/plinth/modules/ikiwiki/urls.py
@@ -25,7 +25,8 @@ from . import views
urlpatterns = [
- url(r'^apps/ikiwiki/$', views.index, name='index'),
+ url(r'^apps/ikiwiki/$',
+ views.ConfigurationView.as_view(module_name='ikiwiki'), name='index'),
url(r'^apps/ikiwiki/manage/$', views.manage, name='manage'),
url(r'^apps/ikiwiki/(?P[\w.@+-]+)/delete/$', views.delete,
name='delete'),
diff --git a/plinth/modules/ikiwiki/views.py b/plinth/modules/ikiwiki/views.py
index 27c1a855a..df806bdb6 100644
--- a/plinth/modules/ikiwiki/views.py
+++ b/plinth/modules/ikiwiki/views.py
@@ -25,9 +25,9 @@ from django.shortcuts import redirect
from django.template.response import TemplateResponse
from django.utils.translation import ugettext as _, ugettext_lazy
-from .forms import IkiwikiForm, IkiwikiCreateForm
+from .forms import IkiwikiCreateForm
from plinth import actions
-from plinth.modules import ikiwiki
+from plinth import views
subsubmenu = [{'url': reverse_lazy('ikiwiki:index'),
@@ -38,48 +38,14 @@ subsubmenu = [{'url': reverse_lazy('ikiwiki:index'),
'text': ugettext_lazy('Create')}]
-def index(request):
+class ConfigurationView(views.ConfigurationView):
"""Serve configuration page."""
- status = get_status()
+ def get_context_data(self, **kwargs):
+ """Return the context data for rendering the template view."""
+ if 'subsubmenu' not in kwargs:
+ kwargs['subsubmenu'] = subsubmenu
- form = None
-
- if request.method == 'POST':
- form = IkiwikiForm(request.POST, prefix='ikiwiki')
- if form.is_valid():
- _apply_changes(request, status, form.cleaned_data)
- status = get_status()
- form = IkiwikiForm(initial=status, prefix='ikiwiki')
- else:
- form = IkiwikiForm(initial=status, prefix='ikiwiki')
-
- return TemplateResponse(request, 'ikiwiki.html',
- {'title': ikiwiki.title,
- 'description': ikiwiki.description,
- 'status': status,
- 'form': form,
- 'subsubmenu': subsubmenu})
-
-
-def get_status():
- """Get the current setting."""
- return {'enabled': ikiwiki.is_enabled()}
-
-
-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('ikiwiki', [sub_command])
- ikiwiki.service.notify_enabled(None, new_status['enabled'])
- modified = True
-
- if modified:
- messages.success(request, _('Configuration updated'))
- else:
- messages.info(request, _('Setting unchanged'))
+ return super().get_context_data(**kwargs)
def manage(request):
diff --git a/plinth/modules/minetest/__init__.py b/plinth/modules/minetest/__init__.py
index cf386bcb8..a8f90b48b 100644
--- a/plinth/modules/minetest/__init__.py
+++ b/plinth/modules/minetest/__init__.py
@@ -21,6 +21,7 @@ Plinth module for minetest.
from django.utils.translation import ugettext_lazy as _
+from plinth import actions
from plinth import action_utils
from plinth import cfg
from plinth import service as service_module
@@ -61,6 +62,12 @@ def setup(helper, old_version=None):
helper.call('post', service.notify_enabled, None, True)
+def get_status():
+ """Get the current service status."""
+ return {'enabled': is_enabled(),
+ 'is_running': is_running()}
+
+
def is_enabled():
"""Return whether the service is enabled."""
return action_utils.service_is_enabled('minetest-server')
@@ -71,6 +78,13 @@ def is_running():
return action_utils.service_is_running('minetest-server')
+def enable(should_enable):
+ """Enable/disable the module."""
+ sub_command = 'enable' if should_enable else 'disable'
+ actions.superuser_run('minetest', [sub_command])
+ service.notify_enabled(None, should_enable)
+
+
def diagnose():
"""Run diagnostics and return the results."""
results = []
diff --git a/plinth/modules/minetest/forms.py b/plinth/modules/minetest/forms.py
deleted file mode 100644
index 87e1fbaa8..000000000
--- a/plinth/modules/minetest/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 the minetest module.
-"""
-
-from django import forms
-from django.utils.translation import ugettext_lazy as _
-
-
-class MinetestForm(forms.Form):
- """Minetest configuration form."""
- enabled = forms.BooleanField(
- label=_('Enable Minetest server'),
- required=False)
diff --git a/plinth/modules/minetest/urls.py b/plinth/modules/minetest/urls.py
index a297c4c6b..a32f5a7c5 100644
--- a/plinth/modules/minetest/urls.py
+++ b/plinth/modules/minetest/urls.py
@@ -21,9 +21,10 @@ URLs for the minetest module.
from django.conf.urls import url
-from . import views
+from plinth.views import ConfigurationView
urlpatterns = [
- url(r'^apps/minetest/$', views.index, name='index'),
+ url(r'^apps/minetest/$', ConfigurationView.as_view(module_name='minetest'),
+ name='index'),
]
diff --git a/plinth/modules/minetest/views.py b/plinth/modules/minetest/views.py
deleted file mode 100644
index 5d5f5a3d3..000000000
--- a/plinth/modules/minetest/views.py
+++ /dev/null
@@ -1,72 +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 .
-#
-
-"""
-Views for the minetest module.
-"""
-
-from django.contrib import messages
-from django.template.response import TemplateResponse
-from django.utils.translation import ugettext as _
-
-from .forms import MinetestForm
-from plinth import actions
-from plinth.modules import minetest
-
-
-def index(request):
- """Serve configuration page."""
- status = get_status()
-
- form = None
-
- if request.method == 'POST':
- form = MinetestForm(request.POST, prefix='minetest')
- if form.is_valid():
- _apply_changes(request, status, form.cleaned_data)
- status = get_status()
- form = MinetestForm(initial=status, prefix='minetest')
- else:
- form = MinetestForm(initial=status, prefix='minetest')
-
- return TemplateResponse(request, 'minetest.html',
- {'title': minetest.title,
- 'description': minetest.description,
- 'status': status,
- 'form': form})
-
-
-def get_status():
- """Get the current service status."""
- return {'enabled': minetest.is_enabled(),
- 'is_running': minetest.is_running()}
-
-
-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('minetest', [sub_command])
- minetest.service.notify_enabled(None, new_status['enabled'])
- modified = True
-
- if modified:
- messages.success(request, _('Configuration updated'))
- else:
- messages.info(request, _('Setting unchanged'))
diff --git a/plinth/modules/mumble/__init__.py b/plinth/modules/mumble/__init__.py
index b7f772494..a5ccd5902 100644
--- a/plinth/modules/mumble/__init__.py
+++ b/plinth/modules/mumble/__init__.py
@@ -21,6 +21,7 @@ Plinth module to configure Mumble server
from django.utils.translation import ugettext_lazy as _
+from plinth import actions
from plinth import action_utils
from plinth import cfg
from plinth import service as service_module
@@ -60,6 +61,12 @@ def setup(helper, old_version=None):
helper.call('post', service.notify_enabled, None, True)
+def get_status():
+ """Get the current settings from server."""
+ return {'enabled': is_enabled(),
+ 'is_running': is_running()}
+
+
def is_enabled():
"""Return whether the module is enabled."""
return action_utils.service_is_enabled('mumble-server')
@@ -70,6 +77,13 @@ def is_running():
return action_utils.service_is_running('mumble-server')
+def enable(should_enable):
+ """Enable/disable the module."""
+ sub_command = 'enable' if should_enable else 'disable'
+ actions.superuser_run('mumble', [sub_command])
+ service.notify_enabled(None, should_enable)
+
+
def diagnose():
"""Run diagnostics and return the results."""
results = []
diff --git a/plinth/modules/mumble/forms.py b/plinth/modules/mumble/forms.py
deleted file mode 100644
index 88568e19b..000000000
--- a/plinth/modules/mumble/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 Mumble
-"""
-
-from django import forms
-from django.utils.translation import ugettext_lazy as _
-
-
-class MumbleForm(forms.Form):
- """Mumble configuration form."""
- enabled = forms.BooleanField(
- label=_('Enable Mumble daemon'),
- required=False)
diff --git a/plinth/modules/mumble/urls.py b/plinth/modules/mumble/urls.py
index 87f27aa88..77aa97da5 100644
--- a/plinth/modules/mumble/urls.py
+++ b/plinth/modules/mumble/urls.py
@@ -21,9 +21,10 @@ URLs for the Mumble module
from django.conf.urls import url
-from . import views
+from plinth.views import ConfigurationView
urlpatterns = [
- url(r'^apps/mumble/$', views.index, name='index'),
+ url(r'^apps/mumble/$', ConfigurationView.as_view(module_name='mumble'),
+ name='index'),
]
diff --git a/plinth/modules/mumble/views.py b/plinth/modules/mumble/views.py
deleted file mode 100644
index 4d67f6458..000000000
--- a/plinth/modules/mumble/views.py
+++ /dev/null
@@ -1,76 +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 for configuring Mumble Server
-"""
-
-from django.contrib import messages
-from django.template.response import TemplateResponse
-from django.utils.translation import ugettext as _
-import logging
-
-from .forms import MumbleForm
-from plinth import actions
-from plinth.modules import mumble
-
-logger = logging.getLogger(__name__)
-
-
-def index(request):
- """Serve configuration page."""
- status = get_status()
-
- form = None
-
- if request.method == 'POST':
- form = MumbleForm(request.POST, prefix='mumble')
- # pylint: disable=E1101
- if form.is_valid():
- _apply_changes(request, status, form.cleaned_data)
- status = get_status()
- form = MumbleForm(initial=status, prefix='mumble')
- else:
- form = MumbleForm(initial=status, prefix='mumble')
-
- return TemplateResponse(request, 'mumble.html',
- {'title': mumble.title,
- 'description': mumble.description,
- 'status': status,
- 'form': form})
-
-
-def get_status():
- """Get the current settings from server."""
- return {'enabled': mumble.is_enabled(),
- 'is_running': mumble.is_running()}
-
-
-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('mumble', [sub_command])
- mumble.service.notify_enabled(None, new_status['enabled'])
- modified = True
-
- if modified:
- messages.success(request, _('Configuration updated'))
- else:
- messages.info(request, _('Setting unchanged'))
diff --git a/plinth/modules/openvpn/views.py b/plinth/modules/openvpn/views.py
index ea1c6aefa..ea460589c 100644
--- a/plinth/modules/openvpn/views.py
+++ b/plinth/modules/openvpn/views.py
@@ -116,7 +116,7 @@ def _collect_setup_result(request):
return_code = setup_process.poll()
# Setup process is not complete yet
- if return_code == None:
+ if return_code is None:
return
if not return_code:
diff --git a/plinth/modules/owncloud/__init__.py b/plinth/modules/owncloud/__init__.py
index c5fbdd59a..c5a77b3f4 100644
--- a/plinth/modules/owncloud/__init__.py
+++ b/plinth/modules/owncloud/__init__.py
@@ -69,12 +69,27 @@ def setup(helper, old_version=None):
helper.call('post', service.notify_enabled, None, True)
+def get_status():
+ """Return the current status"""
+ return {'enabled': is_enabled()}
+
+
def is_enabled():
"""Return whether the module is enabled."""
output = actions.run('owncloud-setup', ['status'])
return 'enable' in output.split()
+def enable(should_enable):
+ """Enable/disable the module."""
+ option = 'enable' if should_enable else 'noenable'
+ actions.superuser_run('owncloud-setup', [option])
+
+ # Send a signal to other modules that the service is
+ # enabled/disabled
+ service.notify_enabled(None, should_enable)
+
+
def diagnose():
"""Run diagnostics and return the results."""
results = []
diff --git a/plinth/modules/owncloud/urls.py b/plinth/modules/owncloud/urls.py
index 338ad6cc5..7f215357b 100644
--- a/plinth/modules/owncloud/urls.py
+++ b/plinth/modules/owncloud/urls.py
@@ -21,9 +21,10 @@ URLs for the ownCloud module
from django.conf.urls import url
-from . import views
+from plinth.views import ConfigurationView
urlpatterns = [
- url(r'^apps/owncloud/$', views.index, name='index'),
+ url(r'^apps/owncloud/$', ConfigurationView.as_view(module_name='owncloud'),
+ name='index'),
]
diff --git a/plinth/modules/owncloud/views.py b/plinth/modules/owncloud/views.py
deleted file mode 100644
index b2e77077b..000000000
--- a/plinth/modules/owncloud/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 for configuring ownCloud.
-"""
-
-from django.contrib import messages
-from django.template.response import TemplateResponse
-from django.utils.translation import ugettext_lazy as _
-
-from .forms import OwnCloudForm
-from plinth import actions
-from plinth.modules import owncloud
-
-
-def index(request):
- """Serve the ownCloud configuration page"""
- status = get_status()
-
- form = None
-
- if request.method == 'POST':
- form = OwnCloudForm(request.POST, prefix='owncloud')
- # pylint: disable-msg=E1101
- if form.is_valid():
- _apply_changes(request, status, form.cleaned_data)
- status = get_status()
- form = OwnCloudForm(initial=status, prefix='owncloud')
- else:
- form = OwnCloudForm(initial=status, prefix='owncloud')
-
- return TemplateResponse(request, 'owncloud.html',
- {'title': owncloud.title,
- 'description': owncloud.description,
- 'form': form})
-
-
-def get_status():
- """Return the current status"""
- return {'enabled': owncloud.is_enabled()}
-
-
-def _apply_changes(request, old_status, new_status):
- """Apply the changes"""
- if old_status['enabled'] == new_status['enabled']:
- messages.info(request, _('Setting unchanged'))
- return
-
- if new_status['enabled']:
- messages.success(request, _('ownCloud enabled'))
- option = 'enable'
- else:
- messages.success(request, _('ownCloud disabled'))
- option = 'noenable'
-
- actions.superuser_run('owncloud-setup', [option])
-
- # Send a signal to other modules that the service is
- # enabled/disabled
- owncloud.service.notify_enabled(None, new_status['enabled'])
diff --git a/plinth/modules/privoxy/__init__.py b/plinth/modules/privoxy/__init__.py
index eaf0d20d1..4416d8f53 100644
--- a/plinth/modules/privoxy/__init__.py
+++ b/plinth/modules/privoxy/__init__.py
@@ -71,6 +71,12 @@ def setup(helper, old_version=None):
helper.call('post', service.notify_enabled, None, True)
+def get_status():
+ """Get the current settings from server."""
+ return {'enabled': is_enabled(),
+ 'is_running': is_running()}
+
+
def is_enabled():
"""Return whether the module is enabled."""
return action_utils.service_is_enabled('privoxy')
@@ -81,6 +87,13 @@ def is_running():
return action_utils.service_is_running('privoxy')
+def enable(should_enable):
+ """Enable/disable the module."""
+ sub_command = 'enable' if should_enable else 'disable'
+ actions.superuser_run('privoxy', [sub_command])
+ service.notify_enabled(None, should_enable)
+
+
def diagnose():
"""Run diagnostics and return the results."""
results = []
diff --git a/plinth/modules/privoxy/forms.py b/plinth/modules/privoxy/forms.py
deleted file mode 100644
index e22b99d27..000000000
--- a/plinth/modules/privoxy/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 Privoxy.
-"""
-
-from django import forms
-from django.utils.translation import ugettext_lazy as _
-
-
-class PrivoxyForm(forms.Form):
- """Privoxy configuration form."""
- enabled = forms.BooleanField(
- label=_('Enable Privoxy'),
- required=False)
diff --git a/plinth/modules/privoxy/urls.py b/plinth/modules/privoxy/urls.py
index 3ca303381..a4a60ca39 100644
--- a/plinth/modules/privoxy/urls.py
+++ b/plinth/modules/privoxy/urls.py
@@ -21,9 +21,10 @@ URLs for the Privoxy module.
from django.conf.urls import url
-from . import views
+from plinth.views import ConfigurationView
urlpatterns = [
- url(r'^apps/privoxy/$', views.index, name='index'),
+ url(r'^apps/privoxy/$', ConfigurationView.as_view(module_name='privoxy'),
+ name='index'),
]
diff --git a/plinth/modules/privoxy/views.py b/plinth/modules/privoxy/views.py
deleted file mode 100644
index 853f8709f..000000000
--- a/plinth/modules/privoxy/views.py
+++ /dev/null
@@ -1,78 +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 for configuring Privoxy Server.
-"""
-
-from django.contrib import messages
-from django.template.response import TemplateResponse
-from django.utils.translation import ugettext as _
-import logging
-
-from .forms import PrivoxyForm
-from plinth import actions
-from plinth.modules import privoxy
-
-logger = logging.getLogger(__name__)
-
-
-def index(request):
- """Serve configuration page."""
- status = get_status()
-
- form = None
-
- if request.method == 'POST':
- form = PrivoxyForm(request.POST, prefix='privoxy')
- # pylint: disable=E1101
- if form.is_valid():
- _apply_changes(request, status, form.cleaned_data)
- status = get_status()
- form = PrivoxyForm(initial=status, prefix='privoxy')
- else:
- form = PrivoxyForm(initial=status, prefix='privoxy')
-
- return TemplateResponse(request, 'privoxy.html',
- {'title': privoxy.title,
- 'description': privoxy.description,
- 'status': status,
- 'form': form})
-
-
-def get_status():
- """Get the current settings from server."""
- status = {'enabled': privoxy.is_enabled(),
- 'is_running': privoxy.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('privoxy', [sub_command])
- privoxy.service.notify_enabled(None, new_status['enabled'])
- modified = True
-
- if modified:
- messages.success(request, _('Configuration updated'))
- else:
- messages.info(request, _('Setting unchanged'))
diff --git a/plinth/modules/quassel/__init__.py b/plinth/modules/quassel/__init__.py
index c30f0abcc..b2a4bdb37 100644
--- a/plinth/modules/quassel/__init__.py
+++ b/plinth/modules/quassel/__init__.py
@@ -21,6 +21,7 @@ Plinth module for Quassel.
from django.utils.translation import ugettext_lazy as _
+from plinth import actions
from plinth import action_utils
from plinth import cfg
from plinth import service as service_module
@@ -68,6 +69,12 @@ def setup(helper, old_version=None):
helper.call('post', service.notify_enabled, None, True)
+def get_status():
+ """Get the current service status."""
+ return {'enabled': is_enabled(),
+ 'is_running': is_running()}
+
+
def is_enabled():
"""Return whether the service is enabled."""
return action_utils.service_is_enabled('quasselcore')
@@ -78,6 +85,13 @@ def is_running():
return action_utils.service_is_running('quasselcore')
+def enable(should_enable):
+ """Enable/disable the module."""
+ sub_command = 'enable' if should_enable else 'disable'
+ actions.superuser_run('quassel', [sub_command])
+ service.notify_enabled(None, should_enable)
+
+
def diagnose():
"""Run diagnostics and return the results."""
results = []
diff --git a/plinth/modules/quassel/forms.py b/plinth/modules/quassel/forms.py
deleted file mode 100644
index c8da8c883..000000000
--- a/plinth/modules/quassel/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 Quassel module.
-"""
-
-from django import forms
-from django.utils.translation import ugettext_lazy as _
-
-
-class QuasselForm(forms.Form):
- """Quassel configuration form."""
- enabled = forms.BooleanField(
- label=_('Enable Quassel core service'),
- required=False)
diff --git a/plinth/modules/quassel/urls.py b/plinth/modules/quassel/urls.py
index 5018ac2f8..3fef76f7f 100644
--- a/plinth/modules/quassel/urls.py
+++ b/plinth/modules/quassel/urls.py
@@ -21,9 +21,10 @@ URLs for the quassel module.
from django.conf.urls import url
-from . import views
+from plinth.views import ConfigurationView
urlpatterns = [
- url(r'^apps/quassel/$', views.index, name='index'),
+ url(r'^apps/quassel/$', ConfigurationView.as_view(module_name='quassel'),
+ name='index'),
]
diff --git a/plinth/modules/quassel/views.py b/plinth/modules/quassel/views.py
deleted file mode 100644
index 2adee5260..000000000
--- a/plinth/modules/quassel/views.py
+++ /dev/null
@@ -1,72 +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 .
-#
-
-"""
-Views for Quassel module.
-"""
-
-from django.contrib import messages
-from django.template.response import TemplateResponse
-from django.utils.translation import ugettext as _
-
-from .forms import QuasselForm
-from plinth import actions
-from plinth.modules import quassel
-
-
-def index(request):
- """Serve configuration page."""
- status = get_status()
-
- form = None
-
- if request.method == 'POST':
- form = QuasselForm(request.POST, prefix='quassel')
- if form.is_valid():
- _apply_changes(request, status, form.cleaned_data)
- status = get_status()
- form = QuasselForm(initial=status, prefix='quassel')
- else:
- form = QuasselForm(initial=status, prefix='quassel')
-
- return TemplateResponse(request, 'quassel.html',
- {'title': quassel.title,
- 'description': quassel.description,
- 'status': status,
- 'form': form})
-
-
-def get_status():
- """Get the current service status."""
- return {'enabled': quassel.is_enabled(),
- 'is_running': quassel.is_running()}
-
-
-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('quassel', [sub_command])
- quassel.service.notify_enabled(None, new_status['enabled'])
- modified = True
-
- if modified:
- messages.success(request, _('Configuration updated'))
- else:
- messages.info(request, _('Setting unchanged'))
diff --git a/plinth/modules/radicale/__init__.py b/plinth/modules/radicale/__init__.py
index 026aa18ee..b421ce174 100644
--- a/plinth/modules/radicale/__init__.py
+++ b/plinth/modules/radicale/__init__.py
@@ -65,6 +65,12 @@ def setup(helper, old_version=None):
helper.call('post', service.notify_enabled, None, True)
+def get_status():
+ """Get the current service status."""
+ return {'enabled': is_enabled(),
+ 'is_running': is_running()}
+
+
def is_enabled():
"""Return whether the service is enabled."""
return action_utils.service_is_enabled('radicale')
@@ -75,6 +81,13 @@ def is_running():
return action_utils.service_is_running('radicale')
+def enable(should_enable):
+ """Enable/disable the module."""
+ sub_command = 'enable' if should_enable else 'disable'
+ actions.superuser_run('radicale', [sub_command])
+ service.notify_enabled(None, should_enable)
+
+
def diagnose():
"""Run diagnostics and return the results."""
results = []
diff --git a/plinth/modules/radicale/forms.py b/plinth/modules/radicale/forms.py
deleted file mode 100644
index 7ecbeae83..000000000
--- a/plinth/modules/radicale/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 radicale module.
-"""
-
-from django import forms
-from django.utils.translation import ugettext_lazy as _
-
-
-class RadicaleForm(forms.Form):
- """Radicale configuration form."""
- enabled = forms.BooleanField(
- label=_('Enable Radicale service'),
- required=False)
diff --git a/plinth/modules/radicale/urls.py b/plinth/modules/radicale/urls.py
index ae7c20084..55f492662 100644
--- a/plinth/modules/radicale/urls.py
+++ b/plinth/modules/radicale/urls.py
@@ -21,9 +21,10 @@ URLs for the radicale module.
from django.conf.urls import url
-from . import views
+from plinth.views import ConfigurationView
urlpatterns = [
- url(r'^apps/radicale/$', views.index, name='index'),
+ url(r'^apps/radicale/$', ConfigurationView.as_view(module_name='radicale'),
+ name='index'),
]
diff --git a/plinth/modules/radicale/views.py b/plinth/modules/radicale/views.py
deleted file mode 100644
index f0d37cc6d..000000000
--- a/plinth/modules/radicale/views.py
+++ /dev/null
@@ -1,72 +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 .
-#
-
-"""
-Views for radicale module.
-"""
-
-from django.contrib import messages
-from django.template.response import TemplateResponse
-from django.utils.translation import ugettext as _
-
-from .forms import RadicaleForm
-from plinth import actions
-from plinth.modules import radicale
-
-
-def index(request):
- """Serve configuration page."""
- status = get_status()
-
- form = None
-
- if request.method == 'POST':
- form = RadicaleForm(request.POST, prefix='radicale')
- if form.is_valid():
- _apply_changes(request, status, form.cleaned_data)
- status = get_status()
- form = RadicaleForm(initial=status, prefix='radicale')
- else:
- form = RadicaleForm(initial=status, prefix='radicale')
-
- return TemplateResponse(request, 'radicale.html',
- {'title': radicale.title,
- 'description': radicale.description,
- 'status': status,
- 'form': form})
-
-
-def get_status():
- """Get the current service status."""
- return {'enabled': radicale.is_enabled(),
- 'is_running': radicale.is_running()}
-
-
-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('radicale', [sub_command])
- radicale.service.notify_enabled(None, new_status['enabled'])
- modified = True
-
- if modified:
- messages.success(request, _('Configuration updated'))
- else:
- messages.info(request, _('Setting unchanged'))
diff --git a/plinth/modules/repro/__init__.py b/plinth/modules/repro/__init__.py
index 0a72adcf8..586923be8 100644
--- a/plinth/modules/repro/__init__.py
+++ b/plinth/modules/repro/__init__.py
@@ -74,6 +74,12 @@ def setup(helper, old_version=None):
helper.call('post', service.notify_enabled, None, True)
+def get_status():
+ """Get the current service status."""
+ return {'enabled': is_enabled(),
+ 'is_running': is_running()}
+
+
def is_enabled():
"""Return whether the service is enabled."""
return action_utils.service_is_enabled('repro')
@@ -84,6 +90,13 @@ def is_running():
return action_utils.service_is_running('repro')
+def enable(should_enable):
+ """Enable/disable the module."""
+ sub_command = 'enable' if should_enable else 'disable'
+ actions.superuser_run('repro', [sub_command])
+ service.notify_enabled(None, should_enable)
+
+
def diagnose():
"""Run diagnostics and return the results."""
results = []
diff --git a/plinth/modules/repro/forms.py b/plinth/modules/repro/forms.py
deleted file mode 100644
index b584701cd..000000000
--- a/plinth/modules/repro/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 repro module.
-"""
-
-from django import forms
-from django.utils.translation import ugettext_lazy as _
-
-
-class ReproForm(forms.Form):
- """Configuration form."""
- enabled = forms.BooleanField(
- label=_('Enable repro service'),
- required=False)
diff --git a/plinth/modules/repro/urls.py b/plinth/modules/repro/urls.py
index d87f8136b..aeff7f51a 100644
--- a/plinth/modules/repro/urls.py
+++ b/plinth/modules/repro/urls.py
@@ -21,9 +21,10 @@ URLs for the repro module.
from django.conf.urls import url
-from . import views
+from plinth.views import ConfigurationView
urlpatterns = [
- url(r'^apps/repro/$', views.index, name='index'),
+ url(r'^apps/repro/$', ConfigurationView.as_view(module_name='repro'),
+ name='index'),
]
diff --git a/plinth/modules/repro/views.py b/plinth/modules/repro/views.py
deleted file mode 100644
index 407a96b0c..000000000
--- a/plinth/modules/repro/views.py
+++ /dev/null
@@ -1,72 +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 .
-#
-
-"""
-Views for repro module.
-"""
-
-from django.contrib import messages
-from django.template.response import TemplateResponse
-from django.utils.translation import ugettext as _
-
-from .forms import ReproForm
-from plinth import actions
-from plinth.modules import repro
-
-
-def index(request):
- """Serve configuration page."""
- status = get_status()
-
- form = None
-
- if request.method == 'POST':
- form = ReproForm(request.POST, prefix='repro')
- if form.is_valid():
- _apply_changes(request, status, form.cleaned_data)
- status = get_status()
- form = ReproForm(initial=status, prefix='repro')
- else:
- form = ReproForm(initial=status, prefix='repro')
-
- return TemplateResponse(request, 'repro.html',
- {'title': repro.title,
- 'description': repro.description,
- 'status': status,
- 'form': form})
-
-
-def get_status():
- """Get the current service status."""
- return {'enabled': repro.is_enabled(),
- 'is_running': repro.is_running()}
-
-
-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('repro', [sub_command])
- repro.service.notify_enabled(None, new_status['enabled'])
- modified = True
-
- if modified:
- messages.success(request, _('Configuration updated'))
- else:
- messages.info(request, _('Setting unchanged'))
diff --git a/plinth/modules/restore/__init__.py b/plinth/modules/restore/__init__.py
index dff18b3d4..532cabd0a 100644
--- a/plinth/modules/restore/__init__.py
+++ b/plinth/modules/restore/__init__.py
@@ -20,11 +20,12 @@ Plinth module to configure reStore.
"""
from django.utils.translation import ugettext_lazy as _
+
+from plinth import actions
from plinth import action_utils, cfg
from plinth import service as service_module
from plinth.utils import format_lazy
-service = None
version = 1
@@ -45,6 +46,8 @@ description = [
'reStore web-interface.')
]
+service = None
+
def init():
"""Initialize the reStore module."""
@@ -62,6 +65,18 @@ def setup(helper, old_version=None):
helper.install(['node-restore'])
+def get_status():
+ """Get the current settings."""
+ return {'enabled': is_enabled()}
+
+
def is_enabled():
"""Return whether the module is enabled."""
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)
diff --git a/plinth/modules/restore/forms.py b/plinth/modules/restore/forms.py
deleted file mode 100644
index 4c8c2bf90..000000000
--- a/plinth/modules/restore/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 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)
diff --git a/plinth/modules/restore/templates/restore_index.html b/plinth/modules/restore/templates/restore.html
similarity index 100%
rename from plinth/modules/restore/templates/restore_index.html
rename to plinth/modules/restore/templates/restore.html
diff --git a/plinth/modules/restore/urls.py b/plinth/modules/restore/urls.py
index 69cec1a51..c51116f8f 100644
--- a/plinth/modules/restore/urls.py
+++ b/plinth/modules/restore/urls.py
@@ -21,9 +21,10 @@ URLs for the reStore module.
from django.conf.urls import url
-from . import views
+from plinth.views import ConfigurationView
urlpatterns = [
- url(r'^apps/restore/$', views.index, name='index'),
+ url(r'^apps/restore/$', ConfigurationView.as_view(module_name='restore'),
+ name='index'),
]
diff --git a/plinth/modules/restore/views.py b/plinth/modules/restore/views.py
deleted file mode 100644
index 0e91904a4..000000000
--- a/plinth/modules/restore/views.py
+++ /dev/null
@@ -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 .
-#
-
-"""
-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'))
diff --git a/plinth/modules/roundcube/__init__.py b/plinth/modules/roundcube/__init__.py
index 1c11596af..a67364707 100644
--- a/plinth/modules/roundcube/__init__.py
+++ b/plinth/modules/roundcube/__init__.py
@@ -68,11 +68,22 @@ def setup(helper, old_version=None):
helper.call('pre', actions.superuser_run, 'roundcube', ['setup'])
+def get_status():
+ """Get the current status."""
+ return {'enabled': is_enabled()}
+
+
def is_enabled():
"""Return whether the module is enabled."""
return action_utils.webserver_is_enabled('roundcube')
+def enable(should_enable):
+ """Enable/disable the module."""
+ sub_command = 'enable' if should_enable else 'disable'
+ actions.superuser_run('roundcube', [sub_command])
+
+
def diagnose():
"""Run diagnostics and return the results."""
results = []
diff --git a/plinth/modules/roundcube/forms.py b/plinth/modules/roundcube/forms.py
deleted file mode 100644
index ef0014a6c..000000000
--- a/plinth/modules/roundcube/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 Roundcube.
-"""
-
-from django import forms
-from django.utils.translation import ugettext_lazy as _
-
-
-class RoundcubeForm(forms.Form):
- """Roundcube configuration form."""
- enabled = forms.BooleanField(
- label=_('Enable Roundcube'),
- required=False)
diff --git a/plinth/modules/roundcube/urls.py b/plinth/modules/roundcube/urls.py
index 66be5df69..a307cce07 100644
--- a/plinth/modules/roundcube/urls.py
+++ b/plinth/modules/roundcube/urls.py
@@ -21,9 +21,10 @@ URLs for the Roundcube module.
from django.conf.urls import url
-from . import views
+from plinth.views import ConfigurationView
urlpatterns = [
- url(r'^apps/roundcube/$', views.index, name='index'),
+ url(r'^apps/roundcube/$',
+ ConfigurationView.as_view(module_name='roundcube'), name='index'),
]
diff --git a/plinth/modules/roundcube/views.py b/plinth/modules/roundcube/views.py
deleted file mode 100644
index 610fdb8c0..000000000
--- a/plinth/modules/roundcube/views.py
+++ /dev/null
@@ -1,74 +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 for configuring Roundcube.
-"""
-
-from django.contrib import messages
-from django.template.response import TemplateResponse
-from django.utils.translation import ugettext as _
-import logging
-
-from .forms import RoundcubeForm
-from plinth import actions
-from plinth.modules import roundcube
-
-logger = logging.getLogger(__name__)
-
-
-def index(request):
- """Serve configuration page."""
- status = get_status()
-
- form = None
-
- if request.method == 'POST':
- form = RoundcubeForm(request.POST, prefix='roundcube')
- # pylint: disable=E1101
- if form.is_valid():
- _apply_changes(request, status, form.cleaned_data)
- status = get_status()
- form = RoundcubeForm(initial=status, prefix='roundcube')
- else:
- form = RoundcubeForm(initial=status, prefix='roundcube')
-
- return TemplateResponse(request, 'roundcube.html',
- {'title': roundcube.title,
- 'description': roundcube.description,
- 'status': status,
- 'form': form})
-
-
-def get_status():
- """Get the current status."""
- return {'enabled': roundcube.is_enabled()}
-
-
-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('roundcube', [sub_command])
- modified = True
-
- if modified:
- messages.success(request, _('Configuration updated'))
- else:
- messages.info(request, _('Setting unchanged'))
diff --git a/plinth/modules/shaarli/__init__.py b/plinth/modules/shaarli/__init__.py
index 2210da998..bbb35cc1e 100644
--- a/plinth/modules/shaarli/__init__.py
+++ b/plinth/modules/shaarli/__init__.py
@@ -21,6 +21,7 @@ Plinth module to configure Shaarli.
from django.utils.translation import ugettext_lazy as _
+from plinth import actions
from plinth import action_utils
from plinth import cfg
from plinth import service as service_module
@@ -61,6 +62,18 @@ 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()}
+
+
def is_enabled():
"""Return whether the module is enabled."""
return action_utils.webserver_is_enabled('shaarli')
+
+
+def enable(should_enable):
+ """Enable/disable the module."""
+ sub_command = 'enable' if should_enable else 'disable'
+ actions.superuser_run('shaarli', [sub_command])
+ service.notify_enabled(None, should_enable)
diff --git a/plinth/modules/shaarli/forms.py b/plinth/modules/shaarli/forms.py
deleted file mode 100644
index 01c571adb..000000000
--- a/plinth/modules/shaarli/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 Shaarli.
-"""
-
-from django import forms
-from django.utils.translation import ugettext_lazy as _
-
-
-class ShaarliForm(forms.Form):
- """Shaarli configuration form."""
- enabled = forms.BooleanField(
- label=_('Enable Shaarli'),
- required=False)
diff --git a/plinth/modules/shaarli/urls.py b/plinth/modules/shaarli/urls.py
index 2784905eb..b75250a3d 100644
--- a/plinth/modules/shaarli/urls.py
+++ b/plinth/modules/shaarli/urls.py
@@ -21,9 +21,10 @@ URLs for the Shaarli module.
from django.conf.urls import url
-from . import views
+from plinth.views import ConfigurationView
urlpatterns = [
- url(r'^apps/shaarli/$', views.index, name='index'),
+ url(r'^apps/shaarli/$', ConfigurationView.as_view(module_name='shaarli'),
+ name='index'),
]
diff --git a/plinth/modules/shaarli/views.py b/plinth/modules/shaarli/views.py
deleted file mode 100644
index de174faa7..000000000
--- a/plinth/modules/shaarli/views.py
+++ /dev/null
@@ -1,72 +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 Shaarli.
-"""
-
-from django.contrib import messages
-from django.template.response import TemplateResponse
-from django.utils.translation import ugettext as _
-
-from .forms import ShaarliForm
-from plinth import actions
-from plinth.modules import shaarli
-
-
-def index(request):
- """Serve configuration page."""
- status = get_status()
-
- form = None
-
- if request.method == 'POST':
- form = ShaarliForm(request.POST, prefix='shaarli')
- if form.is_valid():
- _apply_changes(request, status, form.cleaned_data)
- status = get_status()
- form = ShaarliForm(initial=status, prefix='shaarli')
- else:
- form = ShaarliForm(initial=status, prefix='shaarli')
-
- return TemplateResponse(request, 'shaarli.html',
- {'title': shaarli.title,
- 'description': shaarli.description,
- 'status': status,
- 'form': form})
-
-
-def get_status():
- """Get the current settings."""
- status = {'enabled': shaarli.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('shaarli', [sub_command])
- shaarli.service.notify_enabled(None, new_status['enabled'])
- modified = True
-
- if modified:
- messages.success(request, _('Configuration updated'))
- else:
- messages.info(request, _('Setting unchanged'))
diff --git a/plinth/modules/tor/views.py b/plinth/modules/tor/views.py
index 58e513a1f..d041c7155 100644
--- a/plinth/modules/tor/views.py
+++ b/plinth/modules/tor/views.py
@@ -108,7 +108,7 @@ def _collect_config_result(request):
return_code = config_process.poll()
# Config process is not complete yet
- if return_code == None:
+ if return_code is None:
return
status = tor.get_status()
diff --git a/plinth/modules/transmission/__init__.py b/plinth/modules/transmission/__init__.py
index aed1380ed..c11c2821e 100644
--- a/plinth/modules/transmission/__init__.py
+++ b/plinth/modules/transmission/__init__.py
@@ -21,6 +21,7 @@ Plinth module to configure Transmission server
from django.utils.translation import ugettext_lazy as _
import json
+import socket
from plinth import actions
from plinth import action_utils
@@ -42,6 +43,8 @@ description = [
service = None
+TRANSMISSION_CONFIG = '/etc/transmission-daemon/settings.json'
+
def init():
"""Intialize the Transmission module."""
@@ -67,6 +70,19 @@ def setup(helper, old_version=None):
helper.call('post', service.notify_enabled, None, True)
+def get_status():
+ """Get the current settings from Transmission server."""
+ configuration = open(TRANSMISSION_CONFIG, 'r').read()
+ status = json.loads(configuration)
+ status = {key.translate(str.maketrans({'-': '_'})): value
+ for key, value in status.items()}
+ status['enabled'] = is_enabled()
+ status['is_running'] = is_running()
+ status['hostname'] = socket.gethostname()
+
+ return status
+
+
def is_enabled():
"""Return whether the module is enabled."""
return (action_utils.service_is_enabled('transmission-daemon') and
@@ -78,6 +94,13 @@ def is_running():
return action_utils.service_is_running('transmission-daemon')
+def enable(should_enable):
+ """Enable/disable the module."""
+ sub_command = 'enable' if should_enable else 'disable'
+ actions.superuser_run('transmission', [sub_command])
+ service.notify_enabled(None, should_enable)
+
+
def diagnose():
"""Run diagnostics and return the results."""
results = []
diff --git a/plinth/modules/transmission/forms.py b/plinth/modules/transmission/forms.py
index 0960e8342..6eaa42928 100644
--- a/plinth/modules/transmission/forms.py
+++ b/plinth/modules/transmission/forms.py
@@ -22,13 +22,11 @@ Plinth module for configuring Transmission.
from django import forms
from django.utils.translation import ugettext_lazy as _
+from plinth.forms import ConfigurationForm
-class TransmissionForm(forms.Form): # pylint: disable=W0232
+
+class TransmissionForm(ConfigurationForm): # pylint: disable=W0232
"""Transmission configuration form"""
- enabled = forms.BooleanField(
- label=_('Enable Transmission daemon'),
- required=False)
-
download_dir = forms.CharField(
label=_('Download directory'),
help_text=_('Directory where downloads are saved. If you change the \
diff --git a/plinth/modules/transmission/urls.py b/plinth/modules/transmission/urls.py
index e3ff718f3..3ab28942f 100644
--- a/plinth/modules/transmission/urls.py
+++ b/plinth/modules/transmission/urls.py
@@ -21,9 +21,10 @@ URLs for the Transmission module.
from django.conf.urls import url
-from . import views
+from .views import ConfigurationView
urlpatterns = [
- url(r'^apps/transmission/$', views.index, name='index'),
+ url(r'^apps/transmission/$',
+ ConfigurationView.as_view(module_name='transmission'), name='index'),
]
diff --git a/plinth/modules/transmission/views.py b/plinth/modules/transmission/views.py
index c65c81013..72e520b91 100644
--- a/plinth/modules/transmission/views.py
+++ b/plinth/modules/transmission/views.py
@@ -20,81 +20,37 @@ Plinth module for configuring Transmission Server
"""
from django.contrib import messages
-from django.template.response import TemplateResponse
from django.utils.translation import ugettext as _
import json
import logging
-import socket
from .forms import TransmissionForm
from plinth import actions
-from plinth.modules import transmission
+from plinth import views
logger = logging.getLogger(__name__)
-TRANSMISSION_CONFIG = '/etc/transmission-daemon/settings.json'
-
-def index(request):
+class ConfigurationView(views.ConfigurationView):
"""Serve configuration page."""
- status = get_status()
+ form_class = TransmissionForm
- form = None
+ def apply_changes(self, old_status, new_status):
+ """Apply the changes submitted in the form."""
+ modified = super().apply_changes(old_status, new_status)
- if request.method == 'POST':
- form = TransmissionForm(request.POST, prefix='transmission')
- # pylint: disable=E1101
- if form.is_valid():
- _apply_changes(request, status, form.cleaned_data)
- status = get_status()
- form = TransmissionForm(initial=status, prefix='transmission')
- else:
- form = TransmissionForm(initial=status, prefix='transmission')
+ if old_status['download_dir'] != new_status['download_dir'] or \
+ old_status['rpc_username'] != new_status['rpc_username'] or \
+ old_status['rpc_password'] != new_status['rpc_password']:
+ new_configuration = {
+ 'download-dir': new_status['download_dir'],
+ 'rpc-username': new_status['rpc_username'],
+ 'rpc-password': new_status['rpc_password'],
+ }
- return TemplateResponse(request, 'transmission.html',
- {'title': transmission.title,
- 'description': transmission.description,
- 'status': status,
- 'form': form})
+ actions.superuser_run('transmission', ['merge-configuration'],
+ input=json.dumps(new_configuration).encode())
+ messages.success(self.request, _('Configuration updated'))
+ return True
-
-def get_status():
- """Get the current settings from Transmission server."""
- configuration = open(TRANSMISSION_CONFIG, 'r').read()
- status = json.loads(configuration)
- status = {key.translate(str.maketrans({'-': '_'})): value
- for key, value in status.items()}
- status['enabled'] = transmission.is_enabled()
- status['is_running'] = transmission.is_running()
- status['hostname'] = socket.gethostname()
-
- 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('transmission', [sub_command])
- transmission.service.notify_enabled(None, new_status['enabled'])
- modified = True
-
- if old_status['download_dir'] != new_status['download_dir'] or \
- old_status['rpc_username'] != new_status['rpc_username'] or \
- old_status['rpc_password'] != new_status['rpc_password']:
- new_configuration = {
- 'download-dir': new_status['download_dir'],
- 'rpc-username': new_status['rpc_username'],
- 'rpc-password': new_status['rpc_password'],
- }
-
- actions.superuser_run('transmission', ['merge-configuration'],
- input=json.dumps(new_configuration).encode())
- modified = True
-
- if modified:
- messages.success(request, _('Configuration updated'))
- else:
- messages.info(request, _('Setting unchanged'))
+ return modified
diff --git a/plinth/modules/upgrades/__init__.py b/plinth/modules/upgrades/__init__.py
index 1f58ad821..e8e84ac38 100644
--- a/plinth/modules/upgrades/__init__.py
+++ b/plinth/modules/upgrades/__init__.py
@@ -50,3 +50,20 @@ def setup(helper, old_version=None):
"""Install and configure the module."""
helper.install(['unattended-upgrades'])
helper.call('post', actions.superuser_run, 'upgrades', ['enable-auto'])
+
+
+def get_status():
+ """Return the current status."""
+ return {'auto_upgrades_enabled': 'is_enabled'}
+
+
+def is_enabled():
+ """Return whether the module is enabled."""
+ output = actions.run('upgrades', ['check-auto'])
+ return 'True' in output.split()
+
+
+def enable(should_enable):
+ """Enable/disable the module."""
+ option = 'enable-auto' if should_enable else 'disable-auto'
+ actions.superuser_run('upgrades', [option])
diff --git a/plinth/modules/upgrades/urls.py b/plinth/modules/upgrades/urls.py
index 9457c17dc..eba0e70b8 100644
--- a/plinth/modules/upgrades/urls.py
+++ b/plinth/modules/upgrades/urls.py
@@ -25,6 +25,7 @@ from . import views
urlpatterns = [
- url(r'^sys/upgrades/$', views.index, name='index'),
+ url(r'^sys/upgrades/$',
+ views.ConfigurationView.as_view(module_name='upgrades'), name='index'),
url(r'^sys/upgrades/upgrade/$', views.upgrade, name='upgrade'),
]
diff --git a/plinth/modules/upgrades/views.py b/plinth/modules/upgrades/views.py
index 81b0a4ba3..37b63bc82 100644
--- a/plinth/modules/upgrades/views.py
+++ b/plinth/modules/upgrades/views.py
@@ -27,6 +27,7 @@ import subprocess
from .forms import ConfigureForm
from plinth import actions
+from plinth import views
from plinth.errors import ActionError
from plinth.modules import upgrades
@@ -39,26 +40,43 @@ LOG_FILE = '/var/log/unattended-upgrades/unattended-upgrades.log'
LOCK_FILE = '/var/log/dpkg/lock'
-def index(request):
- """Serve the configuration form."""
- status = get_status()
+class ConfigurationView(views.ConfigurationView):
+ """Serve configuration page."""
+ form_class = ConfigureForm
- form = None
+ def get_context_data(self, **kwargs):
+ """Return the context data for rendering the template view."""
+ if 'subsubmenu' not in kwargs:
+ kwargs['subsubmenu'] = subsubmenu
- if request.method == 'POST':
- form = ConfigureForm(request.POST, prefix='upgrades')
- if form.is_valid():
- _apply_changes(request, status, form.cleaned_data)
- status = get_status()
- form = ConfigureForm(initial=status, prefix='upgrades')
- else:
- form = ConfigureForm(initial=status, prefix='upgrades')
+ return super().get_context_data(**kwargs)
- return TemplateResponse(request, 'upgrades_configure.html',
- {'title': upgrades.title,
- 'description': upgrades.description,
- 'form': form,
- 'subsubmenu': subsubmenu})
+ def get_template_names(self):
+ """Return the list of template names for the view."""
+ return ['upgrades_configure.html']
+
+ def apply_changes(self, old_status, new_status):
+ """Apply the form changes."""
+ if old_status['auto_upgrades_enabled'] \
+ == new_status['auto_upgrades_enabled']:
+ return False
+
+ try:
+ upgrades.enable(new_status['auto_upgrades_enabled'])
+ except ActionError as exception:
+ error = exception.args[2]
+ messages.error(
+ self.request,
+ _('Error when configuring unattended-upgrades: {error}')
+ .format(error=error))
+ return True
+
+ if new_status['auto_upgrades_enabled']:
+ messages.success(self.request, _('Automatic upgrades enabled'))
+ else:
+ messages.success(self.request, _('Automatic upgrades disabled'))
+
+ return True
def is_package_manager_busy():
@@ -97,36 +115,3 @@ def upgrade(request):
'subsubmenu': subsubmenu,
'is_busy': is_busy,
'log': get_log()})
-
-
-def get_status():
- """Return the current status."""
- output = actions.run('upgrades', ['check-auto'])
- return {'auto_upgrades_enabled': 'True' in output.split()}
-
-
-def _apply_changes(request, old_status, new_status):
- """Apply the form changes."""
- if old_status['auto_upgrades_enabled'] \
- == new_status['auto_upgrades_enabled']:
- messages.info(request, _('Setting unchanged'))
- return
-
- if new_status['auto_upgrades_enabled']:
- option = 'enable-auto'
- else:
- option = 'disable-auto'
-
- try:
- actions.superuser_run('upgrades', [option])
- except ActionError as exception:
- error = exception.args[2]
- messages.error(
- request, _('Error when configuring unattended-upgrades: {error}')
- .format(error=error))
- return
-
- if option == 'enable-auto':
- messages.success(request, _('Automatic upgrades enabled'))
- else:
- messages.success(request, _('Automatic upgrades disabled'))
diff --git a/plinth/modules/users/__init__.py b/plinth/modules/users/__init__.py
index b7c6c8ca1..62bb174bc 100644
--- a/plinth/modules/users/__init__.py
+++ b/plinth/modules/users/__init__.py
@@ -67,5 +67,3 @@ def _diagnose_ldap_entry(search_item):
return [_('Check LDAP entry "{search_item}"')
.format(search_item=search_item), result]
-
-
diff --git a/plinth/modules/xmpp/__init__.py b/plinth/modules/xmpp/__init__.py
index 1365f1d98..d823530bd 100644
--- a/plinth/modules/xmpp/__init__.py
+++ b/plinth/modules/xmpp/__init__.py
@@ -79,6 +79,13 @@ 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(),
+ 'domainname': get_domainname()}
+
+
def is_enabled():
"""Return whether the module is enabled."""
return (action_utils.service_is_enabled('ejabberd') and
@@ -96,6 +103,13 @@ def get_domainname():
return '.'.join(fqdn.split('.')[1:])
+def enable(should_enable):
+ """Enable/disable the module."""
+ sub_command = 'enable' if should_enable else 'disable'
+ actions.superuser_run('xmpp', [sub_command])
+ service.notify_enabled(None, should_enable)
+
+
def on_pre_hostname_change(sender, old_hostname, new_hostname, **kwargs):
"""
Backup ejabberd database before hostname is changed.
diff --git a/plinth/modules/xmpp/forms.py b/plinth/modules/xmpp/forms.py
deleted file mode 100644
index 3d9e5d61d..000000000
--- a/plinth/modules/xmpp/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 XMPP service.
-"""
-
-from django import forms
-from django.utils.translation import ugettext_lazy as _
-
-
-class XmppForm(forms.Form): # pylint: disable=W0232
- """XMPP configuration form."""
- enabled = forms.BooleanField(
- label=_('Enable XMPP'),
- required=False)
diff --git a/plinth/modules/xmpp/urls.py b/plinth/modules/xmpp/urls.py
index db022e9cf..36e86a7c3 100644
--- a/plinth/modules/xmpp/urls.py
+++ b/plinth/modules/xmpp/urls.py
@@ -21,8 +21,10 @@ URLs for the XMPP module
from django.conf.urls import url
-from . import views
+from plinth.views import ConfigurationView
+
urlpatterns = [
- url(r'^apps/xmpp/$', views.index, name='index'),
+ url(r'^apps/xmpp/$', ConfigurationView.as_view(module_name='xmpp'),
+ name='index'),
]
diff --git a/plinth/modules/xmpp/views.py b/plinth/modules/xmpp/views.py
deleted file mode 100644
index ca1841535..000000000
--- a/plinth/modules/xmpp/views.py
+++ /dev/null
@@ -1,79 +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 XMPP server
-"""
-
-from django.contrib import messages
-from django.template.response import TemplateResponse
-from django.utils.translation import ugettext as _
-import logging
-
-from .forms import XmppForm
-from plinth import actions
-from plinth.modules import xmpp
-
-
-logger = logging.getLogger(__name__)
-
-
-def index(request):
- """Serve configuration page"""
- status = get_status()
-
- form = None
-
- if request.method == 'POST':
- form = XmppForm(request.POST, prefix='xmpp')
- if form.is_valid():
- _apply_changes(request, status, form.cleaned_data)
- status = get_status()
- form = XmppForm(initial=status, prefix='xmpp')
- else:
- form = XmppForm(initial=status, prefix='xmpp')
-
- return TemplateResponse(request, 'xmpp.html',
- {'title': xmpp.title,
- 'description': xmpp.description,
- 'status': status,
- 'form': form})
-
-
-def get_status():
- """Get the current settings."""
- status = {'enabled': xmpp.is_enabled(),
- 'is_running': xmpp.is_running(),
- 'domainname': xmpp.get_domainname()}
-
- 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('xmpp', [sub_command])
- xmpp.service.notify_enabled(None, new_status['enabled'])
- modified = True
-
- if modified:
- messages.success(request, _('Configuration updated'))
- else:
- messages.info(request, _('Setting unchanged'))
diff --git a/plinth/views.py b/plinth/views.py
index a5b9a7680..669506d0c 100644
--- a/plinth/views.py
+++ b/plinth/views.py
@@ -19,17 +19,101 @@
Main Plinth views
"""
+from django.contrib import messages
+from django.core.exceptions import ImproperlyConfigured
from django.core.urlresolvers import reverse
from django.http.response import HttpResponseRedirect
from django.views.generic import TemplateView
+from django.views.generic.edit import FormView
+from django.utils.translation import ugettext as _
import time
+from . import forms
+import plinth
+
def index(request):
"""Serve the main index page."""
return HttpResponseRedirect(reverse('apps:index'))
+class ConfigurationView(FormView):
+ """A generic view for configuring simple modules."""
+ form_class = forms.ConfigurationForm
+ module_name = None
+
+ def __init__(self, module_name=None, *args, **kwargs):
+ """Set the module name on which this configuration view operates."""
+ self.instance_module_name = module_name
+
+ def get_module_name(self):
+ """Return the name of the module associated with the view."""
+ if not self.instance_module_name and not self.module_name:
+ raise ImproperlyConfigured(
+ 'Using ConfigurationView without the "module_name" class '
+ 'attribute or intialization attribute is prohibited.')
+ else:
+ return self.instance_module_name or self.module_name
+
+ def get_module(self):
+ """Return the module associated with the view."""
+ return plinth.module_loader.loaded_modules[self.get_module_name()]
+
+ def get_initial(self):
+ """Return the status of the module to fill in the form."""
+ return self.get_module().get_status()
+
+ def get_prefix(self):
+ """Return prefix for form used in the view."""
+ return self.get_module_name()
+
+ def get_template_names(self):
+ """Return the list of template names for the view."""
+ return [self.get_module_name() + '.html']
+
+ def get_context_data(self, **kwargs):
+ """Return the context data for rendering the template view."""
+ if 'title' not in kwargs:
+ kwargs['title'] = getattr(self.get_module(), 'title', None)
+
+ if 'description' not in kwargs:
+ kwargs['description'] = \
+ getattr(self.get_module(), 'description', None)
+
+ context = super().get_context_data(**kwargs)
+
+ if 'status' not in context:
+ context['status'] = context['form'].initial
+
+ return context
+
+ def form_valid(self, form):
+ """Perform operation when the form submission is valid."""
+ old_status = form.initial
+ new_status = form.cleaned_data
+
+ modified = self.apply_changes(old_status, new_status)
+ if not modified:
+ messages.info(self.request, _('Setting unchanged'))
+
+ context = self.get_context_data()
+ return self.render_to_response(context)
+
+ def apply_changes(self, old_status, new_status):
+ """Apply the changes submitted in the form."""
+ if old_status['enabled'] == new_status['enabled']:
+ return False
+
+ should_enable = new_status['enabled']
+ self.get_module().enable(should_enable)
+ if should_enable:
+ messages.success(self.request, _('Application enabled'))
+ else:
+ messages.success(self.request, _('Application disabled'))
+
+ return True
+
+
class SetupView(TemplateView):
"""View to prompt and setup applications."""
template_name = 'setup.html'