From c539dc6db378419d786aa6f46285c1be0611aa0e Mon Sep 17 00:00:00 2001 From: James Valleroy Date: Mon, 31 Aug 2015 20:41:49 -0400 Subject: [PATCH] upgrades: Move auto upgrades configure form to first tab. Split forms and views into separate files. --- plinth/modules/upgrades/forms.py | 32 ++++++++++ .../templates/upgrades_configure.html | 2 + plinth/modules/upgrades/urls.py | 4 +- .../upgrades/{upgrades.py => views.py} | 63 ++++++++----------- 4 files changed, 63 insertions(+), 38 deletions(-) create mode 100644 plinth/modules/upgrades/forms.py rename plinth/modules/upgrades/{upgrades.py => views.py} (87%) diff --git a/plinth/modules/upgrades/forms.py b/plinth/modules/upgrades/forms.py new file mode 100644 index 000000000..b4f3c8428 --- /dev/null +++ b/plinth/modules/upgrades/forms.py @@ -0,0 +1,32 @@ +# +# 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 unattended-upgrades. +""" + +from django import forms +from gettext import gettext as _ + + +class ConfigureForm(forms.Form): + """Configuration form to enable/disable automatic upgrades.""" + auto_upgrades_enabled = forms.BooleanField( + label=_('Enable automatic upgrades'), required=False, + help_text=_('When enabled, the unattended-upgrades program will be \ +run once per day. It will attempt to perform any package upgrades that are \ +available.')) diff --git a/plinth/modules/upgrades/templates/upgrades_configure.html b/plinth/modules/upgrades/templates/upgrades_configure.html index 06230657a..edff568e2 100644 --- a/plinth/modules/upgrades/templates/upgrades_configure.html +++ b/plinth/modules/upgrades/templates/upgrades_configure.html @@ -22,6 +22,8 @@ {% block content %} +

{{ title }}

+
{% csrf_token %} diff --git a/plinth/modules/upgrades/urls.py b/plinth/modules/upgrades/urls.py index 848570f75..fa54bedb2 100644 --- a/plinth/modules/upgrades/urls.py +++ b/plinth/modules/upgrades/urls.py @@ -25,6 +25,6 @@ from django.conf.urls import patterns, url urlpatterns = patterns( 'plinth.modules.upgrades.upgrades', url(r'^sys/upgrades/$', 'index', name='index'), - url(r'^sys/upgrades/run/$', 'run', name='run'), - url(r'^sys/upgrades/configure/$', 'configure', name='configure'), + url(r'^sys/upgrades/upgrade/$', 'upgrade', name='upgrade'), + url(r'^sys/upgrades/upgrade/run/$', 'run', name='run'), ) diff --git a/plinth/modules/upgrades/upgrades.py b/plinth/modules/upgrades/views.py similarity index 87% rename from plinth/modules/upgrades/upgrades.py rename to plinth/modules/upgrades/views.py index 1839d3feb..b3145383a 100644 --- a/plinth/modules/upgrades/upgrades.py +++ b/plinth/modules/upgrades/views.py @@ -19,22 +19,22 @@ Plinth module for upgrades """ -from django import forms from django.contrib import messages from django.core.urlresolvers import reverse_lazy from django.template.response import TemplateResponse from django.views.decorators.http import require_POST from gettext import gettext as _ +from .forms import ConfigureForm from plinth import actions from plinth import cfg from plinth import package from plinth.errors import ActionError subsubmenu = [{'url': reverse_lazy('upgrades:index'), - 'text': _('Upgrade Packages')}, - {'url': reverse_lazy('upgrades:configure'), - 'text': _('Automatic Upgrades')}] + 'text': _('Automatic Upgrades')}, + {'url': reverse_lazy('upgrades:upgrade'), + 'text': _('Upgrade Packages')}] def init(): @@ -51,7 +51,29 @@ def on_install(): @package.required(['unattended-upgrades'], on_install=on_install) def index(request): - """Serve the index page.""" + """Serve the configuration form.""" + status = get_status() + + form = None + + 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 TemplateResponse(request, 'upgrades_configure.html', + {'title': _('Automatic Upgrades'), + 'form': form, + 'subsubmenu': subsubmenu}) + + +@package.required(['unattended-upgrades'], on_install=on_install) +def upgrade(request): + """Serve the upgrade page.""" return TemplateResponse(request, 'upgrades.html', {'title': _('Package Upgrades'), 'subsubmenu': subsubmenu}) @@ -77,37 +99,6 @@ def run(request): 'upgrades_error': error}) -class ConfigureForm(forms.Form): - """Configuration form to enable/disable automatic upgrades.""" - auto_upgrades_enabled = forms.BooleanField( - label=_('Enable automatic upgrades'), required=False, - help_text=_('When enabled, the unattended-upgrades program will be \ -run once per day. It will attempt to perform any package upgrades that are \ -available.')) - - -@package.required(['unattended-upgrades'], on_install=on_install) -def configure(request): - """Serve the configuration form.""" - status = get_status() - - form = None - - 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 TemplateResponse(request, 'upgrades_configure.html', - {'title': _('Automatic Upgrades'), - 'form': form, - 'subsubmenu': subsubmenu}) - - def get_status(): """Return the current status.""" output = actions.run('upgrades', ['check-auto'])