diff --git a/plinth/modules/owncloud/__init__.py b/plinth/modules/owncloud/__init__.py
index c5fbdd59a..c5a77b3f4 100644
--- a/plinth/modules/owncloud/__init__.py
+++ b/plinth/modules/owncloud/__init__.py
@@ -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 = []
diff --git a/plinth/modules/owncloud/forms.py b/plinth/modules/owncloud/forms.py
deleted file mode 100644
index 3ea4c6f8c..000000000
--- a/plinth/modules/owncloud/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 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)
diff --git a/plinth/modules/owncloud/urls.py b/plinth/modules/owncloud/urls.py
index 338ad6cc5..7f215357b 100644
--- a/plinth/modules/owncloud/urls.py
+++ b/plinth/modules/owncloud/urls.py
@@ -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'),
]
diff --git a/plinth/modules/owncloud/views.py b/plinth/modules/owncloud/views.py
deleted file mode 100644
index b2e77077b..000000000
--- a/plinth/modules/owncloud/views.py
+++ /dev/null
@@ -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 .
-#
-
-"""
-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'])