owncloud: Use common view for configuration

This commit is contained in:
Sunil Mohan Adapa 2016-02-28 12:27:28 +05:30
parent 9422f43ba5
commit f205612831
No known key found for this signature in database
GPG Key ID: 36C361440C9BC971
4 changed files with 18 additions and 107 deletions

View File

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

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 ownCloud.
"""
from django import forms
from django.utils.translation import ugettext_lazy as _
class OwnCloudForm(forms.Form): # pylint: disable-msg=W0232
"""ownCloud configuration form"""
enabled = forms.BooleanField(
label=_('Enable ownCloud'),
required=False)

View File

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

View File

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