Use default container element delete helper
authorThierry Florac <thierry.florac@onf.fr>
Wed, 11 Apr 2018 11:34:15 +0200
changeset 74 46260820b73f
parent 73 22f4640630ba
child 75 02d9ff8d1803
Use default container element delete helper
src/pyams_portal/zmi/container.py
--- a/src/pyams_portal/zmi/container.py	Wed Mar 28 16:02:00 2018 +0200
+++ b/src/pyams_portal/zmi/container.py	Wed Apr 11 11:34:15 2018 +0200
@@ -30,7 +30,7 @@
 # import packages
 from pyams_form.form import AJAXEditForm
 from pyams_pagelet.pagelet import pagelet_config
-from pyams_skin.container import ContainerView
+from pyams_skin.container import ContainerView, delete_container_element
 from pyams_skin.page import DefaultPageHeaderAdapter
 from pyams_skin.table import DefaultElementEditorAdapter, BaseTable, NameColumn, TrashColumn
 from pyams_skin.viewlet.menu import MenuItem
@@ -90,16 +90,12 @@
     def data_attributes(self):
         manager = query_utility(IPortalTemplateContainer)
         attributes = super(PortalTemplateContainerTable, self).data_attributes
-        table_attrs = {
+        attributes.setdefault('table', {}).update({
             'data-ams-location': absolute_url(manager, self.request),
             'data-ams-plugins': 'pyams_portal',
             'data-ams-plugin-pyams_portal-src': get_resource_path(pyams_portal),
             'data-ams-plugin-pyams_portal-css': get_resource_path(pyams_portal_css)
-        }
-        if 'table' in attributes:
-            attributes['table'].update(table_attrs)
-        else:
-            attributes['table'] = table_attrs
+        })
         return attributes
 
 
@@ -129,6 +125,13 @@
     permission = MANAGE_TEMPLATE_PERMISSION
 
 
+@view_config(name='delete-element.json', context=IPortalTemplateContainer, request_type=IPyAMSLayer,
+             permission=MANAGE_TEMPLATE_PERMISSION, renderer='json', xhr=True)
+def delete_portal_template(request):
+    """Delete selected template"""
+    return delete_container_element(request, ignore_permission=True)
+
+
 @adapter_config(context=(ISite, IAdminLayer, PortalTemplateContainerTable), provides=IValues)
 class PortalTemplateContainerValuesAdapter(ContextRequestViewAdapter):
     """Portal template container values adapter"""
@@ -184,6 +187,8 @@
 class PortalTemplateContainerPropertiesEditForm(AdminDialogEditForm):
     """Portal template container properties edit form"""
 
+    prefix = 'portal_properties.'
+
     title = _("Portal templates container")
     legend = _("Edit selected portlets")
     icon_css_class = 'fa fa-fw fa-thumb-tack'