From 1f6935c30ba5f76c3ffb2c66fe78a3cec62ebfc8 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Sun, 28 Feb 2016 12:54:57 +0530 Subject: [PATCH] roundcube: Use common view for configuration --- plinth/modules/roundcube/__init__.py | 11 +++++ plinth/modules/roundcube/forms.py | 30 ----------- plinth/modules/roundcube/urls.py | 5 +- plinth/modules/roundcube/views.py | 74 ---------------------------- 4 files changed, 14 insertions(+), 106 deletions(-) delete mode 100644 plinth/modules/roundcube/forms.py delete mode 100644 plinth/modules/roundcube/views.py 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'))