Skip to content

Commit

Permalink
Fix logic in controlpanel save method.
Browse files Browse the repository at this point in the history
  • Loading branch information
cekk committed Sep 18, 2023
1 parent 1b4d825 commit 08e0567
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 22 deletions.
36 changes: 15 additions & 21 deletions collective/analyticspanel/browser/controlpanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

3 changes: 2 additions & 1 deletion docs/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 08e0567

Please sign in to comment.