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