From 08e0567aa8f33acbbc9966342e596bf5398ab942 Mon Sep 17 00:00:00 2001 From: Andrea Cecchi Date: Mon, 18 Sep 2023 10:23:15 +0200 Subject: [PATCH] Fix logic in controlpanel save method. --- .../analyticspanel/browser/controlpanel.py | 36 ++++++++----------- docs/HISTORY.rst | 3 +- 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/collective/analyticspanel/browser/controlpanel.py b/collective/analyticspanel/browser/controlpanel.py index 95c20c7..c738726 100644 --- a/collective/analyticspanel/browser/controlpanel.py +++ b/collective/analyticspanel/browser/controlpanel.py @@ -13,56 +13,50 @@ class FormAdvanced(group.Group): - label = _(u"Advanced settings") + label = _("Advanced settings") fields = field.Fields(IAnalyticsAdvancedSettings) class AnalyticsSettingsEditForm(controlpanel.RegistryEditForm): - """Media settings form. - """ + """Media settings form.""" schema = IAnalyticsSettingsSchema fields = field.Fields(IAnalyticsSettings) - fields['error_specific_code'].widgetFactory = BlockDataGridFieldFactory - fields['path_specific_code'].widgetFactory = BlockDataGridFieldFactory + fields["error_specific_code"].widgetFactory = BlockDataGridFieldFactory + fields["path_specific_code"].widgetFactory = BlockDataGridFieldFactory groups = (FormAdvanced,) id = "AnalyticsSettingsEditForm" - label = _(u"Analytics settings") + label = _("Analytics settings") description = _( - u"help_analytics_settings_editform", - default=u"Manage JavaScript code and analytics snippets inclusion for the site", + "help_analytics_settings_editform", + default="Manage JavaScript code and analytics snippets inclusion for the site", ) - @button.buttonAndHandler(_('Save'), name='save') + @button.buttonAndHandler(_("Save"), name="save") def handleSave(self, action): - for k, v in self.request.form.items(): + keys = [x for x in self.request.form.keys()] + for k in keys: if ".AA" in k: - self.request.form[k.replace('.AA', '.0')] = v + self.request.form[k.replace(".AA", ".0")] = self.request.form[k] del self.request.form[k] data, errors = self.extractData() if errors: self.status = self.formErrorsMessage return self.applyChanges(data) - IStatusMessage(self.request).addStatusMessage( - _(u"Changes saved"), "info" - ) + IStatusMessage(self.request).addStatusMessage(_("Changes saved"), "info") self.context.REQUEST.RESPONSE.redirect("@@analytics-settings") - @button.buttonAndHandler(_('Cancel'), name='cancel') + @button.buttonAndHandler(_("Cancel"), name="cancel") def handleCancel(self, action): - IStatusMessage(self.request).addStatusMessage( - _(u"Edit cancelled"), "info" - ) + IStatusMessage(self.request).addStatusMessage(_("Edit cancelled"), "info") self.request.response.redirect( "%s/%s" % (self.context.absolute_url(), self.control_panel_view) ) class AnalyticsSettingsControlPanel(controlpanel.ControlPanelFormWrapper): - """Analytics settings control panel. - """ + """Analytics settings control panel.""" form = AnalyticsSettingsEditForm - diff --git a/docs/HISTORY.rst b/docs/HISTORY.rst index 85c74c8..1d7dd2d 100644 --- a/docs/HISTORY.rst +++ b/docs/HISTORY.rst @@ -4,7 +4,8 @@ Changelog 2.0.1 (unreleased) ------------------ -- Nothing changed yet. +- Fix logic in controlpanel save method. + [cekk] 2.0.0 (2022-11-23)