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'))