Add form for enabling automatic upgrades.

This commit is contained in:
James Valleroy authored and fonfon committed 2015-01-28 19:50:26 +00:00
1 parent 80eff7fd6e
commit 304e2aea62
4 files changed
+122 -3

No files matched your search

@@ -0,0 +1,34 @@
{% extends "base.html" %}
{% comment %}
#
# This file is part of Plinth.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
{% endcomment %}
{% load bootstrap %}
{% block content %}
<form class="form" method="post">
{% csrf_token %}
{{ form|bootstrap }}
<input type="submit" class="btn btn-primary btn-md" value="Update setup"/>
</form>
{% endblock %}
+73 -1
View File
@@ -19,7 +19,10 @@
Plinth module for upgrades
"""
from django import forms
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from django.core.urlresolvers import reverse_lazy
from django.template.response import TemplateResponse
from gettext import gettext as _
@@ -28,6 +31,11 @@ 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')}]
def init():
"""Initialize the module"""
@@ -41,7 +49,8 @@ def init():
def index(request):
"""Serve the index page"""
return TemplateResponse(request, 'upgrades.html',
{'title': _('Package Upgrades')})
{'title': _('Package Upgrades'),
'subsubmenu': subsubmenu})
@login_required
@@ -59,5 +68,68 @@ def run(request):
return TemplateResponse(request, 'upgrades_run.html',
{'title': _('Package Upgrades'),
'subsubmenu': subsubmenu,
'upgrades_output': output,
'upgrades__error': error})
class ConfigureForm(forms.Form):
"""Configuration form"""
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.'))
@login_required
@package.required('unattended-upgrades')
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'])
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'
output = actions.superuser_run('upgrades', [option])
if 'Error' in output:
messages.error(request,
_('Error when configuring unattended-upgrades: %s') %
output)
elif option == 'enable-auto':
messages.success(request, _('Automatic upgrades enabled'))
else:
messages.success(request, _('Automatic upgrades disabled'))
+1
View File
@@ -26,4 +26,5 @@ 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'),
)