diff --git a/plinth/modules/upgrades/__init__.py b/plinth/modules/upgrades/__init__.py index 2e5110a16..795b88e1b 100644 --- a/plinth/modules/upgrades/__init__.py +++ b/plinth/modules/upgrades/__init__.py @@ -21,14 +21,32 @@ Plinth module for upgrades from django.utils.translation import ugettext_lazy as _ +from plinth import actions from plinth import cfg +version = 1 + +is_essential = 1 + depends = ['system'] +title = _('Software Upgrades') + +description = [ + _('Upgrades install the latest software and security updates. When ' + 'automatic upgrades are enabled, upgrades are automatically run every ' + 'night. You don\'t normally need to start the upgrade process.') +] + def init(): """Initialize the module.""" menu = cfg.main_menu.get('system:index') - menu.add_urlname(_('Software Upgrades'), 'glyphicon-refresh', - 'upgrades:index', 21) + menu.add_urlname(title, 'glyphicon-refresh', 'upgrades:index', 21) + + +def setup(helper, old_version=None): + """Install and configure the module.""" + helper.install(['unattended-upgrades']) + helper.call('post', actions.superuser_run, 'upgrades', ['enable-auto']) diff --git a/plinth/modules/upgrades/templates/upgrades.html b/plinth/modules/upgrades/templates/upgrades.html index 15b0167b2..4cc47be98 100644 --- a/plinth/modules/upgrades/templates/upgrades.html +++ b/plinth/modules/upgrades/templates/upgrades.html @@ -1,4 +1,4 @@ -{% extends 'base.html' %} +{% extends 'app.html' %} {% comment %} # # This file is part of Plinth. @@ -29,17 +29,7 @@ {% endblock %} -{% block content %} - -

{{ title }}

- -

- {% blocktrans trimmed %} - Upgrades install the latest software and security updates. When automatic - upgrades are enabled, upgrades are automatically run every night. You - don't normally need to start the upgrade process. - {% endblocktrans %} -

+{% block configuration %}

{% blocktrans trimmed %} diff --git a/plinth/modules/upgrades/templates/upgrades_configure.html b/plinth/modules/upgrades/templates/upgrades_configure.html index 1ee94ec32..4a4e1c3fe 100644 --- a/plinth/modules/upgrades/templates/upgrades_configure.html +++ b/plinth/modules/upgrades/templates/upgrades_configure.html @@ -1,4 +1,4 @@ -{% extends "base.html" %} +{% extends "app.html" %} {% comment %} # # This file is part of Plinth. @@ -21,9 +21,7 @@ {% load bootstrap %} {% load i18n %} -{% block content %} - -

{{ title }}

+{% block configuration %}
{% csrf_token %} diff --git a/plinth/modules/upgrades/views.py b/plinth/modules/upgrades/views.py index d08d6f291..81b0a4ba3 100644 --- a/plinth/modules/upgrades/views.py +++ b/plinth/modules/upgrades/views.py @@ -21,16 +21,14 @@ Plinth module for upgrades from django.contrib import messages from django.core.urlresolvers import reverse_lazy -from django.shortcuts import redirect from django.template.response import TemplateResponse from django.utils.translation import ugettext as _, ugettext_lazy -from django.views.decorators.http import require_POST import subprocess from .forms import ConfigureForm from plinth import actions -from plinth import package from plinth.errors import ActionError +from plinth.modules import upgrades subsubmenu = [{'url': reverse_lazy('upgrades:index'), 'text': ugettext_lazy('Automatic Upgrades')}, @@ -41,12 +39,6 @@ LOG_FILE = '/var/log/unattended-upgrades/unattended-upgrades.log' LOCK_FILE = '/var/log/dpkg/lock' -def on_install(): - """Enable automatic upgrades after install.""" - actions.superuser_run('upgrades', ['enable-auto']) - - -@package.required(['unattended-upgrades'], on_install=on_install) def index(request): """Serve the configuration form.""" status = get_status() @@ -63,10 +55,12 @@ def index(request): form = ConfigureForm(initial=status, prefix='upgrades') return TemplateResponse(request, 'upgrades_configure.html', - {'title': _('Automatic Upgrades'), + {'title': upgrades.title, + 'description': upgrades.description, 'form': form, 'subsubmenu': subsubmenu}) + def is_package_manager_busy(): """Return whether a package manager is running.""" try: @@ -85,7 +79,6 @@ def get_log(): return None -@package.required(['unattended-upgrades'], on_install=on_install) def upgrade(request): """Serve the upgrade page.""" is_busy = is_package_manager_busy() @@ -99,7 +92,8 @@ def upgrade(request): messages.error(request, _('Starting upgrade failed.')) return TemplateResponse(request, 'upgrades.html', - {'title': _('Package Upgrades'), + {'title': upgrades.title, + 'description': upgrades.description, 'subsubmenu': subsubmenu, 'is_busy': is_busy, 'log': get_log()})