mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-09-19 04:59:01 +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 import __version__
|
||||||
from plinth.modules import first_boot, upgrades
|
from plinth.modules import first_boot, upgrades
|
||||||
from plinth.privileged import packages as packages_privileged
|
from plinth.privileged import packages as packages_privileged
|
||||||
from plinth.views import AppView
|
from plinth.views import AppView, messages_error
|
||||||
|
|
||||||
from . import privileged
|
from . import privileged
|
||||||
from .forms import BackportsFirstbootForm, ConfigureForm, UpdateFirstbootForm
|
from .forms import BackportsFirstbootForm, ConfigureForm, UpdateFirstbootForm
|
||||||
@ -56,6 +56,8 @@ class UpgradesConfigurationView(AppView):
|
|||||||
old_status = form.initial
|
old_status = form.initial
|
||||||
new_status = form.cleaned_data
|
new_status = form.cleaned_data
|
||||||
|
|
||||||
|
is_changed = False
|
||||||
|
|
||||||
if old_status['auto_upgrades_enabled'] \
|
if old_status['auto_upgrades_enabled'] \
|
||||||
!= new_status['auto_upgrades_enabled']:
|
!= new_status['auto_upgrades_enabled']:
|
||||||
|
|
||||||
@ -64,29 +66,21 @@ class UpgradesConfigurationView(AppView):
|
|||||||
privileged.enable_auto()
|
privileged.enable_auto()
|
||||||
else:
|
else:
|
||||||
privileged.disable_auto()
|
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']:
|
is_changed = True
|
||||||
messages.success(self.request, _('Automatic upgrades enabled'))
|
except Exception as exception:
|
||||||
else:
|
messages_error(self.request,
|
||||||
messages.success(self.request,
|
_('Error when configuring unattended-upgrades'),
|
||||||
_('Automatic upgrades disabled'))
|
exception)
|
||||||
|
|
||||||
if old_status['dist_upgrade_enabled'] \
|
if old_status['dist_upgrade_enabled'] \
|
||||||
!= new_status['dist_upgrade_enabled']:
|
!= new_status['dist_upgrade_enabled']:
|
||||||
upgrades.set_dist_upgrade_enabled(
|
upgrades.set_dist_upgrade_enabled(
|
||||||
new_status['dist_upgrade_enabled'])
|
new_status['dist_upgrade_enabled'])
|
||||||
if new_status['dist_upgrade_enabled']:
|
is_changed = True
|
||||||
messages.success(self.request,
|
|
||||||
_('Distribution upgrade enabled'))
|
if is_changed:
|
||||||
else:
|
messages.success(self.request, _('Configuration updated.'))
|
||||||
messages.success(self.request,
|
|
||||||
_('Distribution upgrade disabled'))
|
|
||||||
|
|
||||||
return super().form_valid(form)
|
return super().form_valid(form)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user