Move ownCloud to separate module

This commit is contained in:
Sunil Mohan Adapa committed 2014-06-01 23:35:10 +05:30
1 parent 1b4364b045
commit 034745e91f
3 files changed
+1 -1

No files matched your search

+85
View File
@@ -0,0 +1,85 @@
import cherrypy
from django import forms
from gettext import gettext as _
from modules.auth import require
from plugin_mount import PagePlugin
import actions
import cfg
import service
import util
class OwnCloudForm(forms.Form): # pylint: disable-msg=W0232
"""ownCloud configuration form"""
enabled = forms.BooleanField(label=_('Enable ownCloud'), required=False)
# XXX: Only present due to issue with submitting empty form
dummy = forms.CharField(label='Dummy', initial='dummy',
widget=forms.HiddenInput())
class OwnCloud(PagePlugin):
"""ownCloud configuration page"""
order = 90
def __init__(self, *args, **kwargs):
PagePlugin.__init__(self, *args, **kwargs)
self.register_page('apps.owncloud')
cfg.html_root.apps.menu.add_item('Owncloud', 'icon-picture',
'/apps/owncloud', 35)
status = self.get_status()
self.service = service.Service('owncloud', _('ownCloud'),
['http', 'https'], is_external=True,
enabled=status['enabled'])
@cherrypy.expose
@require()
def index(self, **kwargs):
"""Serve the ownCloud configuration page"""
status = self.get_status()
form = None
messages = []
if kwargs:
form = OwnCloudForm(kwargs, prefix='owncloud')
# pylint: disable-msg=E1101
if form.is_valid():
self._apply_changes(status, form.cleaned_data, messages)
status = self.get_status()
form = OwnCloudForm(initial=status, prefix='owncloud')
else:
form = OwnCloudForm(initial=status, prefix='owncloud')
return util.render_template(template='owncloud', title=_('ownCloud'),
form=form, messages=messages)
@staticmethod
def get_status():
"""Return the current status"""
output, error = actions.run('owncloud-setup', 'status')
if error:
raise Exception('Error getting ownCloud status: %s' % error)
return {'enabled': 'enable' in output.split()}
def _apply_changes(self, old_status, new_status, messages):
"""Apply the changes"""
if old_status['enabled'] == new_status['enabled']:
messages.append(('info', _('Setting unchanged')))
return
if new_status['enabled']:
messages.append(('success', _('ownCloud enabled')))
option = 'enable'
else:
messages.append(('success', _('ownCloud disabled')))
option = 'noenable'
actions.superuser_run('owncloud-setup', [option], async=True)
# Send a signal to other modules that the service is
# enabled/disabled
self.service.notify_enabled(self, new_status['enabled'])
@@ -0,0 +1,63 @@
{% extends "login_nav.html" %}
{% comment %}
#
# 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/>.
#
{% endcomment %}
{% load bootstrap %}
{% block main_block %}
{% include 'messages.html' %}
<form class="form" method="post">
{% csrf_token %}
{{ form|bootstrap }}
<p>When enabled, the owncloud installation will be available
from <a href="/owncloud">owncloud</a> on the web server. Visit
this URL to set up the initial administration account for
owncloud.</p>
<p><strong>Note: Setting up owncloud for the first time might take
5 minutes or more, depending on download bandwidth from the
Debian APT sources.</strong></p>
<input type="submit" class="btn-primary" value="Update setup"/>
</form>
{% endblock %}
{% block sidebar_right_block %}
<div class="well sidebar-nav">
<h3>ownCloud</h3>
<p>ownCloud gives you universal access to your files through a web
interface or WebDAV. It also provides a platform to easily view
& sync your contacts, calendars and bookmarks across all your
devices and enables basic editing right on the web. Installation
has minimal server requirements, doesn't need special
permissions and is quick. ownCloud is extendable via a simple
but powerful API for applications and plugins.</p>
</div>
{% endblock %}