Commit 3a76f8db authored by Romain Courteaud's avatar Romain Courteaud

Modify Folder_delete.

The trash button does not allow anymore to remove object from the database when there is a workflow associated to this object (excepted for edit_workflow).
In such case, there must be a workflow transition called "delete_action", which changes the state of the object to "deleted".

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@10004 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 2210ab5e
...@@ -106,42 +106,101 @@ if error:\n ...@@ -106,42 +106,101 @@ if error:\n
elif uids is not None:\n elif uids is not None:\n
# Check if there is some related objets.\n # Check if there is some related objets.\n
object_used = 0\n object_used = 0\n
for uid in uids:\n \n
object = context.portal_catalog(uid=uid)[0].getObject()\n object_list = [x.getObject() for x in context.portal_catalog(uid=uids)]\n
if Object_hasRelation(object):\n object_used = sum([Object_hasRelation(x) for x in object_list])\n
object_used += 1\n \n
if object_used>0:\n if object_used > 0:\n
if object_used == 1:\n if object_used == 1:\n
message = N_("Sorry,+1+Item+Is+In+Use.")\n message = N_("Sorry,+1+Item+Is+In+Use.")\n
qs = \'?portal_status_message=%s\' % message\n
else:\n else:\n
message = N_("Sorry,+${count}+Items+Are+In+Use.",\n message = N_("Sorry,+${count}+Items+Are+In+Use.",\n
mapping={\'count\': repr(object_used)})\n mapping={\'count\': repr(object_used)})\n
qs = \'?portal_status_message=%s\' % message \n qs = \'?portal_status_message=%s\' % message \n
else:\n else:\n
try : \n \n
object_ids = \', \'.join([x.getObject().getId()\n # Do not delete objects which have a workflow history \n
for x in context.portal_catalog(uid=uids)])\n object_to_remove_list = []\n
context.manage_delObjects(uids=uids, REQUEST=REQUEST)\n object_to_delete_list = []\n
\n
for object in object_list:\n
\n
workflow_id_list = [x.id for x in object.portal_workflow.getWorkflowsFor(object)]\n
# XXX Remove edit_workflow, which should no prevent deletion\n
try:\n
workflow_id_list.remove("edit_workflow")\n
except ValueError:\n
pass\n
\n
# If a workflow manage a history, \n
# object should not be removed, but only put in state deleted\n
for wf_id in workflow_id_list:\n
# It is important to use the history variable\n
try:\n
list_history_item = context.portal_workflow.getInfoFor(\n
ob=object, name="history", wf_id=wf_id)\n
# XXX Can not use WorkflowException\n
except ConflictError:\n
raise\n
except:\n
pass\n
else:\n
object_to_delete_list.append(object)\n
break\n
else:\n
object_to_remove_list.append(object)\n
\n
# Remove some objects\n
try: \n
if object_to_remove_list != []:\n
context.manage_delObjects(\n
uids=[x.getUid() for x in object_to_remove_list],\n
REQUEST=REQUEST)\n
except ConflictError: \n
raise\n
except Exception, message : \n
qs = \'?portal_status_message=%s\' % message\n
else:\n
object_ids = [x.getId() for x in object_to_remove_list]\n
comment = N_(\'Deleted objects: ${object_ids}\',\n comment = N_(\'Deleted objects: ${object_ids}\',\n
mapping={\'object_ids\': object_ids})\n mapping={\'object_ids\': object_ids})\n
if \'edit_action\' in [x.get(\'id\', \'\') for x in\n if \'edit_action\' in [x.get(\'id\', \'\') for x in\n
context.portal_workflow.getActionsFor(context)] :\n context.portal_workflow.getActionsFor(context)]:\n
# record object deletion in workflow history\n # record object deletion in workflow history\n
context.getPortalObject().portal_workflow.doActionFor(\n context.getPortalObject().portal_workflow.doActionFor(\n
context,\n context,\n
\'edit_action\',\n \'edit_action\',\n
comment=comment)\n comment=comment)\n
\n
message = N_("Deleted.")\n message = N_("Deleted.")\n
\n
# Change workflow state of others objects\n
not_deleted_count = 0\n
for object in object_to_delete_list:\n
try:\n
context.getPortalObject().portal_workflow.doActionFor(\n
object,\n
\'delete_action\')\n
except ConflictError:\n
raise\n
except:\n
not_deleted_count += 1\n
pass\n
\n
# Generate message\n
if not_deleted_count == 1:\n
message = N_("Sorry+You+Can+Not+Delete+${count}+Item.",\n
mapping={\'count\': not_deleted_count})\n
elif not_deleted_count > 1:\n
message = N_("Sorry+You+Can+Not+Delete+${count}+Items.",\n
mapping={\'count\': not_deleted_count})\n
qs = \'?portal_status_message=%s\' % message\n qs = \'?portal_status_message=%s\' % message\n
except ConflictError : raise\n \n
except Exception, message : \n
qs = \'?portal_status_message=%s\' % message\n
else:\n else:\n
message = N_("Please+select+one+or+more+items+first.")\n message = N_("Please+select+one+or+more+items+first.")\n
qs = \'?portal_status_message=%s\' % message\n qs = \'?portal_status_message=%s\' % message\n
\n \n
return REQUEST.RESPONSE.redirect( ret_url + qs )\n return REQUEST.RESPONSE.redirect("%s%s" % (ret_url, qs))\n
]]></string> </value> ]]></string> </value>
...@@ -152,12 +211,24 @@ return REQUEST.RESPONSE.redirect( ret_url + qs )\n ...@@ -152,12 +211,24 @@ return REQUEST.RESPONSE.redirect( ret_url + qs )\n
<none/> <none/>
</value> </value>
</item> </item>
<item>
<key> <string>_dav_writelocks</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item> <item>
<key> <string>_filepath</string> </key> <key> <string>_filepath</string> </key>
<value> <value>
<none/> <none/>
</value> </value>
</item> </item>
<item>
<key> <string>_owner</string> </key>
<value>
<none/>
</value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>form_id=\'\',selection_index=None,object_uid=None,selection_name=None,field_id=None,uids=None,cancel_url=\'\',listbox_uid=[],md5_object_uid_list=\'\'</string> </value> <value> <string>form_id=\'\',selection_index=None,object_uid=None,selection_name=None,field_id=None,uids=None,cancel_url=\'\',listbox_uid=[],md5_object_uid_list=\'\'</string> </value>
...@@ -210,17 +281,24 @@ return REQUEST.RESPONSE.redirect( ret_url + qs )\n ...@@ -210,17 +281,24 @@ return REQUEST.RESPONSE.redirect( ret_url + qs )\n
<string>message</string> <string>message</string>
<string>None</string> <string>None</string>
<string>object_used</string> <string>object_used</string>
<string>_getiter_</string>
<string>uid</string>
<string>_getitem_</string>
<string>object</string>
<string>repr</string>
<string>append</string> <string>append</string>
<string>$append0</string> <string>$append0</string>
<string>_getiter_</string>
<string>x</string> <string>x</string>
<string>object_list</string>
<string>sum</string>
<string>repr</string>
<string>object_to_remove_list</string>
<string>object_to_delete_list</string>
<string>object</string>
<string>workflow_id_list</string>
<string>ValueError</string>
<string>wf_id</string>
<string>list_history_item</string>
<string>Exception</string>
<string>object_ids</string> <string>object_ids</string>
<string>comment</string> <string>comment</string>
<string>Exception</string> <string>not_deleted_count</string>
</tuple> </tuple>
</value> </value>
</item> </item>
...@@ -262,4 +340,25 @@ return REQUEST.RESPONSE.redirect( ret_url + qs )\n ...@@ -262,4 +340,25 @@ return REQUEST.RESPONSE.redirect( ret_url + qs )\n
</dictionary> </dictionary>
</pickle> </pickle>
</record> </record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<tuple>
<tuple>
<string>Persistence</string>
<string>PersistentMapping</string>
</tuple>
<none/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_container</string> </key>
<value>
<dictionary/>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData> </ZopeData>
67 68
\ No newline at end of file \ 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