mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-28 08:03:36 +00:00
upgrades: Move auto upgrades configure form to first tab.
Split forms and views into separate files.
This commit is contained in:
parent
76cdc69099
commit
c539dc6db3
32
plinth/modules/upgrades/forms.py
Normal file
32
plinth/modules/upgrades/forms.py
Normal file
@ -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 <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
"""
|
||||
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.'))
|
||||
@ -22,6 +22,8 @@
|
||||
|
||||
{% block content %}
|
||||
|
||||
<h2>{{ title }}</h2>
|
||||
|
||||
<form class="form" method="post">
|
||||
{% csrf_token %}
|
||||
|
||||
|
||||
@ -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'),
|
||||
)
|
||||
|
||||
@ -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'])
|
||||
Loading…
x
Reference in New Issue
Block a user