From fa8c2cf6ff7f589334096a60cef49430d9d00c3d Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Sun, 28 Feb 2016 12:21:29 +0530 Subject: [PATCH 01/20] views: Add a common view for enabling applications - A lot of boiler plate code can be removed from Plinth if enabling and disabling an application can be done using a common base form. - This also allows to define a reusable method in an application for enabling and disabling. - This brings more structure to a application module and paves way for having a different views such as dashboard. --- plinth/forms.py | 30 ++++++++++++++++++ plinth/views.py | 84 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 114 insertions(+) create mode 100644 plinth/forms.py diff --git a/plinth/forms.py b/plinth/forms.py new file mode 100644 index 000000000..f554bcfc8 --- /dev/null +++ b/plinth/forms.py @@ -0,0 +1,30 @@ +# +# 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 . +# + +""" +Common forms for use by modules. +""" + +from django import forms +from django.utils.translation import ugettext_lazy as _ + + +class ConfigurationForm(forms.Form): + """Generic configuration form for simple modules.""" + enabled = forms.BooleanField( + label=_('Enable application'), + required=False) diff --git a/plinth/views.py b/plinth/views.py index a5b9a7680..47f7518c8 100644 --- a/plinth/views.py +++ b/plinth/views.py @@ -19,17 +19,101 @@ Main Plinth views """ +from django.contrib import messages +from django.core.exceptions import ImproperlyConfigured from django.core.urlresolvers import reverse from django.http.response import HttpResponseRedirect from django.views.generic import TemplateView +from django.views.generic.edit import FormView +from django.utils.translation import ugettext as _ import time +from . import forms +from . import module_loader + def index(request): """Serve the main index page.""" return HttpResponseRedirect(reverse('apps:index')) +class ConfigurationView(FormView): + """A generic view for configuring simple modules.""" + form_class = forms.ConfigurationForm + module_name = None + + def __init__(self, module_name=None, *args, **kwargs): + """Set the module name on which this configuration view operates.""" + self.instance_module_name = module_name + + def get_module_name(self): + """Return the name of the module associated with the view.""" + if not self.instance_module_name and not self.module_name: + raise ImproperlyConfigured( + 'Using ConfigurationView without the "module_name" class ' + 'attribute or intialization attribute is prohibited.') + else: + return self.instance_module_name or self.module_name + + def get_module(self): + """Return the module associated with the view.""" + return module_loader.loaded_modules[self.get_module_name()] + + def get_initial(self): + """Return the status of the module to fill in the form.""" + return self.get_module().get_status() + + def get_prefix(self): + """Return prefix for form used in the view.""" + return self.get_module_name() + + def get_template_names(self): + """Return the list of template names for the view.""" + return [self.get_module_name() + '.html'] + + def get_context_data(self, **kwargs): + """Return the context data for rendering the template view.""" + if 'title' not in kwargs: + kwargs['title'] = getattr(self.get_module(), 'title', None) + + if 'description' not in kwargs: + kwargs['description'] = \ + getattr(self.get_module(), 'description', None) + + context = super().get_context_data(**kwargs) + + if 'status' not in context: + context['status'] = context['form'].initial + + return context + + def form_valid(self, form): + """Perform operation when the form submission is valid.""" + old_status = form.initial + new_status = form.cleaned_data + + modified = self.apply_changes(old_status, new_status) + if not modified: + messages.info(self.request, _('Setting unchanged')) + + context = self.get_context_data() + return self.render_to_response(context) + + def apply_changes(self, old_status, new_status): + """Apply the changes submitted in the form.""" + if old_status['enabled'] == new_status['enabled']: + return False + + should_enable = new_status['enabled'] + self.get_module().enable(should_enable) + if should_enable: + messages.success(self.request, _('Application enabled')) + else: + messages.success(self.request, _('Application disabled')) + + return True + + class SetupView(TemplateView): """View to prompt and setup applications.""" template_name = 'setup.html' From 96ca09d59d29c8102ad4a1b8039582de286cf8ff Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Sun, 28 Feb 2016 12:26:27 +0530 Subject: [PATCH 02/20] deluge: Use common view for configuration --- plinth/modules/deluge/__init__.py | 13 ++++++ plinth/modules/deluge/forms.py | 30 ------------- plinth/modules/deluge/urls.py | 5 ++- plinth/modules/deluge/views.py | 75 ------------------------------- 4 files changed, 16 insertions(+), 107 deletions(-) delete mode 100644 plinth/modules/deluge/forms.py delete mode 100644 plinth/modules/deluge/views.py diff --git a/plinth/modules/deluge/__init__.py b/plinth/modules/deluge/__init__.py index f5c1b6f37..794817b36 100644 --- a/plinth/modules/deluge/__init__.py +++ b/plinth/modules/deluge/__init__.py @@ -63,6 +63,12 @@ def setup(helper, old_version=None): helper.call('post', service.notify_enabled, None, True) +def get_status(): + """Get the current settings.""" + return {'enabled': is_enabled(), + 'is_running': is_running()} + + def is_enabled(): """Return whether the module is enabled.""" return (action_utils.webserver_is_enabled('deluge-plinth') and @@ -74,6 +80,13 @@ def is_running(): return action_utils.service_is_running('deluge-web') +def enable(should_enable): + """Enable/disable the module.""" + sub_command = 'enable' if should_enable else 'disable' + actions.superuser_run('deluge', [sub_command]) + service.notify_enabled(None, should_enable) + + def diagnose(): """Run diagnostics and return the results.""" results = [] diff --git a/plinth/modules/deluge/forms.py b/plinth/modules/deluge/forms.py deleted file mode 100644 index 3ae1271d9..000000000 --- a/plinth/modules/deluge/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 Deluge web client. -""" - -from django import forms -from django.utils.translation import ugettext_lazy as _ - - -class DelugeForm(forms.Form): - """Deluge configuration form.""" - enabled = forms.BooleanField( - label=_('Enable Deluge'), - required=False) diff --git a/plinth/modules/deluge/urls.py b/plinth/modules/deluge/urls.py index a36941271..4aa3712fd 100644 --- a/plinth/modules/deluge/urls.py +++ b/plinth/modules/deluge/urls.py @@ -21,9 +21,10 @@ URLs for the Deluge module. from django.conf.urls import url -from . import views +from plinth.views import ConfigurationView urlpatterns = [ - url(r'^apps/deluge/$', views.index, name='index'), + url(r'^apps/deluge/$', ConfigurationView.as_view(module_name='deluge'), + name='index'), ] diff --git a/plinth/modules/deluge/views.py b/plinth/modules/deluge/views.py deleted file mode 100644 index 0b48b2333..000000000 --- a/plinth/modules/deluge/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 to configure a Deluge web client. -""" - -from django.contrib import messages -from django.template.response import TemplateResponse -from django.utils.translation import ugettext as _ - -from .forms import DelugeForm -from plinth import actions -from plinth.modules import deluge - - -def index(request): - """Serve configuration page.""" - status = get_status() - - form = None - - if request.method == 'POST': - form = DelugeForm(request.POST, prefix='deluge') - # pylint: disable=E1101 - if form.is_valid(): - _apply_changes(request, status, form.cleaned_data) - status = get_status() - form = DelugeForm(initial=status, prefix='deluge') - else: - form = DelugeForm(initial=status, prefix='deluge') - - return TemplateResponse(request, 'deluge.html', - {'title': deluge.title, - 'description': deluge.description, - 'status': status, - 'form': form}) - - -def get_status(): - """Get the current settings.""" - status = {'enabled': deluge.is_enabled(), - 'is_running': deluge.is_running()} - - return status - - -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('deluge', [sub_command]) - deluge.service.notify_enabled(None, new_status['enabled']) - modified = True - - if modified: - messages.success(request, _('Configuration updated')) - else: - messages.info(request, _('Setting unchanged')) From 9422f43ba58fb0a6f7ed7a372e806f5ae3a9afda Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Sun, 28 Feb 2016 12:27:05 +0530 Subject: [PATCH 03/20] minetest: Use common view for configuration --- plinth/modules/minetest/__init__.py | 14 ++++++ plinth/modules/minetest/forms.py | 30 ------------ plinth/modules/minetest/urls.py | 5 +- plinth/modules/minetest/views.py | 72 ----------------------------- 4 files changed, 17 insertions(+), 104 deletions(-) delete mode 100644 plinth/modules/minetest/forms.py delete mode 100644 plinth/modules/minetest/views.py diff --git a/plinth/modules/minetest/__init__.py b/plinth/modules/minetest/__init__.py index cf386bcb8..a8f90b48b 100644 --- a/plinth/modules/minetest/__init__.py +++ b/plinth/modules/minetest/__init__.py @@ -21,6 +21,7 @@ Plinth module for minetest. from django.utils.translation import ugettext_lazy as _ +from plinth import actions from plinth import action_utils from plinth import cfg from plinth import service as service_module @@ -61,6 +62,12 @@ def setup(helper, old_version=None): helper.call('post', service.notify_enabled, None, True) +def get_status(): + """Get the current service status.""" + return {'enabled': is_enabled(), + 'is_running': is_running()} + + def is_enabled(): """Return whether the service is enabled.""" return action_utils.service_is_enabled('minetest-server') @@ -71,6 +78,13 @@ def is_running(): return action_utils.service_is_running('minetest-server') +def enable(should_enable): + """Enable/disable the module.""" + sub_command = 'enable' if should_enable else 'disable' + actions.superuser_run('minetest', [sub_command]) + service.notify_enabled(None, should_enable) + + def diagnose(): """Run diagnostics and return the results.""" results = [] diff --git a/plinth/modules/minetest/forms.py b/plinth/modules/minetest/forms.py deleted file mode 100644 index 87e1fbaa8..000000000 --- a/plinth/modules/minetest/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 the minetest module. -""" - -from django import forms -from django.utils.translation import ugettext_lazy as _ - - -class MinetestForm(forms.Form): - """Minetest configuration form.""" - enabled = forms.BooleanField( - label=_('Enable Minetest server'), - required=False) diff --git a/plinth/modules/minetest/urls.py b/plinth/modules/minetest/urls.py index a297c4c6b..a32f5a7c5 100644 --- a/plinth/modules/minetest/urls.py +++ b/plinth/modules/minetest/urls.py @@ -21,9 +21,10 @@ URLs for the minetest module. from django.conf.urls import url -from . import views +from plinth.views import ConfigurationView urlpatterns = [ - url(r'^apps/minetest/$', views.index, name='index'), + url(r'^apps/minetest/$', ConfigurationView.as_view(module_name='minetest'), + name='index'), ] diff --git a/plinth/modules/minetest/views.py b/plinth/modules/minetest/views.py deleted file mode 100644 index 5d5f5a3d3..000000000 --- a/plinth/modules/minetest/views.py +++ /dev/null @@ -1,72 +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 . -# - -""" -Views for the minetest module. -""" - -from django.contrib import messages -from django.template.response import TemplateResponse -from django.utils.translation import ugettext as _ - -from .forms import MinetestForm -from plinth import actions -from plinth.modules import minetest - - -def index(request): - """Serve configuration page.""" - status = get_status() - - form = None - - if request.method == 'POST': - form = MinetestForm(request.POST, prefix='minetest') - if form.is_valid(): - _apply_changes(request, status, form.cleaned_data) - status = get_status() - form = MinetestForm(initial=status, prefix='minetest') - else: - form = MinetestForm(initial=status, prefix='minetest') - - return TemplateResponse(request, 'minetest.html', - {'title': minetest.title, - 'description': minetest.description, - 'status': status, - 'form': form}) - - -def get_status(): - """Get the current service status.""" - return {'enabled': minetest.is_enabled(), - 'is_running': minetest.is_running()} - - -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('minetest', [sub_command]) - minetest.service.notify_enabled(None, new_status['enabled']) - modified = True - - if modified: - messages.success(request, _('Configuration updated')) - else: - messages.info(request, _('Setting unchanged')) From f2056128311b4bfa29c9ddf284f25cd989acc200 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Sun, 28 Feb 2016 12:27:28 +0530 Subject: [PATCH 04/20] owncloud: Use common view for configuration --- plinth/modules/owncloud/__init__.py | 15 ++++++ plinth/modules/owncloud/forms.py | 30 ------------ plinth/modules/owncloud/urls.py | 5 +- plinth/modules/owncloud/views.py | 75 ----------------------------- 4 files changed, 18 insertions(+), 107 deletions(-) delete mode 100644 plinth/modules/owncloud/forms.py delete mode 100644 plinth/modules/owncloud/views.py 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']) From 5c7eb69c319766da9e5378ae83c8f750981ebbc5 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Sun, 28 Feb 2016 12:27:47 +0530 Subject: [PATCH 05/20] radicale: Use common view for configuration --- plinth/modules/radicale/__init__.py | 13 ++++++ plinth/modules/radicale/forms.py | 30 ------------ plinth/modules/radicale/urls.py | 5 +- plinth/modules/radicale/views.py | 72 ----------------------------- 4 files changed, 16 insertions(+), 104 deletions(-) delete mode 100644 plinth/modules/radicale/forms.py delete mode 100644 plinth/modules/radicale/views.py diff --git a/plinth/modules/radicale/__init__.py b/plinth/modules/radicale/__init__.py index 026aa18ee..b421ce174 100644 --- a/plinth/modules/radicale/__init__.py +++ b/plinth/modules/radicale/__init__.py @@ -65,6 +65,12 @@ def setup(helper, old_version=None): helper.call('post', service.notify_enabled, None, True) +def get_status(): + """Get the current service status.""" + return {'enabled': is_enabled(), + 'is_running': is_running()} + + def is_enabled(): """Return whether the service is enabled.""" return action_utils.service_is_enabled('radicale') @@ -75,6 +81,13 @@ def is_running(): return action_utils.service_is_running('radicale') +def enable(should_enable): + """Enable/disable the module.""" + sub_command = 'enable' if should_enable else 'disable' + actions.superuser_run('radicale', [sub_command]) + service.notify_enabled(None, should_enable) + + def diagnose(): """Run diagnostics and return the results.""" results = [] diff --git a/plinth/modules/radicale/forms.py b/plinth/modules/radicale/forms.py deleted file mode 100644 index 7ecbeae83..000000000 --- a/plinth/modules/radicale/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 radicale module. -""" - -from django import forms -from django.utils.translation import ugettext_lazy as _ - - -class RadicaleForm(forms.Form): - """Radicale configuration form.""" - enabled = forms.BooleanField( - label=_('Enable Radicale service'), - required=False) diff --git a/plinth/modules/radicale/urls.py b/plinth/modules/radicale/urls.py index ae7c20084..55f492662 100644 --- a/plinth/modules/radicale/urls.py +++ b/plinth/modules/radicale/urls.py @@ -21,9 +21,10 @@ URLs for the radicale module. from django.conf.urls import url -from . import views +from plinth.views import ConfigurationView urlpatterns = [ - url(r'^apps/radicale/$', views.index, name='index'), + url(r'^apps/radicale/$', ConfigurationView.as_view(module_name='radicale'), + name='index'), ] diff --git a/plinth/modules/radicale/views.py b/plinth/modules/radicale/views.py deleted file mode 100644 index f0d37cc6d..000000000 --- a/plinth/modules/radicale/views.py +++ /dev/null @@ -1,72 +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 . -# - -""" -Views for radicale module. -""" - -from django.contrib import messages -from django.template.response import TemplateResponse -from django.utils.translation import ugettext as _ - -from .forms import RadicaleForm -from plinth import actions -from plinth.modules import radicale - - -def index(request): - """Serve configuration page.""" - status = get_status() - - form = None - - if request.method == 'POST': - form = RadicaleForm(request.POST, prefix='radicale') - if form.is_valid(): - _apply_changes(request, status, form.cleaned_data) - status = get_status() - form = RadicaleForm(initial=status, prefix='radicale') - else: - form = RadicaleForm(initial=status, prefix='radicale') - - return TemplateResponse(request, 'radicale.html', - {'title': radicale.title, - 'description': radicale.description, - 'status': status, - 'form': form}) - - -def get_status(): - """Get the current service status.""" - return {'enabled': radicale.is_enabled(), - 'is_running': radicale.is_running()} - - -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('radicale', [sub_command]) - radicale.service.notify_enabled(None, new_status['enabled']) - modified = True - - if modified: - messages.success(request, _('Configuration updated')) - else: - messages.info(request, _('Setting unchanged')) From fb19fed6f54f12bf291d345b1ad95a8cd3fc795f Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Sun, 28 Feb 2016 12:28:00 +0530 Subject: [PATCH 06/20] shaarli: Use common view for configuration --- plinth/modules/shaarli/__init__.py | 13 ++++++ plinth/modules/shaarli/forms.py | 30 ------------- plinth/modules/shaarli/urls.py | 5 ++- plinth/modules/shaarli/views.py | 72 ------------------------------ 4 files changed, 16 insertions(+), 104 deletions(-) delete mode 100644 plinth/modules/shaarli/forms.py delete mode 100644 plinth/modules/shaarli/views.py diff --git a/plinth/modules/shaarli/__init__.py b/plinth/modules/shaarli/__init__.py index 2210da998..bbb35cc1e 100644 --- a/plinth/modules/shaarli/__init__.py +++ b/plinth/modules/shaarli/__init__.py @@ -21,6 +21,7 @@ Plinth module to configure Shaarli. from django.utils.translation import ugettext_lazy as _ +from plinth import actions from plinth import action_utils from plinth import cfg from plinth import service as service_module @@ -61,6 +62,18 @@ def setup(helper, old_version=None): helper.call('post', service.notify_enabled, None, True) +def get_status(): + """Get the current settings.""" + return {'enabled': is_enabled()} + + def is_enabled(): """Return whether the module is enabled.""" return action_utils.webserver_is_enabled('shaarli') + + +def enable(should_enable): + """Enable/disable the module.""" + sub_command = 'enable' if should_enable else 'disable' + actions.superuser_run('shaarli', [sub_command]) + service.notify_enabled(None, should_enable) diff --git a/plinth/modules/shaarli/forms.py b/plinth/modules/shaarli/forms.py deleted file mode 100644 index 01c571adb..000000000 --- a/plinth/modules/shaarli/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 Shaarli. -""" - -from django import forms -from django.utils.translation import ugettext_lazy as _ - - -class ShaarliForm(forms.Form): - """Shaarli configuration form.""" - enabled = forms.BooleanField( - label=_('Enable Shaarli'), - required=False) diff --git a/plinth/modules/shaarli/urls.py b/plinth/modules/shaarli/urls.py index 2784905eb..b75250a3d 100644 --- a/plinth/modules/shaarli/urls.py +++ b/plinth/modules/shaarli/urls.py @@ -21,9 +21,10 @@ URLs for the Shaarli module. from django.conf.urls import url -from . import views +from plinth.views import ConfigurationView urlpatterns = [ - url(r'^apps/shaarli/$', views.index, name='index'), + url(r'^apps/shaarli/$', ConfigurationView.as_view(module_name='shaarli'), + name='index'), ] diff --git a/plinth/modules/shaarli/views.py b/plinth/modules/shaarli/views.py deleted file mode 100644 index de174faa7..000000000 --- a/plinth/modules/shaarli/views.py +++ /dev/null @@ -1,72 +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 to configure Shaarli. -""" - -from django.contrib import messages -from django.template.response import TemplateResponse -from django.utils.translation import ugettext as _ - -from .forms import ShaarliForm -from plinth import actions -from plinth.modules import shaarli - - -def index(request): - """Serve configuration page.""" - status = get_status() - - form = None - - if request.method == 'POST': - form = ShaarliForm(request.POST, prefix='shaarli') - if form.is_valid(): - _apply_changes(request, status, form.cleaned_data) - status = get_status() - form = ShaarliForm(initial=status, prefix='shaarli') - else: - form = ShaarliForm(initial=status, prefix='shaarli') - - return TemplateResponse(request, 'shaarli.html', - {'title': shaarli.title, - 'description': shaarli.description, - 'status': status, - 'form': form}) - - -def get_status(): - """Get the current settings.""" - status = {'enabled': shaarli.is_enabled()} - return status - - -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('shaarli', [sub_command]) - shaarli.service.notify_enabled(None, new_status['enabled']) - modified = True - - if modified: - messages.success(request, _('Configuration updated')) - else: - messages.info(request, _('Setting unchanged')) From 40a9507aae024b432fc8b581e0d45078381c48cf Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Sun, 28 Feb 2016 12:38:52 +0530 Subject: [PATCH 07/20] xmpp: Use common view for configuration --- plinth/modules/xmpp/__init__.py | 14 ++++++ plinth/modules/xmpp/forms.py | 30 ------------- plinth/modules/xmpp/urls.py | 6 ++- plinth/modules/xmpp/views.py | 79 --------------------------------- 4 files changed, 18 insertions(+), 111 deletions(-) delete mode 100644 plinth/modules/xmpp/forms.py delete mode 100644 plinth/modules/xmpp/views.py diff --git a/plinth/modules/xmpp/__init__.py b/plinth/modules/xmpp/__init__.py index 1365f1d98..d823530bd 100644 --- a/plinth/modules/xmpp/__init__.py +++ b/plinth/modules/xmpp/__init__.py @@ -79,6 +79,13 @@ def setup(helper, old_version=None): helper.call('post', service.notify_enabled, None, True) +def get_status(): + """Get the current settings.""" + return {'enabled': is_enabled(), + 'is_running': is_running(), + 'domainname': get_domainname()} + + def is_enabled(): """Return whether the module is enabled.""" return (action_utils.service_is_enabled('ejabberd') and @@ -96,6 +103,13 @@ def get_domainname(): return '.'.join(fqdn.split('.')[1:]) +def enable(should_enable): + """Enable/disable the module.""" + sub_command = 'enable' if should_enable else 'disable' + actions.superuser_run('xmpp', [sub_command]) + service.notify_enabled(None, should_enable) + + def on_pre_hostname_change(sender, old_hostname, new_hostname, **kwargs): """ Backup ejabberd database before hostname is changed. diff --git a/plinth/modules/xmpp/forms.py b/plinth/modules/xmpp/forms.py deleted file mode 100644 index 3d9e5d61d..000000000 --- a/plinth/modules/xmpp/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 XMPP service. -""" - -from django import forms -from django.utils.translation import ugettext_lazy as _ - - -class XmppForm(forms.Form): # pylint: disable=W0232 - """XMPP configuration form.""" - enabled = forms.BooleanField( - label=_('Enable XMPP'), - required=False) diff --git a/plinth/modules/xmpp/urls.py b/plinth/modules/xmpp/urls.py index db022e9cf..36e86a7c3 100644 --- a/plinth/modules/xmpp/urls.py +++ b/plinth/modules/xmpp/urls.py @@ -21,8 +21,10 @@ URLs for the XMPP module from django.conf.urls import url -from . import views +from plinth.views import ConfigurationView + urlpatterns = [ - url(r'^apps/xmpp/$', views.index, name='index'), + url(r'^apps/xmpp/$', ConfigurationView.as_view(module_name='xmpp'), + name='index'), ] diff --git a/plinth/modules/xmpp/views.py b/plinth/modules/xmpp/views.py deleted file mode 100644 index ca1841535..000000000 --- a/plinth/modules/xmpp/views.py +++ /dev/null @@ -1,79 +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 to configure XMPP server -""" - -from django.contrib import messages -from django.template.response import TemplateResponse -from django.utils.translation import ugettext as _ -import logging - -from .forms import XmppForm -from plinth import actions -from plinth.modules import xmpp - - -logger = logging.getLogger(__name__) - - -def index(request): - """Serve configuration page""" - status = get_status() - - form = None - - if request.method == 'POST': - form = XmppForm(request.POST, prefix='xmpp') - if form.is_valid(): - _apply_changes(request, status, form.cleaned_data) - status = get_status() - form = XmppForm(initial=status, prefix='xmpp') - else: - form = XmppForm(initial=status, prefix='xmpp') - - return TemplateResponse(request, 'xmpp.html', - {'title': xmpp.title, - 'description': xmpp.description, - 'status': status, - 'form': form}) - - -def get_status(): - """Get the current settings.""" - status = {'enabled': xmpp.is_enabled(), - 'is_running': xmpp.is_running(), - 'domainname': xmpp.get_domainname()} - - return status - - -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('xmpp', [sub_command]) - xmpp.service.notify_enabled(None, new_status['enabled']) - modified = True - - if modified: - messages.success(request, _('Configuration updated')) - else: - messages.info(request, _('Setting unchanged')) From 1f6935c30ba5f76c3ffb2c66fe78a3cec62ebfc8 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Sun, 28 Feb 2016 12:54:57 +0530 Subject: [PATCH 08/20] roundcube: Use common view for configuration --- plinth/modules/roundcube/__init__.py | 11 +++++ plinth/modules/roundcube/forms.py | 30 ----------- plinth/modules/roundcube/urls.py | 5 +- plinth/modules/roundcube/views.py | 74 ---------------------------- 4 files changed, 14 insertions(+), 106 deletions(-) delete mode 100644 plinth/modules/roundcube/forms.py delete mode 100644 plinth/modules/roundcube/views.py diff --git a/plinth/modules/roundcube/__init__.py b/plinth/modules/roundcube/__init__.py index 1c11596af..a67364707 100644 --- a/plinth/modules/roundcube/__init__.py +++ b/plinth/modules/roundcube/__init__.py @@ -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 = [] diff --git a/plinth/modules/roundcube/forms.py b/plinth/modules/roundcube/forms.py deleted file mode 100644 index ef0014a6c..000000000 --- a/plinth/modules/roundcube/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 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) diff --git a/plinth/modules/roundcube/urls.py b/plinth/modules/roundcube/urls.py index 66be5df69..a307cce07 100644 --- a/plinth/modules/roundcube/urls.py +++ b/plinth/modules/roundcube/urls.py @@ -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'), ] diff --git a/plinth/modules/roundcube/views.py b/plinth/modules/roundcube/views.py deleted file mode 100644 index 610fdb8c0..000000000 --- a/plinth/modules/roundcube/views.py +++ /dev/null @@ -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 . -# - -""" -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')) From 1eae781e647c7856402388a8f10179974e6467f0 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Sun, 28 Feb 2016 14:49:34 +0530 Subject: [PATCH 09/20] quassel: Use common view for configuration --- plinth/modules/quassel/__init__.py | 14 ++++++ plinth/modules/quassel/forms.py | 30 ------------- plinth/modules/quassel/urls.py | 5 ++- plinth/modules/quassel/views.py | 72 ------------------------------ 4 files changed, 17 insertions(+), 104 deletions(-) delete mode 100644 plinth/modules/quassel/forms.py delete mode 100644 plinth/modules/quassel/views.py diff --git a/plinth/modules/quassel/__init__.py b/plinth/modules/quassel/__init__.py index c30f0abcc..b2a4bdb37 100644 --- a/plinth/modules/quassel/__init__.py +++ b/plinth/modules/quassel/__init__.py @@ -21,6 +21,7 @@ Plinth module for Quassel. from django.utils.translation import ugettext_lazy as _ +from plinth import actions from plinth import action_utils from plinth import cfg from plinth import service as service_module @@ -68,6 +69,12 @@ def setup(helper, old_version=None): helper.call('post', service.notify_enabled, None, True) +def get_status(): + """Get the current service status.""" + return {'enabled': is_enabled(), + 'is_running': is_running()} + + def is_enabled(): """Return whether the service is enabled.""" return action_utils.service_is_enabled('quasselcore') @@ -78,6 +85,13 @@ def is_running(): return action_utils.service_is_running('quasselcore') +def enable(should_enable): + """Enable/disable the module.""" + sub_command = 'enable' if should_enable else 'disable' + actions.superuser_run('quassel', [sub_command]) + service.notify_enabled(None, should_enable) + + def diagnose(): """Run diagnostics and return the results.""" results = [] diff --git a/plinth/modules/quassel/forms.py b/plinth/modules/quassel/forms.py deleted file mode 100644 index c8da8c883..000000000 --- a/plinth/modules/quassel/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 Quassel module. -""" - -from django import forms -from django.utils.translation import ugettext_lazy as _ - - -class QuasselForm(forms.Form): - """Quassel configuration form.""" - enabled = forms.BooleanField( - label=_('Enable Quassel core service'), - required=False) diff --git a/plinth/modules/quassel/urls.py b/plinth/modules/quassel/urls.py index 5018ac2f8..3fef76f7f 100644 --- a/plinth/modules/quassel/urls.py +++ b/plinth/modules/quassel/urls.py @@ -21,9 +21,10 @@ URLs for the quassel module. from django.conf.urls import url -from . import views +from plinth.views import ConfigurationView urlpatterns = [ - url(r'^apps/quassel/$', views.index, name='index'), + url(r'^apps/quassel/$', ConfigurationView.as_view(module_name='quassel'), + name='index'), ] diff --git a/plinth/modules/quassel/views.py b/plinth/modules/quassel/views.py deleted file mode 100644 index 2adee5260..000000000 --- a/plinth/modules/quassel/views.py +++ /dev/null @@ -1,72 +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 . -# - -""" -Views for Quassel module. -""" - -from django.contrib import messages -from django.template.response import TemplateResponse -from django.utils.translation import ugettext as _ - -from .forms import QuasselForm -from plinth import actions -from plinth.modules import quassel - - -def index(request): - """Serve configuration page.""" - status = get_status() - - form = None - - if request.method == 'POST': - form = QuasselForm(request.POST, prefix='quassel') - if form.is_valid(): - _apply_changes(request, status, form.cleaned_data) - status = get_status() - form = QuasselForm(initial=status, prefix='quassel') - else: - form = QuasselForm(initial=status, prefix='quassel') - - return TemplateResponse(request, 'quassel.html', - {'title': quassel.title, - 'description': quassel.description, - 'status': status, - 'form': form}) - - -def get_status(): - """Get the current service status.""" - return {'enabled': quassel.is_enabled(), - 'is_running': quassel.is_running()} - - -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('quassel', [sub_command]) - quassel.service.notify_enabled(None, new_status['enabled']) - modified = True - - if modified: - messages.success(request, _('Configuration updated')) - else: - messages.info(request, _('Setting unchanged')) From 07df62854bf2d5a52b3460d2d1e0c6c4b0020d96 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Sun, 28 Feb 2016 14:54:06 +0530 Subject: [PATCH 10/20] restore: Use common view for configuration - Rename the template from restore_index.html to restore.html to avoid having to create a custom view. --- plinth/modules/restore/__init__.py | 17 ++++- plinth/modules/restore/forms.py | 30 -------- .../{restore_index.html => restore.html} | 0 plinth/modules/restore/urls.py | 5 +- plinth/modules/restore/views.py | 70 ------------------- 5 files changed, 19 insertions(+), 103 deletions(-) delete mode 100644 plinth/modules/restore/forms.py rename plinth/modules/restore/templates/{restore_index.html => restore.html} (100%) delete mode 100644 plinth/modules/restore/views.py diff --git a/plinth/modules/restore/__init__.py b/plinth/modules/restore/__init__.py index dff18b3d4..532cabd0a 100644 --- a/plinth/modules/restore/__init__.py +++ b/plinth/modules/restore/__init__.py @@ -20,11 +20,12 @@ Plinth module to configure reStore. """ from django.utils.translation import ugettext_lazy as _ + +from plinth import actions from plinth import action_utils, cfg from plinth import service as service_module from plinth.utils import format_lazy -service = None version = 1 @@ -45,6 +46,8 @@ description = [ 'reStore web-interface.') ] +service = None + def init(): """Initialize the reStore module.""" @@ -62,6 +65,18 @@ def setup(helper, old_version=None): helper.install(['node-restore']) +def get_status(): + """Get the current settings.""" + return {'enabled': is_enabled()} + + def is_enabled(): """Return whether the module is enabled.""" return action_utils.service_is_enabled('node-restore') + + +def enable(should_enable): + """Enable/disable the module.""" + sub_command = 'enable' if should_enable else 'disable' + actions.superuser_run('restore', [sub_command]) + service.notify_enabled(None, should_enable) diff --git a/plinth/modules/restore/forms.py b/plinth/modules/restore/forms.py deleted file mode 100644 index 4c8c2bf90..000000000 --- a/plinth/modules/restore/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 reStore. -""" - -from django import forms -from django.utils.translation import ugettext_lazy as _ - - -class ReStoreForm(forms.Form): - """reStore configuration form.""" - enabled = forms.BooleanField( - label=_('Enable reStore'), - required=False) diff --git a/plinth/modules/restore/templates/restore_index.html b/plinth/modules/restore/templates/restore.html similarity index 100% rename from plinth/modules/restore/templates/restore_index.html rename to plinth/modules/restore/templates/restore.html diff --git a/plinth/modules/restore/urls.py b/plinth/modules/restore/urls.py index 69cec1a51..c51116f8f 100644 --- a/plinth/modules/restore/urls.py +++ b/plinth/modules/restore/urls.py @@ -21,9 +21,10 @@ URLs for the reStore module. from django.conf.urls import url -from . import views +from plinth.views import ConfigurationView urlpatterns = [ - url(r'^apps/restore/$', views.index, name='index'), + url(r'^apps/restore/$', ConfigurationView.as_view(module_name='restore'), + name='index'), ] diff --git a/plinth/modules/restore/views.py b/plinth/modules/restore/views.py deleted file mode 100644 index 0e91904a4..000000000 --- a/plinth/modules/restore/views.py +++ /dev/null @@ -1,70 +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 reStore. -""" - -from django.contrib import messages -from django.template.response import TemplateResponse -from django.utils.translation import ugettext as _ - -from .forms import ReStoreForm -from plinth import actions -from plinth.modules import restore - - -def index(request): - """Serve configuration page.""" - status = get_status() - - if request.method == 'POST': - form = ReStoreForm(request.POST, prefix='restore') - if form.is_valid(): - _apply_changes(request, status, form.cleaned_data) - status = get_status() - form = ReStoreForm(initial=status, prefix='restore') - else: - form = ReStoreForm(initial=status, prefix='restore') - - return TemplateResponse(request, 'restore_index.html', - {'title': restore.title, - 'description': restore.description, - 'status': status, - 'form': form}) - - -def get_status(): - """Get the current settings.""" - status = {'enabled': restore.is_enabled()} - return status - - -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('restore', [sub_command]) - restore.service.notify_enabled(None, new_status['enabled']) - modified = True - - if modified: - messages.success(request, _('Configuration updated')) - else: - messages.info(request, _('Setting unchanged')) From 75d35b3d6046e2ae680c9e0bc3aca529470e4bd0 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Sun, 28 Feb 2016 15:06:11 +0530 Subject: [PATCH 11/20] mumble: Use common view for configuration --- plinth/modules/mumble/__init__.py | 14 ++++++ plinth/modules/mumble/forms.py | 30 ------------ plinth/modules/mumble/urls.py | 5 +- plinth/modules/mumble/views.py | 76 ------------------------------- 4 files changed, 17 insertions(+), 108 deletions(-) delete mode 100644 plinth/modules/mumble/forms.py delete mode 100644 plinth/modules/mumble/views.py diff --git a/plinth/modules/mumble/__init__.py b/plinth/modules/mumble/__init__.py index b7f772494..a5ccd5902 100644 --- a/plinth/modules/mumble/__init__.py +++ b/plinth/modules/mumble/__init__.py @@ -21,6 +21,7 @@ Plinth module to configure Mumble server from django.utils.translation import ugettext_lazy as _ +from plinth import actions from plinth import action_utils from plinth import cfg from plinth import service as service_module @@ -60,6 +61,12 @@ def setup(helper, old_version=None): helper.call('post', service.notify_enabled, None, True) +def get_status(): + """Get the current settings from server.""" + return {'enabled': is_enabled(), + 'is_running': is_running()} + + def is_enabled(): """Return whether the module is enabled.""" return action_utils.service_is_enabled('mumble-server') @@ -70,6 +77,13 @@ def is_running(): return action_utils.service_is_running('mumble-server') +def enable(should_enable): + """Enable/disable the module.""" + sub_command = 'enable' if should_enable else 'disable' + actions.superuser_run('mumble', [sub_command]) + service.notify_enabled(None, should_enable) + + def diagnose(): """Run diagnostics and return the results.""" results = [] diff --git a/plinth/modules/mumble/forms.py b/plinth/modules/mumble/forms.py deleted file mode 100644 index 88568e19b..000000000 --- a/plinth/modules/mumble/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 Mumble -""" - -from django import forms -from django.utils.translation import ugettext_lazy as _ - - -class MumbleForm(forms.Form): - """Mumble configuration form.""" - enabled = forms.BooleanField( - label=_('Enable Mumble daemon'), - required=False) diff --git a/plinth/modules/mumble/urls.py b/plinth/modules/mumble/urls.py index 87f27aa88..77aa97da5 100644 --- a/plinth/modules/mumble/urls.py +++ b/plinth/modules/mumble/urls.py @@ -21,9 +21,10 @@ URLs for the Mumble module from django.conf.urls import url -from . import views +from plinth.views import ConfigurationView urlpatterns = [ - url(r'^apps/mumble/$', views.index, name='index'), + url(r'^apps/mumble/$', ConfigurationView.as_view(module_name='mumble'), + name='index'), ] diff --git a/plinth/modules/mumble/views.py b/plinth/modules/mumble/views.py deleted file mode 100644 index 4d67f6458..000000000 --- a/plinth/modules/mumble/views.py +++ /dev/null @@ -1,76 +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 Mumble Server -""" - -from django.contrib import messages -from django.template.response import TemplateResponse -from django.utils.translation import ugettext as _ -import logging - -from .forms import MumbleForm -from plinth import actions -from plinth.modules import mumble - -logger = logging.getLogger(__name__) - - -def index(request): - """Serve configuration page.""" - status = get_status() - - form = None - - if request.method == 'POST': - form = MumbleForm(request.POST, prefix='mumble') - # pylint: disable=E1101 - if form.is_valid(): - _apply_changes(request, status, form.cleaned_data) - status = get_status() - form = MumbleForm(initial=status, prefix='mumble') - else: - form = MumbleForm(initial=status, prefix='mumble') - - return TemplateResponse(request, 'mumble.html', - {'title': mumble.title, - 'description': mumble.description, - 'status': status, - 'form': form}) - - -def get_status(): - """Get the current settings from server.""" - return {'enabled': mumble.is_enabled(), - 'is_running': mumble.is_running()} - - -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('mumble', [sub_command]) - mumble.service.notify_enabled(None, new_status['enabled']) - modified = True - - if modified: - messages.success(request, _('Configuration updated')) - else: - messages.info(request, _('Setting unchanged')) From 6a462cecc8b83d2afb9c96730e99e476576c1f88 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Sun, 28 Feb 2016 15:11:48 +0530 Subject: [PATCH 12/20] privoxy: Use common view for configuration --- plinth/modules/privoxy/__init__.py | 13 +++++ plinth/modules/privoxy/forms.py | 30 ------------ plinth/modules/privoxy/urls.py | 5 +- plinth/modules/privoxy/views.py | 78 ------------------------------ 4 files changed, 16 insertions(+), 110 deletions(-) delete mode 100644 plinth/modules/privoxy/forms.py delete mode 100644 plinth/modules/privoxy/views.py diff --git a/plinth/modules/privoxy/__init__.py b/plinth/modules/privoxy/__init__.py index eaf0d20d1..4416d8f53 100644 --- a/plinth/modules/privoxy/__init__.py +++ b/plinth/modules/privoxy/__init__.py @@ -71,6 +71,12 @@ def setup(helper, old_version=None): helper.call('post', service.notify_enabled, None, True) +def get_status(): + """Get the current settings from server.""" + return {'enabled': is_enabled(), + 'is_running': is_running()} + + def is_enabled(): """Return whether the module is enabled.""" return action_utils.service_is_enabled('privoxy') @@ -81,6 +87,13 @@ def is_running(): return action_utils.service_is_running('privoxy') +def enable(should_enable): + """Enable/disable the module.""" + sub_command = 'enable' if should_enable else 'disable' + actions.superuser_run('privoxy', [sub_command]) + service.notify_enabled(None, should_enable) + + def diagnose(): """Run diagnostics and return the results.""" results = [] diff --git a/plinth/modules/privoxy/forms.py b/plinth/modules/privoxy/forms.py deleted file mode 100644 index e22b99d27..000000000 --- a/plinth/modules/privoxy/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 Privoxy. -""" - -from django import forms -from django.utils.translation import ugettext_lazy as _ - - -class PrivoxyForm(forms.Form): - """Privoxy configuration form.""" - enabled = forms.BooleanField( - label=_('Enable Privoxy'), - required=False) diff --git a/plinth/modules/privoxy/urls.py b/plinth/modules/privoxy/urls.py index 3ca303381..a4a60ca39 100644 --- a/plinth/modules/privoxy/urls.py +++ b/plinth/modules/privoxy/urls.py @@ -21,9 +21,10 @@ URLs for the Privoxy module. from django.conf.urls import url -from . import views +from plinth.views import ConfigurationView urlpatterns = [ - url(r'^apps/privoxy/$', views.index, name='index'), + url(r'^apps/privoxy/$', ConfigurationView.as_view(module_name='privoxy'), + name='index'), ] diff --git a/plinth/modules/privoxy/views.py b/plinth/modules/privoxy/views.py deleted file mode 100644 index 853f8709f..000000000 --- a/plinth/modules/privoxy/views.py +++ /dev/null @@ -1,78 +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 Privoxy Server. -""" - -from django.contrib import messages -from django.template.response import TemplateResponse -from django.utils.translation import ugettext as _ -import logging - -from .forms import PrivoxyForm -from plinth import actions -from plinth.modules import privoxy - -logger = logging.getLogger(__name__) - - -def index(request): - """Serve configuration page.""" - status = get_status() - - form = None - - if request.method == 'POST': - form = PrivoxyForm(request.POST, prefix='privoxy') - # pylint: disable=E1101 - if form.is_valid(): - _apply_changes(request, status, form.cleaned_data) - status = get_status() - form = PrivoxyForm(initial=status, prefix='privoxy') - else: - form = PrivoxyForm(initial=status, prefix='privoxy') - - return TemplateResponse(request, 'privoxy.html', - {'title': privoxy.title, - 'description': privoxy.description, - 'status': status, - 'form': form}) - - -def get_status(): - """Get the current settings from server.""" - status = {'enabled': privoxy.is_enabled(), - 'is_running': privoxy.is_running()} - - return status - - -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('privoxy', [sub_command]) - privoxy.service.notify_enabled(None, new_status['enabled']) - modified = True - - if modified: - messages.success(request, _('Configuration updated')) - else: - messages.info(request, _('Setting unchanged')) From ab96bc7068e157e79a41b98c479a0489fd244940 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Sun, 28 Feb 2016 15:18:19 +0530 Subject: [PATCH 13/20] repro: Use common view for configuration --- plinth/modules/repro/__init__.py | 13 ++++++ plinth/modules/repro/forms.py | 30 ------------- plinth/modules/repro/urls.py | 5 ++- plinth/modules/repro/views.py | 72 -------------------------------- 4 files changed, 16 insertions(+), 104 deletions(-) delete mode 100644 plinth/modules/repro/forms.py delete mode 100644 plinth/modules/repro/views.py diff --git a/plinth/modules/repro/__init__.py b/plinth/modules/repro/__init__.py index 0a72adcf8..586923be8 100644 --- a/plinth/modules/repro/__init__.py +++ b/plinth/modules/repro/__init__.py @@ -74,6 +74,12 @@ def setup(helper, old_version=None): helper.call('post', service.notify_enabled, None, True) +def get_status(): + """Get the current service status.""" + return {'enabled': is_enabled(), + 'is_running': is_running()} + + def is_enabled(): """Return whether the service is enabled.""" return action_utils.service_is_enabled('repro') @@ -84,6 +90,13 @@ def is_running(): return action_utils.service_is_running('repro') +def enable(should_enable): + """Enable/disable the module.""" + sub_command = 'enable' if should_enable else 'disable' + actions.superuser_run('repro', [sub_command]) + service.notify_enabled(None, should_enable) + + def diagnose(): """Run diagnostics and return the results.""" results = [] diff --git a/plinth/modules/repro/forms.py b/plinth/modules/repro/forms.py deleted file mode 100644 index b584701cd..000000000 --- a/plinth/modules/repro/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 repro module. -""" - -from django import forms -from django.utils.translation import ugettext_lazy as _ - - -class ReproForm(forms.Form): - """Configuration form.""" - enabled = forms.BooleanField( - label=_('Enable repro service'), - required=False) diff --git a/plinth/modules/repro/urls.py b/plinth/modules/repro/urls.py index d87f8136b..aeff7f51a 100644 --- a/plinth/modules/repro/urls.py +++ b/plinth/modules/repro/urls.py @@ -21,9 +21,10 @@ URLs for the repro module. from django.conf.urls import url -from . import views +from plinth.views import ConfigurationView urlpatterns = [ - url(r'^apps/repro/$', views.index, name='index'), + url(r'^apps/repro/$', ConfigurationView.as_view(module_name='repro'), + name='index'), ] diff --git a/plinth/modules/repro/views.py b/plinth/modules/repro/views.py deleted file mode 100644 index 407a96b0c..000000000 --- a/plinth/modules/repro/views.py +++ /dev/null @@ -1,72 +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 . -# - -""" -Views for repro module. -""" - -from django.contrib import messages -from django.template.response import TemplateResponse -from django.utils.translation import ugettext as _ - -from .forms import ReproForm -from plinth import actions -from plinth.modules import repro - - -def index(request): - """Serve configuration page.""" - status = get_status() - - form = None - - if request.method == 'POST': - form = ReproForm(request.POST, prefix='repro') - if form.is_valid(): - _apply_changes(request, status, form.cleaned_data) - status = get_status() - form = ReproForm(initial=status, prefix='repro') - else: - form = ReproForm(initial=status, prefix='repro') - - return TemplateResponse(request, 'repro.html', - {'title': repro.title, - 'description': repro.description, - 'status': status, - 'form': form}) - - -def get_status(): - """Get the current service status.""" - return {'enabled': repro.is_enabled(), - 'is_running': repro.is_running()} - - -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('repro', [sub_command]) - repro.service.notify_enabled(None, new_status['enabled']) - modified = True - - if modified: - messages.success(request, _('Configuration updated')) - else: - messages.info(request, _('Setting unchanged')) From 73c7d8e89e2ea99c1addbfc3c711c6a3403d5ee9 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Sun, 28 Feb 2016 16:20:43 +0530 Subject: [PATCH 14/20] avahi: Use common view for configuration --- plinth/modules/avahi/__init__.py | 14 ++++++ plinth/modules/avahi/forms.py | 30 ------------- plinth/modules/avahi/urls.py | 5 ++- plinth/modules/avahi/views.py | 75 -------------------------------- 4 files changed, 17 insertions(+), 107 deletions(-) delete mode 100644 plinth/modules/avahi/forms.py delete mode 100644 plinth/modules/avahi/views.py diff --git a/plinth/modules/avahi/__init__.py b/plinth/modules/avahi/__init__.py index c4c0970bc..f53ce9566 100644 --- a/plinth/modules/avahi/__init__.py +++ b/plinth/modules/avahi/__init__.py @@ -21,6 +21,7 @@ Plinth module for service discovery. from django.utils.translation import ugettext_lazy as _ +from plinth import actions from plinth import action_utils from plinth import cfg from plinth import service as service_module @@ -65,6 +66,12 @@ def setup(helper, old_version=False): helper.install(['avahi-daemon']) +def get_status(): + """Get the current settings from server.""" + return {'enabled': is_enabled(), + 'is_running': is_running()} + + def is_enabled(): """Return whether the module is enabled.""" return action_utils.service_is_enabled('avahi-daemon') @@ -73,3 +80,10 @@ def is_enabled(): def is_running(): """Return whether the service is running.""" return action_utils.service_is_running('avahi-daemon') + + +def enable(should_enable): + """Enable/disable the module.""" + sub_command = 'enable' if should_enable else 'disable' + actions.superuser_run('avahi', [sub_command]) + service.notify_enabled(None, should_enable) diff --git a/plinth/modules/avahi/forms.py b/plinth/modules/avahi/forms.py deleted file mode 100644 index 66776d0c0..000000000 --- a/plinth/modules/avahi/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 . -# - -""" -Plinth module for service discovery forms. -""" - -from django import forms -from django.utils.translation import ugettext_lazy as _ - - -class ServiceDiscoveryForm(forms.Form): - """Service discovery form.""" - enabled = forms.BooleanField( - label=_('Enable service discovery'), - required=False) diff --git a/plinth/modules/avahi/urls.py b/plinth/modules/avahi/urls.py index d9f84d89d..9a86c45f6 100644 --- a/plinth/modules/avahi/urls.py +++ b/plinth/modules/avahi/urls.py @@ -21,9 +21,10 @@ URLs for the service discovery module. from django.conf.urls import url -from . import views +from plinth.views import ConfigurationView urlpatterns = [ - url(r'^sys/avahi/$', views.index, name='index'), + url(r'^sys/avahi/$', ConfigurationView.as_view(module_name='avahi'), + name='index'), ] diff --git a/plinth/modules/avahi/views.py b/plinth/modules/avahi/views.py deleted file mode 100644 index 77751abca..000000000 --- a/plinth/modules/avahi/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 service discovery views. -""" - -from django.contrib import messages -from django.template.response import TemplateResponse -from django.utils.translation import ugettext as _ -import logging - -from .forms import ServiceDiscoveryForm -from plinth import actions -from plinth.modules import avahi - - -logger = logging.getLogger(__name__) # pylint: disable=C0103 - - -def index(request): - """Serve configuration page.""" - status = get_status() - - form = None - - if request.method == 'POST': - form = ServiceDiscoveryForm(request.POST, prefix='avahi') - if form.is_valid(): - _apply_changes(request, status, form.cleaned_data) - status = get_status() - form = ServiceDiscoveryForm(initial=status, prefix='avahi') - else: - form = ServiceDiscoveryForm(initial=status, prefix='avahi') - - return TemplateResponse(request, 'avahi.html', - {'title': avahi.title, - 'description': avahi.description, - 'status': status, - 'form': form}) - - -def get_status(): - """Get the current settings from server.""" - return {'enabled': avahi.is_enabled(), - 'is_running': avahi.is_running()} - - -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' - modified = True - actions.superuser_run('avahi', [sub_command]) - avahi.service.notify_enabled(None, new_status['enabled']) - messages.success(request, _('Configuration updated')) - - if not modified: - messages.info(request, _('Setting unchanged')) From 7385bebb89810bad2c157630091b35a203121547 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Sun, 28 Feb 2016 17:18:34 +0530 Subject: [PATCH 15/20] transmission: Use common view for configuration --- plinth/modules/transmission/__init__.py | 23 +++++++ plinth/modules/transmission/forms.py | 8 +-- plinth/modules/transmission/urls.py | 5 +- plinth/modules/transmission/views.py | 82 ++++++------------------- 4 files changed, 48 insertions(+), 70 deletions(-) diff --git a/plinth/modules/transmission/__init__.py b/plinth/modules/transmission/__init__.py index aed1380ed..c11c2821e 100644 --- a/plinth/modules/transmission/__init__.py +++ b/plinth/modules/transmission/__init__.py @@ -21,6 +21,7 @@ Plinth module to configure Transmission server from django.utils.translation import ugettext_lazy as _ import json +import socket from plinth import actions from plinth import action_utils @@ -42,6 +43,8 @@ description = [ service = None +TRANSMISSION_CONFIG = '/etc/transmission-daemon/settings.json' + def init(): """Intialize the Transmission module.""" @@ -67,6 +70,19 @@ def setup(helper, old_version=None): helper.call('post', service.notify_enabled, None, True) +def get_status(): + """Get the current settings from Transmission server.""" + configuration = open(TRANSMISSION_CONFIG, 'r').read() + status = json.loads(configuration) + status = {key.translate(str.maketrans({'-': '_'})): value + for key, value in status.items()} + status['enabled'] = is_enabled() + status['is_running'] = is_running() + status['hostname'] = socket.gethostname() + + return status + + def is_enabled(): """Return whether the module is enabled.""" return (action_utils.service_is_enabled('transmission-daemon') and @@ -78,6 +94,13 @@ def is_running(): return action_utils.service_is_running('transmission-daemon') +def enable(should_enable): + """Enable/disable the module.""" + sub_command = 'enable' if should_enable else 'disable' + actions.superuser_run('transmission', [sub_command]) + service.notify_enabled(None, should_enable) + + def diagnose(): """Run diagnostics and return the results.""" results = [] diff --git a/plinth/modules/transmission/forms.py b/plinth/modules/transmission/forms.py index 0960e8342..6eaa42928 100644 --- a/plinth/modules/transmission/forms.py +++ b/plinth/modules/transmission/forms.py @@ -22,13 +22,11 @@ Plinth module for configuring Transmission. from django import forms from django.utils.translation import ugettext_lazy as _ +from plinth.forms import ConfigurationForm -class TransmissionForm(forms.Form): # pylint: disable=W0232 + +class TransmissionForm(ConfigurationForm): # pylint: disable=W0232 """Transmission configuration form""" - enabled = forms.BooleanField( - label=_('Enable Transmission daemon'), - required=False) - download_dir = forms.CharField( label=_('Download directory'), help_text=_('Directory where downloads are saved. If you change the \ diff --git a/plinth/modules/transmission/urls.py b/plinth/modules/transmission/urls.py index e3ff718f3..3ab28942f 100644 --- a/plinth/modules/transmission/urls.py +++ b/plinth/modules/transmission/urls.py @@ -21,9 +21,10 @@ URLs for the Transmission module. from django.conf.urls import url -from . import views +from .views import ConfigurationView urlpatterns = [ - url(r'^apps/transmission/$', views.index, name='index'), + url(r'^apps/transmission/$', + ConfigurationView.as_view(module_name='transmission'), name='index'), ] diff --git a/plinth/modules/transmission/views.py b/plinth/modules/transmission/views.py index c65c81013..72e520b91 100644 --- a/plinth/modules/transmission/views.py +++ b/plinth/modules/transmission/views.py @@ -20,81 +20,37 @@ Plinth module for configuring Transmission Server """ from django.contrib import messages -from django.template.response import TemplateResponse from django.utils.translation import ugettext as _ import json import logging -import socket from .forms import TransmissionForm from plinth import actions -from plinth.modules import transmission +from plinth import views logger = logging.getLogger(__name__) -TRANSMISSION_CONFIG = '/etc/transmission-daemon/settings.json' - -def index(request): +class ConfigurationView(views.ConfigurationView): """Serve configuration page.""" - status = get_status() + form_class = TransmissionForm - form = None + def apply_changes(self, old_status, new_status): + """Apply the changes submitted in the form.""" + modified = super().apply_changes(old_status, new_status) - if request.method == 'POST': - form = TransmissionForm(request.POST, prefix='transmission') - # pylint: disable=E1101 - if form.is_valid(): - _apply_changes(request, status, form.cleaned_data) - status = get_status() - form = TransmissionForm(initial=status, prefix='transmission') - else: - form = TransmissionForm(initial=status, prefix='transmission') + if old_status['download_dir'] != new_status['download_dir'] or \ + old_status['rpc_username'] != new_status['rpc_username'] or \ + old_status['rpc_password'] != new_status['rpc_password']: + new_configuration = { + 'download-dir': new_status['download_dir'], + 'rpc-username': new_status['rpc_username'], + 'rpc-password': new_status['rpc_password'], + } - return TemplateResponse(request, 'transmission.html', - {'title': transmission.title, - 'description': transmission.description, - 'status': status, - 'form': form}) + actions.superuser_run('transmission', ['merge-configuration'], + input=json.dumps(new_configuration).encode()) + messages.success(self.request, _('Configuration updated')) + return True - -def get_status(): - """Get the current settings from Transmission server.""" - configuration = open(TRANSMISSION_CONFIG, 'r').read() - status = json.loads(configuration) - status = {key.translate(str.maketrans({'-': '_'})): value - for key, value in status.items()} - status['enabled'] = transmission.is_enabled() - status['is_running'] = transmission.is_running() - status['hostname'] = socket.gethostname() - - return status - - -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('transmission', [sub_command]) - transmission.service.notify_enabled(None, new_status['enabled']) - modified = True - - if old_status['download_dir'] != new_status['download_dir'] or \ - old_status['rpc_username'] != new_status['rpc_username'] or \ - old_status['rpc_password'] != new_status['rpc_password']: - new_configuration = { - 'download-dir': new_status['download_dir'], - 'rpc-username': new_status['rpc_username'], - 'rpc-password': new_status['rpc_password'], - } - - actions.superuser_run('transmission', ['merge-configuration'], - input=json.dumps(new_configuration).encode()) - modified = True - - if modified: - messages.success(request, _('Configuration updated')) - else: - messages.info(request, _('Setting unchanged')) + return modified From d31de69d36353e45e4b79e54256f8337971286f0 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Sun, 28 Feb 2016 18:51:11 +0530 Subject: [PATCH 16/20] datetime: Use common view for configuration --- plinth/modules/datetime/__init__.py | 13 +++++ plinth/modules/datetime/urls.py | 6 ++- plinth/modules/datetime/views.py | 81 +++++++++-------------------- 3 files changed, 42 insertions(+), 58 deletions(-) diff --git a/plinth/modules/datetime/__init__.py b/plinth/modules/datetime/__init__.py index 0c200169a..b82a92169 100644 --- a/plinth/modules/datetime/__init__.py +++ b/plinth/modules/datetime/__init__.py @@ -59,6 +59,19 @@ def setup(helper, old_version=None): helper.call('post', service.notify_enabled, None, True) +def get_status(): + """Get the current settings from server.""" + return {'enabled': is_enabled(), + 'is_running': is_running(), + 'time_zone': get_current_time_zone()} + + +def get_current_time_zone(): + """Get current time zone.""" + time_zone = open('/etc/timezone').read().rstrip() + return time_zone or 'none' + + def is_enabled(): """Return whether the module is enabled.""" return action_utils.service_is_enabled('ntp') diff --git a/plinth/modules/datetime/urls.py b/plinth/modules/datetime/urls.py index 080e3e103..8840eb403 100644 --- a/plinth/modules/datetime/urls.py +++ b/plinth/modules/datetime/urls.py @@ -21,8 +21,10 @@ URLs for the date and time module from django.conf.urls import url -from . import views +from .views import ConfigurationView + urlpatterns = [ - url(r'^sys/datetime/$', views.index, name='index'), + url(r'^sys/datetime/$', ConfigurationView.as_view(module_name='datetime'), + name='index'), ] diff --git a/plinth/modules/datetime/views.py b/plinth/modules/datetime/views.py index f687e1506..cb2ac9a90 100644 --- a/plinth/modules/datetime/views.py +++ b/plinth/modules/datetime/views.py @@ -20,74 +20,43 @@ Plinth module for configuring date and time """ from django.contrib import messages -from django.template.response import TemplateResponse from django.utils.translation import ugettext as _ import logging from .forms import DateTimeForm from plinth import actions +from plinth import views from plinth.modules import datetime logger = logging.getLogger(__name__) -def index(request): +class ConfigurationView(views.ConfigurationView): """Serve configuration page.""" - status = get_status() + form_class = DateTimeForm - form = None + def apply_changes(self, old_status, new_status): + """Apply the changes.""" + modified = False - if request.method == 'POST': - form = DateTimeForm(request.POST, prefix='datetime') - # pylint: disable=E1101 - if form.is_valid(): - _apply_changes(request, status, form.cleaned_data) - status = get_status() - form = DateTimeForm(initial=status, prefix='datetime') - else: - form = DateTimeForm(initial=status, prefix='datetime') + if old_status['enabled'] != new_status['enabled']: + sub_command = 'enable' if new_status['enabled'] else 'disable' + modified = True + actions.superuser_run('datetime', [sub_command]) + datetime.service.notify_enabled(None, new_status['enabled']) + messages.success(self.request, _('Configuration updated')) - return TemplateResponse(request, 'datetime.html', - {'title': datetime.title, - 'description': datetime.description, - 'status': status, - 'form': form}) + if old_status['time_zone'] != new_status['time_zone'] and \ + new_status['time_zone'] != 'none': + modified = True + try: + actions.superuser_run( + 'timezone-change', [new_status['time_zone']]) + except Exception as exception: + messages.error( + self.request, _('Error setting time zone: {exception}') + .format(exception=exception)) + else: + messages.success(self.request, _('Time zone set')) - -def get_status(): - """Get the current settings from server.""" - return {'enabled': datetime.is_enabled(), - 'is_running': datetime.is_running(), - 'time_zone': get_current_time_zone()} - - -def get_current_time_zone(): - """Get current time zone.""" - time_zone = open('/etc/timezone').read().rstrip() - return time_zone or 'none' - - -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' - modified = True - actions.superuser_run('datetime', [sub_command]) - datetime.service.notify_enabled(None, new_status['enabled']) - messages.success(request, _('Configuration updated')) - - if old_status['time_zone'] != new_status['time_zone'] and \ - new_status['time_zone'] != 'none': - modified = True - try: - actions.superuser_run('timezone-change', [new_status['time_zone']]) - except Exception as exception: - messages.error(request, _('Error setting time zone: {exception}') - .format(exception=exception)) - else: - messages.success(request, _('Time zone set')) - - if not modified: - messages.info(request, _('Setting unchanged')) + return modified From a0e676c51cb209b7d8f92ef3ed7c9aa898b05721 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Sun, 28 Feb 2016 18:58:58 +0530 Subject: [PATCH 17/20] ikiwiki: Use common view for configuration --- plinth/modules/ikiwiki/__init__.py | 12 +++++++ plinth/modules/ikiwiki/forms.py | 7 ----- plinth/modules/ikiwiki/urls.py | 3 +- plinth/modules/ikiwiki/views.py | 50 +++++------------------------- 4 files changed, 22 insertions(+), 50 deletions(-) diff --git a/plinth/modules/ikiwiki/__init__.py b/plinth/modules/ikiwiki/__init__.py index 05f105743..f6bc67ce3 100644 --- a/plinth/modules/ikiwiki/__init__.py +++ b/plinth/modules/ikiwiki/__init__.py @@ -65,11 +65,23 @@ def setup(helper, old_version=None): helper.call('post', service.notify_enabled, None, True) +def get_status(): + """Get the current setting.""" + return {'enabled': is_enabled()} + + def is_enabled(): """Return whether the module is enabled.""" return action_utils.webserver_is_enabled('ikiwiki-plinth') +def enable(should_enable): + """Enable/disable the module.""" + sub_command = 'enable' if should_enable else 'disable' + actions.superuser_run('ikiwiki', [sub_command]) + service.notify_enabled(None, should_enable) + + def diagnose(): """Run diagnostics and return the results.""" results = [] diff --git a/plinth/modules/ikiwiki/forms.py b/plinth/modules/ikiwiki/forms.py index 11d3c8020..a5c4a7f27 100644 --- a/plinth/modules/ikiwiki/forms.py +++ b/plinth/modules/ikiwiki/forms.py @@ -23,13 +23,6 @@ from django import forms from django.utils.translation import ugettext_lazy as _ -class IkiwikiForm(forms.Form): - """ikiwiki configuration form.""" - enabled = forms.BooleanField( - label=_('Enable ikiwiki'), - required=False) - - class IkiwikiCreateForm(forms.Form): """Form to create a wiki or blog.""" site_type = forms.ChoiceField( diff --git a/plinth/modules/ikiwiki/urls.py b/plinth/modules/ikiwiki/urls.py index 59bf30236..65854ae88 100644 --- a/plinth/modules/ikiwiki/urls.py +++ b/plinth/modules/ikiwiki/urls.py @@ -25,7 +25,8 @@ from . import views urlpatterns = [ - url(r'^apps/ikiwiki/$', views.index, name='index'), + url(r'^apps/ikiwiki/$', + views.ConfigurationView.as_view(module_name='ikiwiki'), name='index'), url(r'^apps/ikiwiki/manage/$', views.manage, name='manage'), url(r'^apps/ikiwiki/(?P[\w.@+-]+)/delete/$', views.delete, name='delete'), diff --git a/plinth/modules/ikiwiki/views.py b/plinth/modules/ikiwiki/views.py index 27c1a855a..df806bdb6 100644 --- a/plinth/modules/ikiwiki/views.py +++ b/plinth/modules/ikiwiki/views.py @@ -25,9 +25,9 @@ from django.shortcuts import redirect from django.template.response import TemplateResponse from django.utils.translation import ugettext as _, ugettext_lazy -from .forms import IkiwikiForm, IkiwikiCreateForm +from .forms import IkiwikiCreateForm from plinth import actions -from plinth.modules import ikiwiki +from plinth import views subsubmenu = [{'url': reverse_lazy('ikiwiki:index'), @@ -38,48 +38,14 @@ subsubmenu = [{'url': reverse_lazy('ikiwiki:index'), 'text': ugettext_lazy('Create')}] -def index(request): +class ConfigurationView(views.ConfigurationView): """Serve configuration page.""" - status = get_status() + def get_context_data(self, **kwargs): + """Return the context data for rendering the template view.""" + if 'subsubmenu' not in kwargs: + kwargs['subsubmenu'] = subsubmenu - form = None - - if request.method == 'POST': - form = IkiwikiForm(request.POST, prefix='ikiwiki') - if form.is_valid(): - _apply_changes(request, status, form.cleaned_data) - status = get_status() - form = IkiwikiForm(initial=status, prefix='ikiwiki') - else: - form = IkiwikiForm(initial=status, prefix='ikiwiki') - - return TemplateResponse(request, 'ikiwiki.html', - {'title': ikiwiki.title, - 'description': ikiwiki.description, - 'status': status, - 'form': form, - 'subsubmenu': subsubmenu}) - - -def get_status(): - """Get the current setting.""" - return {'enabled': ikiwiki.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('ikiwiki', [sub_command]) - ikiwiki.service.notify_enabled(None, new_status['enabled']) - modified = True - - if modified: - messages.success(request, _('Configuration updated')) - else: - messages.info(request, _('Setting unchanged')) + return super().get_context_data(**kwargs) def manage(request): From 711892486e6625b043dc485e49b39c3263d49433 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Sun, 28 Feb 2016 19:17:26 +0530 Subject: [PATCH 18/20] upgrades: Use common view for configuration --- plinth/modules/upgrades/__init__.py | 17 ++++++ plinth/modules/upgrades/urls.py | 3 +- plinth/modules/upgrades/views.py | 85 ++++++++++++----------------- 3 files changed, 54 insertions(+), 51 deletions(-) diff --git a/plinth/modules/upgrades/__init__.py b/plinth/modules/upgrades/__init__.py index 1f58ad821..e8e84ac38 100644 --- a/plinth/modules/upgrades/__init__.py +++ b/plinth/modules/upgrades/__init__.py @@ -50,3 +50,20 @@ def setup(helper, old_version=None): """Install and configure the module.""" helper.install(['unattended-upgrades']) helper.call('post', actions.superuser_run, 'upgrades', ['enable-auto']) + + +def get_status(): + """Return the current status.""" + return {'auto_upgrades_enabled': 'is_enabled'} + + +def is_enabled(): + """Return whether the module is enabled.""" + output = actions.run('upgrades', ['check-auto']) + return 'True' in output.split() + + +def enable(should_enable): + """Enable/disable the module.""" + option = 'enable-auto' if should_enable else 'disable-auto' + actions.superuser_run('upgrades', [option]) diff --git a/plinth/modules/upgrades/urls.py b/plinth/modules/upgrades/urls.py index 9457c17dc..eba0e70b8 100644 --- a/plinth/modules/upgrades/urls.py +++ b/plinth/modules/upgrades/urls.py @@ -25,6 +25,7 @@ from . import views urlpatterns = [ - url(r'^sys/upgrades/$', views.index, name='index'), + url(r'^sys/upgrades/$', + views.ConfigurationView.as_view(module_name='upgrades'), name='index'), url(r'^sys/upgrades/upgrade/$', views.upgrade, name='upgrade'), ] diff --git a/plinth/modules/upgrades/views.py b/plinth/modules/upgrades/views.py index 81b0a4ba3..37b63bc82 100644 --- a/plinth/modules/upgrades/views.py +++ b/plinth/modules/upgrades/views.py @@ -27,6 +27,7 @@ import subprocess from .forms import ConfigureForm from plinth import actions +from plinth import views from plinth.errors import ActionError from plinth.modules import upgrades @@ -39,26 +40,43 @@ LOG_FILE = '/var/log/unattended-upgrades/unattended-upgrades.log' LOCK_FILE = '/var/log/dpkg/lock' -def index(request): - """Serve the configuration form.""" - status = get_status() +class ConfigurationView(views.ConfigurationView): + """Serve configuration page.""" + form_class = ConfigureForm - form = None + def get_context_data(self, **kwargs): + """Return the context data for rendering the template view.""" + if 'subsubmenu' not in kwargs: + kwargs['subsubmenu'] = subsubmenu - if request.method == 'POST': - form = ConfigureForm(request.POST, prefix='upgrades') - if form.is_valid(): - _apply_changes(request, status, form.cleaned_data) - status = get_status() - form = ConfigureForm(initial=status, prefix='upgrades') - else: - form = ConfigureForm(initial=status, prefix='upgrades') + return super().get_context_data(**kwargs) - return TemplateResponse(request, 'upgrades_configure.html', - {'title': upgrades.title, - 'description': upgrades.description, - 'form': form, - 'subsubmenu': subsubmenu}) + def get_template_names(self): + """Return the list of template names for the view.""" + return ['upgrades_configure.html'] + + def apply_changes(self, old_status, new_status): + """Apply the form changes.""" + if old_status['auto_upgrades_enabled'] \ + == new_status['auto_upgrades_enabled']: + return False + + try: + upgrades.enable(new_status['auto_upgrades_enabled']) + except ActionError as exception: + error = exception.args[2] + messages.error( + self.request, + _('Error when configuring unattended-upgrades: {error}') + .format(error=error)) + return True + + if new_status['auto_upgrades_enabled']: + messages.success(self.request, _('Automatic upgrades enabled')) + else: + messages.success(self.request, _('Automatic upgrades disabled')) + + return True def is_package_manager_busy(): @@ -97,36 +115,3 @@ def upgrade(request): 'subsubmenu': subsubmenu, 'is_busy': is_busy, 'log': get_log()}) - - -def get_status(): - """Return the current status.""" - output = actions.run('upgrades', ['check-auto']) - return {'auto_upgrades_enabled': 'True' in output.split()} - - -def _apply_changes(request, old_status, new_status): - """Apply the form changes.""" - if old_status['auto_upgrades_enabled'] \ - == new_status['auto_upgrades_enabled']: - messages.info(request, _('Setting unchanged')) - return - - if new_status['auto_upgrades_enabled']: - option = 'enable-auto' - else: - option = 'disable-auto' - - try: - actions.superuser_run('upgrades', [option]) - except ActionError as exception: - error = exception.args[2] - messages.error( - request, _('Error when configuring unattended-upgrades: {error}') - .format(error=error)) - return - - if option == 'enable-auto': - messages.success(request, _('Automatic upgrades enabled')) - else: - messages.success(request, _('Automatic upgrades disabled')) From f04e1c1657ef22aa9cb203cae66e531fafc41013 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Sun, 28 Feb 2016 19:27:49 +0530 Subject: [PATCH 19/20] Minor PEP8 & spelling fixes in various modules --- plinth/modules/apps/apps.py | 4 ++-- plinth/modules/config/config.py | 2 +- plinth/modules/firewall/views.py | 2 +- plinth/modules/help/help.py | 1 - plinth/modules/openvpn/views.py | 2 +- plinth/modules/tor/views.py | 2 +- plinth/modules/users/__init__.py | 2 -- 7 files changed, 6 insertions(+), 9 deletions(-) diff --git a/plinth/modules/apps/apps.py b/plinth/modules/apps/apps.py index 39c77c43f..9d90af549 100644 --- a/plinth/modules/apps/apps.py +++ b/plinth/modules/apps/apps.py @@ -23,8 +23,8 @@ from plinth import cfg def init(): """Initailize the apps module""" - cfg.main_menu.add_urlname(_('Apps'), 'glyphicon-download-alt', 'apps:index', - 80) + cfg.main_menu.add_urlname(_('Apps'), 'glyphicon-download-alt', + 'apps:index', 80) def index(request): diff --git a/plinth/modules/config/config.py b/plinth/modules/config/config.py index 4957589bd..8f75bca2a 100644 --- a/plinth/modules/config/config.py +++ b/plinth/modules/config/config.py @@ -226,7 +226,7 @@ def _apply_changes(request, old_status, new_status): request.session[translation.LANGUAGE_SESSION_KEY] = language except Exception as exception: messages.error(request, _('Error setting language: {exception}') - .format(exception=exception)) + .format(exception=exception)) else: messages.success(request, _('Language changed')) diff --git a/plinth/modules/firewall/views.py b/plinth/modules/firewall/views.py index 3dab988ab..8ed984741 100644 --- a/plinth/modules/firewall/views.py +++ b/plinth/modules/firewall/views.py @@ -26,7 +26,7 @@ import plinth.service as service_module def index(request): - """Serve introcution page""" + """Serve introduction page""" if not firewall.get_enabled_status(): return TemplateResponse(request, 'firewall.html', {'title': firewall.title, diff --git a/plinth/modules/help/help.py b/plinth/modules/help/help.py index 0f8aa3f52..1db714089 100644 --- a/plinth/modules/help/help.py +++ b/plinth/modules/help/help.py @@ -20,7 +20,6 @@ Help module for Plinth. """ import os -from gettext import gettext as _ from django.http import Http404 from django.template.response import TemplateResponse from django.utils.translation import ugettext as _, ugettext_lazy diff --git a/plinth/modules/openvpn/views.py b/plinth/modules/openvpn/views.py index ea1c6aefa..ea460589c 100644 --- a/plinth/modules/openvpn/views.py +++ b/plinth/modules/openvpn/views.py @@ -116,7 +116,7 @@ def _collect_setup_result(request): return_code = setup_process.poll() # Setup process is not complete yet - if return_code == None: + if return_code is None: return if not return_code: diff --git a/plinth/modules/tor/views.py b/plinth/modules/tor/views.py index 58e513a1f..d041c7155 100644 --- a/plinth/modules/tor/views.py +++ b/plinth/modules/tor/views.py @@ -108,7 +108,7 @@ def _collect_config_result(request): return_code = config_process.poll() # Config process is not complete yet - if return_code == None: + if return_code is None: return status = tor.get_status() diff --git a/plinth/modules/users/__init__.py b/plinth/modules/users/__init__.py index b7c6c8ca1..62bb174bc 100644 --- a/plinth/modules/users/__init__.py +++ b/plinth/modules/users/__init__.py @@ -67,5 +67,3 @@ def _diagnose_ldap_entry(search_item): return [_('Check LDAP entry "{search_item}"') .format(search_item=search_item), result] - - From 2078e209d111c2c68682a61e911cdb02a2af4548 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Sun, 28 Feb 2016 19:54:24 +0530 Subject: [PATCH 20/20] views: Minor adjustment to module load order --- plinth/views.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plinth/views.py b/plinth/views.py index 47f7518c8..669506d0c 100644 --- a/plinth/views.py +++ b/plinth/views.py @@ -29,7 +29,7 @@ from django.utils.translation import ugettext as _ import time from . import forms -from . import module_loader +import plinth def index(request): @@ -57,7 +57,7 @@ class ConfigurationView(FormView): def get_module(self): """Return the module associated with the view.""" - return module_loader.loaded_modules[self.get_module_name()] + return plinth.module_loader.loaded_modules[self.get_module_name()] def get_initial(self): """Return the status of the module to fill in the form."""