Commit 1e79d92a authored by Nicolas Delaby's avatar Nicolas Delaby

Improve script added by Kazuhiko to delete Obsolete Business Templates.

* Add action on Template Tool, only available for Manager
* Use dialog to choose which Business Template that user wants to keep

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@32407 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent e950352f
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<global name="ActionInformation" module="Products.CMFCore.ActionInformation"/>
<tuple/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>action</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>action_type/object_action</string>
</tuple>
</value>
</item>
<item>
<key> <string>category</string> </key>
<value> <string>object_action</string> </value>
</item>
<item>
<key> <string>condition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>icon</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>delete_obsolete_template_list</string> </value>
</item>
<item>
<key> <string>permissions</string> </key>
<value>
<tuple>
<string>Manage portal</string>
</tuple>
</value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Action Information</string> </value>
</item>
<item>
<key> <string>priority</string> </key>
<value> <float>50.0</float> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Delete Obsolete Template List</string> </value>
</item>
<item>
<key> <string>visible</string> </key>
<value> <int>1</int> </value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<tuple>
<global name="Expression" module="Products.CMFCore.Expression"/>
<tuple/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>text</string> </key>
<value> <string>string:${object_url}/TemplateTool_viewDeleteObsoleteTemplateListDialog</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -86,7 +86,6 @@
<value>
<list>
<string>my_categories_list</string>
<string>my_recorded_property_list</string>
</list>
</value>
</item>
......
......@@ -53,29 +53,21 @@
</item>
<item>
<key> <string>_body</string> </key>
<value> <string encoding="cdata"><![CDATA[
portal_templates = context.getPortalObject().portal_templates\n
delete_list = []\n
bt_list = portal_templates.objectValues()\n
for bt in bt_list:\n
bt_id = bt.getId()\n
installation_state = bt.getInstallationState()\n
if installation_state in (\'deleted\', \'replaced\'):\n
delete_list.append(bt_id)\n
elif installation_state == \'not_installed\':\n
if len([x for x in bt_list \\\n
if x.getTitle() == bt.getTitle() and \\\n
x.getInstallationState() == \'installed\' and \\\n
int(x.getRevision() or \'0\') > int(bt.getRevision() or \'0\')]):\n
delete_list.append(bt_id)\n
<value> <string>portal = context.getPortalObject()\n
uid_list = portal.portal_selections.getSelectionCheckedUidsFor(\'delete_template_list_selection\')\n
\n
print \'Deleted id list:%r\' % delete_list\n
portal_templates.manage_delObjects(delete_list)\n
return printed\n
]]></string> </value>
if uid_list:\n
# if parameter is empty, catalog query will discard it and return all objects.\n
id_list = [content.getId() for content in portal.portal_catalog(uid=uid_list)]\n
message = \'Templates deleted: ${len_template_list}.\'\n
mapping = {\'len_template_list\': len(id_list)}\n
context.manage_delObjects(id_list)\n
translated_message = context.Base_translateString(message, mapping=mapping)\n
else:\n
translated_message = context.Base_translateString(\'No Business Template deleted.\')\n
\n
portal.ERP5Site_redirect(context.getAbsoluteUrl(), keep_items={\'portal_status_message\': translated_message})\n
</string> </value>
</item>
<item>
<key> <string>_code</string> </key>
......@@ -85,7 +77,7 @@ return printed\n
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
<value> <string>*args, **kw</string> </value>
</item>
<item>
<key> <string>errors</string> </key>
......@@ -111,22 +103,21 @@ return printed\n
<key> <string>co_varnames</string> </key>
<value>
<tuple>
<string>_print_</string>
<string>_print</string>
<string>args</string>
<string>kw</string>
<string>_getattr_</string>
<string>context</string>
<string>portal_templates</string>
<string>delete_list</string>
<string>bt_list</string>
<string>_getiter_</string>
<string>bt</string>
<string>bt_id</string>
<string>installation_state</string>
<string>len</string>
<string>portal</string>
<string>uid_list</string>
<string>append</string>
<string>$append0</string>
<string>x</string>
<string>int</string>
<string>_getiter_</string>
<string>content</string>
<string>id_list</string>
<string>message</string>
<string>len</string>
<string>mapping</string>
<string>translated_message</string>
</tuple>
</value>
</item>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
<tuple/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string encoding="cdata"><![CDATA[
portal = context.getPortalObject()\n
obsolete_list = []\n
\n
business_template_list = context.objectValues(**kw)\n
for business_template in business_template_list:\n
business_template_id = business_template.getId()\n
installation_state = business_template.getInstallationState()\n
if installation_state in (\'deleted\', \'replaced\'):\n
obsolete_list.append(business_template)\n
elif installation_state == \'not_installed\':\n
if len([x for x in business_template_list \\\n
if x.getTitle() == business_template.getTitle() and \\\n
x.getInstallationState() == \'installed\' and \\\n
int(x.getRevision() or \'0\') > int(business_template.getRevision() or \'0\')]):\n
obsolete_list.append(business_template)\n
\n
# Select all by default in selection\n
uid_list = [business_template.getUid() for business_template in obsolete_list]\n
portal.portal_selections.setSelectionCheckedUidsFor(kw.get(\'selection_name\'), uid_list)\n
return obsolete_list\n
]]></string> </value>
</item>
<item>
<key> <string>_code</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>*args, **kw</string> </value>
</item>
<item>
<key> <string>errors</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>func_code</string> </key>
<value>
<object>
<klass>
<global name="FuncCode" module="Shared.DC.Scripts.Signature"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>co_argcount</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>co_varnames</string> </key>
<value>
<tuple>
<string>args</string>
<string>kw</string>
<string>_getattr_</string>
<string>context</string>
<string>portal</string>
<string>obsolete_list</string>
<string>_apply_</string>
<string>business_template_list</string>
<string>_getiter_</string>
<string>business_template</string>
<string>business_template_id</string>
<string>installation_state</string>
<string>len</string>
<string>append</string>
<string>$append0</string>
<string>x</string>
<string>int</string>
<string>uid_list</string>
</tuple>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>func_defaults</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>TemplateTool_getObsoleteTemplateList</string> </value>
</item>
<item>
<key> <string>warnings</string> </key>
<value>
<tuple/>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<global name="ERP5Form" module="Products.ERP5Form.Form"/>
<tuple/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary/>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_objects</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>action</string> </key>
<value> <string>TemplateTool_deleteObsoleteTemplateList</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>edit_order</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>encoding</string> </key>
<value> <string>UTF-8</string> </value>
</item>
<item>
<key> <string>enctype</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>group_list</string> </key>
<value>
<list>
<string>left</string>
<string>right</string>
<string>center</string>
<string>bottom</string>
<string>hidden</string>
</list>
</value>
</item>
<item>
<key> <string>groups</string> </key>
<value>
<dictionary>
<item>
<key> <string>bottom</string> </key>
<value>
<list>
<string>listbox</string>
</list>
</value>
</item>
<item>
<key> <string>center</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>hidden</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>left</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>right</string> </key>
<value>
<list/>
</value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>TemplateTool_viewDeleteObsoleteTemplateListDialog</string> </value>
</item>
<item>
<key> <string>method</string> </key>
<value> <string>POST</string> </value>
</item>
<item>
<key> <string>name</string> </key>
<value> <string>TemplateTool_viewDeleteObsoleteTemplateListDialog</string> </value>
</item>
<item>
<key> <string>pt</string> </key>
<value> <string>form_dialog</string> </value>
</item>
<item>
<key> <string>row_length</string> </key>
<value> <int>4</int> </value>
</item>
<item>
<key> <string>stored_encoding</string> </key>
<value> <string>UTF-8</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Delete Obsolete Templates</string> </value>
</item>
<item>
<key> <string>unicode_mode</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>update_action</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>update_action_title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
89
\ No newline at end of file
90
\ No newline at end of file
Applied Rule | view
Simulation Movement | view
Simulation Tool | view
Template Tool | delete_obsolete_template_list
portal_properties | consistency
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment