diff --git a/modules/installed/apps/owncloud.py b/modules/installed/apps/owncloud.py index 1dcca2241..7ed4dfcdb 100644 --- a/modules/installed/apps/owncloud.py +++ b/modules/installed/apps/owncloud.py @@ -1,84 +1,85 @@ import cherrypy +from django import forms from gettext import gettext as _ from modules.auth import require -from plugin_mount import PagePlugin, FormPlugin -from forms import Form +from plugin_mount import PagePlugin import actions import cfg import service import util -class Owncloud(PagePlugin, FormPlugin): +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) + 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=self.is_enabled) - - def is_enabled(self): - """Return whether ownCloud is enabled""" - output, error = actions.run('owncloud-setup', 'status') - if error: - raise Exception('Error getting ownCloud status: %s' % error) - - return 'enable' in output.split() + enabled=status['enabled']) @cherrypy.expose @require() def index(self, **kwargs): - owncloud_enable = self.is_enabled() + """Serve the ownCloud configuration page""" + status = self.get_status() - if 'submitted' in kwargs: - owncloud_enable = self.process_form(kwargs) - - main = self.form(owncloud_enable) - sidebar_right=""" -ownCloud
-

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. -

-""" - return util.render_template(title="Owncloud", main=main, - sidebar_right=sidebar_right) + form = None + messages = [] - def form(self, owncloud_enable, message=None): - form = Form(title="Configuration", - action=cfg.server_dir + "/apps/owncloud/index", - name="configure_owncloud", - message=message) - form.checkbox(_("Enable Owncloud"), name="owncloud_enable", id="owncloud_enable", checked=owncloud_enable) - # hidden field is needed because checkbox doesn't post if not checked - form.hidden(name="submitted", value="True") - form.html(_("""

When enabled, the owncloud installation will be available from owncloud on the web server. Visit this URL to set up the initial administration account for owncloud.

""")) - form.html(_("""

Note: Setting up owncloud for the first time might take 5 minutes or more, depending on download bandwidth from the Debian APT sources.

""")) - form.submit(_("Update setup")) - return form.render() + 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') - def process_form(self, kwargs): - checkedinfo = { - 'enable' : False, - } + return util.render_template(template='owncloud', title=_('ownCloud'), + form=form, messages=messages) - opts = [] - for k in kwargs.keys(): - if 'on' == kwargs[k]: - shortk = k.split("owncloud_").pop() - checkedinfo[shortk] = True + @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) - for key in checkedinfo.keys(): - if checkedinfo[key]: - opts.append(key) - else: - opts.append('no'+key) - actions.superuser_run("owncloud-setup", opts, async=True) + 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, checkedinfo['enable']) - - return checkedinfo['enable'] + self.service.notify_enabled(self, new_status['enabled']) diff --git a/modules/installed/apps/templates/owncloud.html b/modules/installed/apps/templates/owncloud.html new file mode 100644 index 000000000..b0418e91d --- /dev/null +++ b/modules/installed/apps/templates/owncloud.html @@ -0,0 +1,46 @@ +{% extends "login_nav.html" %} +{% load bootstrap %} + +{% block main_block %} + + {% for severity, message in messages %} +
{{ message }}
+ {% endfor %} + +
+ {% csrf_token %} + + {{ form|bootstrap }} + +

When enabled, the owncloud installation will be available + from owncloud on the web server. Visit + this URL to set up the initial administration account for + owncloud.

+ +

Note: Setting up owncloud for the first time might take + 5 minutes or more, depending on download bandwidth from the + Debian APT sources.

+ + + +
+ +{% endblock %} + +{% block sidebar_right_block %} + + + +{% endblock %}