roundcube: Use common view for configuration

This commit is contained in:
Sunil Mohan Adapa 2016-02-28 12:54:57 +05:30
parent 40a9507aae
commit 1f6935c30b
No known key found for this signature in database
GPG Key ID: 36C361440C9BC971
4 changed files with 14 additions and 106 deletions

View File

@ -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 = []

View File

@ -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 <http://www.gnu.org/licenses/>.
#
"""
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)

View File

@ -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'),
]

View File

@ -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 <http://www.gnu.org/licenses/>.
#
"""
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'))