mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-03-11 09:04:54 +00:00
upgrades: Show better error messages
- Reduce the number of specialized messages to ease localization and clear way for generalized configuration change handler. Tests: - Update the one or two configuration setting at the same time and notice that a single message is shown. - When no setting is changed and form is submitted, 'settings unchanged' message is shown. - Raise error when enabling/disable auto updates and notice a proper HTML error shown. When other setting is also updated, then one error and one success message is shown. Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
64d754701f
commit
f240c4203c
@ -15,7 +15,7 @@ from django.views.generic.edit import FormView
|
||||
from plinth import __version__
|
||||
from plinth.modules import first_boot, upgrades
|
||||
from plinth.privileged import packages as packages_privileged
|
||||
from plinth.views import AppView
|
||||
from plinth.views import AppView, messages_error
|
||||
|
||||
from . import privileged
|
||||
from .forms import BackportsFirstbootForm, ConfigureForm, UpdateFirstbootForm
|
||||
@ -56,6 +56,8 @@ class UpgradesConfigurationView(AppView):
|
||||
old_status = form.initial
|
||||
new_status = form.cleaned_data
|
||||
|
||||
is_changed = False
|
||||
|
||||
if old_status['auto_upgrades_enabled'] \
|
||||
!= new_status['auto_upgrades_enabled']:
|
||||
|
||||
@ -64,29 +66,21 @@ class UpgradesConfigurationView(AppView):
|
||||
privileged.enable_auto()
|
||||
else:
|
||||
privileged.disable_auto()
|
||||
except Exception as exception:
|
||||
error = exception.args[2]
|
||||
messages.error(
|
||||
self.request,
|
||||
_('Error when configuring unattended-upgrades: {error}').
|
||||
format(error=error))
|
||||
|
||||
if new_status['auto_upgrades_enabled']:
|
||||
messages.success(self.request, _('Automatic upgrades enabled'))
|
||||
else:
|
||||
messages.success(self.request,
|
||||
_('Automatic upgrades disabled'))
|
||||
is_changed = True
|
||||
except Exception as exception:
|
||||
messages_error(self.request,
|
||||
_('Error when configuring unattended-upgrades'),
|
||||
exception)
|
||||
|
||||
if old_status['dist_upgrade_enabled'] \
|
||||
!= new_status['dist_upgrade_enabled']:
|
||||
upgrades.set_dist_upgrade_enabled(
|
||||
new_status['dist_upgrade_enabled'])
|
||||
if new_status['dist_upgrade_enabled']:
|
||||
messages.success(self.request,
|
||||
_('Distribution upgrade enabled'))
|
||||
else:
|
||||
messages.success(self.request,
|
||||
_('Distribution upgrade disabled'))
|
||||
is_changed = True
|
||||
|
||||
if is_changed:
|
||||
messages.success(self.request, _('Configuration updated.'))
|
||||
|
||||
return super().form_valid(form)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user