Updated result in items visibility switch views
authorThierry Florac <tflorac@ulthar.net>
Sat, 21 Nov 2020 10:18:02 +0100
changeset 1436 758f1ae21724
parent 1435 347a4c2ef20c
child 1437 31db3e8a4e44
Updated result in items visibility switch views
src/pyams_content/features/redirect/zmi/container.py
src/pyams_content/features/share/zmi/container.py
--- a/src/pyams_content/features/redirect/zmi/container.py	Fri Nov 20 14:25:23 2020 +0100
+++ b/src/pyams_content/features/redirect/zmi/container.py	Sat Nov 21 10:18:02 2020 +0100
@@ -28,7 +28,8 @@
 
 from pyams_catalog.query import CatalogResultSet
 from pyams_content import _
-from pyams_content.features.redirect.interfaces import IRedirectionManager, IRedirectionManagerTarget
+from pyams_content.features.redirect.interfaces import IRedirectionManager, \
+    IRedirectionManagerTarget
 from pyams_content.interfaces import MANAGE_SITE_ROOT_PERMISSION
 from pyams_content.zmi import pyams_content
 from pyams_form.form import AJAXAddForm
@@ -43,7 +44,8 @@
 from pyams_skin.layer import IPyAMSLayer
 from pyams_skin.page import DefaultPageHeaderAdapter
 from pyams_skin.skin import apply_skin
-from pyams_skin.table import AttributeSwitcherColumn, BaseTable, I18nColumn, ImageColumn, SorterColumn, TrashColumn
+from pyams_skin.table import AttributeSwitcherColumn, BaseTable, I18nColumn, ImageColumn, \
+    SorterColumn, TrashColumn
 from pyams_skin.viewlet.menu import MenuItem
 from pyams_skin.viewlet.toolbar import ToolbarAction
 from pyams_template.template import template_config
@@ -125,7 +127,8 @@
         return super(RedirectionsContainerTable, self).render()
 
 
-@adapter_config(context=(IRedirectionManagerTarget, IPyAMSLayer, RedirectionsContainerTable), provides=IValues)
+@adapter_config(context=(IRedirectionManagerTarget, IPyAMSLayer, RedirectionsContainerTable),
+                provides=IValues)
 class RedirectionsContainerValues(ContextRequestViewAdapter):
     """Redirections container values"""
 
@@ -134,7 +137,8 @@
         return IRedirectionManager(self.context).values()
 
 
-@adapter_config(name='sorter', context=(IRedirectionManagerTarget, IPyAMSLayer, RedirectionsContainerTable),
+@adapter_config(name='sorter',
+                context=(IRedirectionManagerTarget, IPyAMSLayer, RedirectionsContainerTable),
                 provides=IColumn)
 class RedirectionsContainerSorterColumn(SorterColumn):
     """Redirections container sorter column"""
@@ -149,7 +153,8 @@
     return {'status': 'success'}
 
 
-@adapter_config(name='enable-disable', context=(IRedirectionManagerTarget, IPyAMSLayer, RedirectionsContainerTable),
+@adapter_config(name='enable-disable',
+                context=(IRedirectionManagerTarget, IPyAMSLayer, RedirectionsContainerTable),
                 provides=IColumn)
 class RedirectionsContainerEnablerColumn(AttributeSwitcherColumn):
     """Redirections container enabler switcher column"""
@@ -164,8 +169,9 @@
     weight = 6
 
 
-@view_config(name='switch-rule-activity.json', context=IRedirectionManager, request_type=IPyAMSLayer,
-             permission=MANAGE_SITE_ROOT_PERMISSION, renderer='json', xhr=True)
+@view_config(name='switch-rule-activity.json', context=IRedirectionManager,
+             request_type=IPyAMSLayer, permission=MANAGE_SITE_ROOT_PERMISSION,
+             renderer='json', xhr=True)
 def switch_rule_activity(request):
     """Switch rule activity"""
     container = IRedirectionManager(request.context)
@@ -173,10 +179,14 @@
     if rule is None:
         raise NotFound()
     rule.active = not rule.active
-    return {'on': rule.active}
+    return {
+        'status': 'success',
+        'on': rule.active
+    }
 
 
-@adapter_config(name='chain-unchain', context=(IRedirectionManagerTarget, IPyAMSLayer, RedirectionsContainerTable),
+@adapter_config(name='chain-unchain',
+                context=(IRedirectionManagerTarget, IPyAMSLayer, RedirectionsContainerTable),
                 provides=IColumn)
 class RedirectionsContainerChainedColumn(AttributeSwitcherColumn):
     """Redirections container chained switcher column"""
@@ -203,7 +213,8 @@
     return {'chained': rule.chained}
 
 
-@adapter_config(name='name', context=(IRedirectionManagerTarget, IPyAMSLayer, RedirectionsContainerTable),
+@adapter_config(name='name',
+                context=(IRedirectionManagerTarget, IPyAMSLayer, RedirectionsContainerTable),
                 provides=IColumn)
 class RedirectionsContainerNameColumn(I18nColumn, GetAttrColumn):
     """Redirections container name column"""
@@ -216,7 +227,8 @@
 MISSING_TARGET = object()
 
 
-@adapter_config(name='visible', context=(IRedirectionManagerTarget, IPyAMSLayer, RedirectionsContainerTable),
+@adapter_config(name='visible',
+                context=(IRedirectionManagerTarget, IPyAMSLayer, RedirectionsContainerTable),
                 provides=IColumn)
 class RedirectionsContainerVisibleColumn(ImageColumn):
     """Redirections container visible column"""
@@ -278,7 +290,8 @@
             return self.request.localizer.translate(_("External link"))
 
 
-@adapter_config(name='target', context=(IRedirectionManagerTarget, IPyAMSLayer, RedirectionsContainerTable),
+@adapter_config(name='target',
+                context=(IRedirectionManagerTarget, IPyAMSLayer, RedirectionsContainerTable),
                 provides=IColumn)
 class RedirectionsContainerTargetColumn(I18nColumn, GetAttrColumn):
     """Redirections container target column"""
@@ -299,7 +312,8 @@
             return super(RedirectionsContainerTargetColumn, self).getValue(obj)
 
 
-@adapter_config(name='trash', context=(IRedirectionManagerTarget, IPyAMSLayer, RedirectionsContainerTable),
+@adapter_config(name='trash',
+                context=(IRedirectionManagerTarget, IPyAMSLayer, RedirectionsContainerTable),
                 provides=IColumn)
 class RedirectionsContainerTrashColumn(TrashColumn):
     """Redirections container trash column"""
@@ -316,14 +330,16 @@
     table_class = RedirectionsContainerTable
 
 
-@adapter_config(context=(IRedirectionManagerTarget, IAdminLayer, RedirectionsContainerView), provides=IPageHeader)
+@adapter_config(context=(IRedirectionManagerTarget, IAdminLayer, RedirectionsContainerView),
+                provides=IPageHeader)
 class RedirectionsContainerViewHeaderAdapter(DefaultPageHeaderAdapter):
     """Redirections container view header adapter"""
 
     icon_class = 'fa fa-fw fa-map-signs'
 
 
-@adapter_config(context=(IRedirectionManagerTarget, IAdminLayer, RedirectionsContainerView), provides=IContentHelp)
+@adapter_config(context=(IRedirectionManagerTarget, IAdminLayer, RedirectionsContainerView),
+                provides=IContentHelp)
 class RedirectionsContainerHelpAdapter(ContentHelp):
     """Redirections container help adapter"""
 
@@ -383,8 +399,8 @@
     test = button.Button(name='test', title=_("Test rules"))
 
 
-@pagelet_config(name='test-redirection-rules.html', context=IRedirectionManagerTarget, layer=IPyAMSLayer,
-                permission=MANAGE_SITE_ROOT_PERMISSION)
+@pagelet_config(name='test-redirection-rules.html', context=IRedirectionManagerTarget,
+                layer=IPyAMSLayer, permission=MANAGE_SITE_ROOT_PERMISSION)
 class RedirectionsContainerTestForm(AdminDialogAddForm):
     """Redirections container test form"""
 
@@ -411,18 +427,21 @@
         data = data.get(self, data)
         request = copy_request(self.request)
         apply_skin(request, IUserSkinnable(self.context).get_skin())
-        return IRedirectionManager(self.context).test_rules(data['source_url'], request, data['check_inactive_rules'])
+        return IRedirectionManager(self.context).test_rules(data['source_url'], request,
+                                                            data['check_inactive_rules'])
 
 
-@viewlet_config(name='test-indexer-process.suffix', layer=IAdminLayer, manager=IWidgetsSuffixViewletsManager,
-                view=RedirectionsContainerTestForm, weight=50)
+@viewlet_config(name='test-indexer-process.suffix', layer=IAdminLayer,
+                manager=IWidgetsSuffixViewletsManager, view=RedirectionsContainerTestForm,
+                weight=50)
 @template_config(template='templates/manager-test.pt')
 class RedirectionsContainerTestSuffix(Viewlet):
     """Redirections container test form suffix"""
 
 
-@view_config(name='test-redirection-rules.json', context=IRedirectionManagerTarget, request_type=IPyAMSLayer,
-             permission=MANAGE_SITE_ROOT_PERMISSION, renderer='json', xhr=True)
+@view_config(name='test-redirection-rules.json', context=IRedirectionManagerTarget,
+             request_type=IPyAMSLayer, permission=MANAGE_SITE_ROOT_PERMISSION,
+             renderer='json', xhr=True)
 class RedirectionsContainerAJAXTestForm(AJAXAddForm, RedirectionsContainerTestForm):
     """Redirections container test form, JSON renderer"""
 
@@ -435,7 +454,8 @@
                                                                  translate(_("URL pattern")),
                                                                  translate(_("Output URL"))))
                 message.append('{:<40}-|-{:<40}-|-{:<40}'.format('-' * 40, '-' * 40, '-' * 40))
-            message.append('{:<40} | {:<40} | {:<40}'.format(source_url, rule.url_pattern, target_url))
+            message.append('{:<40} | {:<40} | {:<40}'.format(source_url, rule.url_pattern,
+                                                             target_url))
         if not message:
             message.append(translate(_("No matching rule!")))
         return {
--- a/src/pyams_content/features/share/zmi/container.py	Fri Nov 20 14:25:23 2020 +0100
+++ b/src/pyams_content/features/share/zmi/container.py	Sat Nov 21 10:18:02 2020 +0100
@@ -20,10 +20,10 @@
 from z3c.form import field
 from z3c.table.interfaces import IColumn, IValues
 from zope.interface import implementer
-from zope.schema import getFieldNamesInOrder
 
 from pyams_content import _
-from pyams_content.features.share.interfaces import ISocialShareInfo, ISocialShareManager, ISocialShareManagerTarget
+from pyams_content.features.share.interfaces import ISocialShareInfo, ISocialShareManager, \
+    ISocialShareManagerTarget
 from pyams_content.features.share.zmi.interfaces import ISocialShareMenu
 from pyams_content.interfaces import MANAGE_SITE_ROOT_PERMISSION
 from pyams_content.zmi import pyams_content
@@ -34,7 +34,8 @@
 from pyams_skin.interfaces import IContentHelp, IPageHeader
 from pyams_skin.layer import IPyAMSLayer
 from pyams_skin.page import DefaultPageHeaderAdapter
-from pyams_skin.table import AttributeSwitcherColumn, BaseTable, I18nColumn, I18nValueColumn, SorterColumn, TrashColumn
+from pyams_skin.table import AttributeSwitcherColumn, BaseTable, I18nColumn, I18nValueColumn, \
+    SorterColumn, TrashColumn
 from pyams_skin.viewlet.menu import MenuItem
 from pyams_utils.adapter import ContextRequestViewAdapter, adapter_config
 from pyams_utils.fanstatic import get_resource_path
@@ -96,7 +97,8 @@
         return super(SocialShareContainerTable, self).render()
 
 
-@adapter_config(context=(ISocialShareManagerTarget, IPyAMSLayer, SocialShareContainerTable), provides=IValues)
+@adapter_config(context=(ISocialShareManagerTarget, IPyAMSLayer, SocialShareContainerTable),
+                provides=IValues)
 class SocialShareContainerValues(ContextRequestViewAdapter):
     """Social network share items container values"""
 
@@ -105,14 +107,16 @@
         return ISocialShareManager(self.context).values()
 
 
-@adapter_config(name='sorter', context=(ISocialShareManagerTarget, IPyAMSLayer, SocialShareContainerTable),
+@adapter_config(name='sorter',
+                context=(ISocialShareManagerTarget, IPyAMSLayer, SocialShareContainerTable),
                 provides=IColumn)
 class SocialShareContainerSorterColumn(SorterColumn):
     """Social network share items container sorter column"""
 
 
-@view_config(name='set-social-items-order.json', context=ISocialShareManager, request_type=IPyAMSLayer,
-             permission=MANAGE_SITE_ROOT_PERMISSION, renderer='json', xhr=True)
+@view_config(name='set-social-items-order.json', context=ISocialShareManager,
+             request_type=IPyAMSLayer, permission=MANAGE_SITE_ROOT_PERMISSION,
+             renderer='json', xhr=True)
 def set_social_items_order(request):
     """Update social network share items order"""
     order = list(map(str, json.loads(request.params.get('names'))))
@@ -120,7 +124,8 @@
     return {'status': 'success'}
 
 
-@adapter_config(name='enable-disable', context=(ISocialShareManagerTarget, IPyAMSLayer, SocialShareContainerTable),
+@adapter_config(name='enable-disable',
+                context=(ISocialShareManagerTarget, IPyAMSLayer, SocialShareContainerTable),
                 provides=IColumn)
 class SocialShareContainerEnablerColumn(AttributeSwitcherColumn):
     """Social network share items container enabler switcher column"""
@@ -135,8 +140,9 @@
     weight = 6
 
 
-@view_config(name='switch-item-activity.json', context=ISocialShareManager, request_type=IPyAMSLayer,
-             permission=MANAGE_SITE_ROOT_PERMISSION, renderer='json', xhr=True)
+@view_config(name='switch-item-activity.json', context=ISocialShareManager,
+             request_type=IPyAMSLayer, permission=MANAGE_SITE_ROOT_PERMISSION,
+             renderer='json', xhr=True)
 def switch_social_item_activity(request):
     """Switch social item activity"""
     container = ISocialShareManager(request.context)
@@ -144,10 +150,14 @@
     if item is None:
         raise NotFound()
     item.active = not item.active
-    return {'on': item.active}
+    return {
+        'status': 'success',
+        'on': item.active
+    }
 
 
-@adapter_config(name='name', context=(ISocialShareManagerTarget, IPyAMSLayer, SocialShareContainerTable),
+@adapter_config(name='name',
+                context=(ISocialShareManagerTarget, IPyAMSLayer, SocialShareContainerTable),
                 provides=IColumn)
 class SocialShareContainerNameColumn(I18nColumn, I18nValueColumn):
     """Social network share items container name column"""
@@ -157,7 +167,8 @@
     weight = 10
 
 
-@adapter_config(name='trash', context=(ISocialShareManagerTarget, IPyAMSLayer, SocialShareContainerTable),
+@adapter_config(name='trash',
+                context=(ISocialShareManagerTarget, IPyAMSLayer, SocialShareContainerTable),
                 provides=IColumn)
 class SocialShareContainerTrashColumn(TrashColumn):
     """Social network share items container trash column"""
@@ -174,14 +185,16 @@
     table_class = SocialShareContainerTable
 
 
-@adapter_config(context=(ISocialShareManagerTarget, IAdminLayer, SocialShareContainerView), provides=IPageHeader)
+@adapter_config(context=(ISocialShareManagerTarget, IAdminLayer, SocialShareContainerView),
+                provides=IPageHeader)
 class SocialShareContainerViewHeaderAdapter(DefaultPageHeaderAdapter):
     """Social network share items container view header adapter"""
 
     icon_class = 'fa fa-fw fa-share-alt'
 
 
-@adapter_config(context=(ISocialShareManagerTarget, IAdminLayer, SocialShareContainerView), provides=IContentHelp)
+@adapter_config(context=(ISocialShareManagerTarget, IAdminLayer, SocialShareContainerView),
+                provides=IContentHelp)
 class SocialShareContainerHelpAdapter(ContentHelp):
     """Social network share items container help adapter"""
 
@@ -197,8 +210,9 @@
 # General social share info
 #
 
-@viewlet_config(name='social-share-info.menu', context=ISocialShareManagerTarget, layer=IPyAMSLayer,
-                manager=ISocialShareMenu, permission=MANAGE_SITE_ROOT_PERMISSION, weight=10)
+@viewlet_config(name='social-share-info.menu', context=ISocialShareManagerTarget,
+                layer=IPyAMSLayer, manager=ISocialShareMenu,
+                permission=MANAGE_SITE_ROOT_PERMISSION, weight=10)
 class SocialShareInfoMenu(MenuItem):
     """Social share info menu"""
 
@@ -208,8 +222,8 @@
     modal_target = True
 
 
-@pagelet_config(name='social-share-info.html', context=ISocialShareManagerTarget, layer=IPyAMSLayer,
-                permission=MANAGE_SITE_ROOT_PERMISSION)
+@pagelet_config(name='social-share-info.html', context=ISocialShareManagerTarget,
+                layer=IPyAMSLayer, permission=MANAGE_SITE_ROOT_PERMISSION)
 @ajax_config(name='social-share-info.json', context=ISocialShareManagerTarget, layer=IPyAMSLayer)
 class SocialShareInfoEditForm(AdminDialogEditForm):
     """Social share info properties edit form"""