Reload page after title modification
authorThierry Florac <tflorac@ulthar.net>
Fri, 20 Nov 2020 14:25:23 +0100
changeset 1435 347a4c2ef20c
parent 1434 13db47aeac34
child 1436 758f1ae21724
Reload page after title modification
src/pyams_content/shared/site/zmi/folder.py
--- a/src/pyams_content/shared/site/zmi/folder.py	Fri Nov 20 08:30:22 2020 +0100
+++ b/src/pyams_content/shared/site/zmi/folder.py	Fri Nov 20 14:25:23 2020 +0100
@@ -18,7 +18,7 @@
 from zope.intid.interfaces import IIntIds
 from zope.schema import Int, Text
 
-from pyams_content.interfaces import MANAGE_SITE_PERMISSION, MANAGE_TOOL_PERMISSION
+from pyams_content.interfaces import IBaseContent, MANAGE_SITE_PERMISSION, MANAGE_TOOL_PERMISSION
 from pyams_content.shared.common import IDashboardTypeColumnValue
 from pyams_content.shared.common.interfaces import IBaseSharedTool
 from pyams_content.shared.common.interfaces.zmi import IDashboardTable
@@ -83,7 +83,8 @@
 
 @pagelet_config(name='add-site-folder.html', context=ISiteContainer, layer=IPyAMSLayer,
                 permission=MANAGE_SITE_PERMISSION)
-@ajax_config(name='add-site-folder.json', context=ISiteContainer, layer=IPyAMSLayer, base=AJAXAddForm)
+@ajax_config(name='add-site-folder.json', context=ISiteContainer, layer=IPyAMSLayer,
+             base=AJAXAddForm)
 class SiteFolderAddForm(AdminDialogAddForm):
     """Site folder add form"""
 
@@ -151,7 +152,8 @@
     negotiator = get_utility(INegotiator)
     title = event.data.get('title', {}).get(negotiator.server_language)
     if not title:
-        event.form.widgets.errors += (Invalid(_("You must provide a folder name for default server language!")),)
+        event.form.widgets.errors += (Invalid(_("You must provide a folder name for default "
+                                                "server language!")),)
 
 
 @adapter_config(context=(ISiteFolder, ISiteManagementMenu), provides=IMenuHeader)
@@ -189,18 +191,31 @@
     modal_target = False
 
 
-@pagelet_config(name='properties.html', context=ISiteFolder, layer=IPyAMSLayer, permission=MANAGE_TOOL_PERMISSION)
+@pagelet_config(name='properties.html', context=ISiteFolder, layer=IPyAMSLayer,
+                permission=MANAGE_TOOL_PERMISSION)
 @ajax_config(name='properties.json', context=ISiteFolder, layer=IPyAMSLayer)
 class SiteFolderPropertiesEditForm(SharedToolPropertiesEditForm):
     """Site folder properties edit form"""
 
     legend = _("Site folder properties")
 
-    fields = field.Fields(ISiteFolder).select('title', 'short_name', 'header', 'description', 'notepad') + \
+    fields = field.Fields(ISiteFolder).select('title', 'short_name', 'header', 'description',
+                                              'notepad') + \
         field.Fields(IBaseSharedTool).select('shared_content_workflow')
 
+    def get_ajax_output(self, changes):
+        updated = changes.get(IBaseContent, ())
+        if 'title' in updated:
+            return {
+                'status': 'redirect',
+                'message': self.request.localizer.translate(self.successMessage)
+            }
+        else:
+            return super(SiteFolderPropertiesEditForm, self).get_ajax_output(changes)
+        
 
-@adapter_config(name='navigation', context=(ISiteFolder, IPyAMSLayer, SiteFolderPropertiesEditForm),
+@adapter_config(name='navigation',
+                context=(ISiteFolder, IPyAMSLayer, SiteFolderPropertiesEditForm),
                 provides=IInnerSubForm)
 class SiteFolderNavigationPropertiesEditForm(InnerAdminEditForm):
     """Site folder navigation properties edit form"""
@@ -215,7 +230,8 @@
     main_group_legend = _("Navigation properties")
     main_group_class = 'inner switcher no-y-padding'
 
-    fields = field.Fields(ISiteFolder).select('visible_in_list', 'navigation_title', 'navigation_mode')
+    fields = field.Fields(ISiteFolder).select('visible_in_list', 'navigation_title',
+                                              'navigation_mode')
 
     weight = 5
 
@@ -225,7 +241,8 @@
 
     def updateGroups(self):
         self.add_group(NamedWidgetsGroup(self, 'navigation', self.widgets,
-                                         ('visible_in_list', 'navigation_title', 'navigation_mode'),
+                                         ('visible_in_list', 'navigation_title',
+                                          'navigation_mode'),
                                          fieldset_class=self.fieldset_class,
                                          legend=self.main_group_legend,
                                          css_class=self.main_group_class,