Commit aee05d0c authored by Georgios Dagkakis's avatar Georgios Dagkakis

erp5_core: cleanups in Folder_delete script

- Remove useless conditions of "if True"
- No use to use try-except-else, since all except branches
either raise or return
- Remove trailing whitespaces
parent e051c03e
...@@ -32,86 +32,83 @@ if not listbox_uid: ...@@ -32,86 +32,83 @@ if not listbox_uid:
'portal_status_level': "warning"}) 'portal_status_level': "warning"})
if True: # already filters out documents with relations that cannot be deleted
# already filters out documents with relations that cannot be deleted object_list = context.Folder_getDeleteObjectList(uid=listbox_uid)
object_list = context.Folder_getDeleteObjectList(uid=listbox_uid) object_not_deletable_len = len(listbox_uid) - len(object_list)
object_not_deletable_len = len(listbox_uid) - len(object_list)
# some documents cannot be deleted thus we stop and warn the user
# some documents cannot be deleted thus we stop and warn the user if object_not_deletable_len == 1:
if object_not_deletable_len == 1: return context.Base_redirect(keep_items={
return context.Base_redirect(keep_items={ 'portal_status_message': translate("Sorry, 1 item is in use."),
'portal_status_message': translate("Sorry, 1 item is in use."), 'portal_status_level': "warning"})
'portal_status_level': "warning"}) elif object_not_deletable_len > 1:
elif object_not_deletable_len > 1: return context.Base_redirect(keep_items={
return context.Base_redirect(keep_items={ 'portal_status_message': translate("Sorry, ${count} items are in use.", mapping={'count': str(object_not_deletable_len)}),
'portal_status_message': translate("Sorry, ${count} items are in use.", mapping={'count': str(object_not_deletable_len)}), 'portal_status_level': "warning"})
'portal_status_level': "warning"})
# Do not delete objects which have a workflow history
if True: object_to_remove_list = []
object_to_delete_list = []
# Do not delete objects which have a workflow history
object_to_remove_list = [] for obj in object_list:
object_to_delete_list = []
history_dict = obj.Base_getWorkflowHistory()
for obj in object_list: history_dict.pop('edit_workflow', None)
if history_dict == {} or obj.aq_parent.portal_type=='Preference':
history_dict = obj.Base_getWorkflowHistory() # templates inside preference will be unconditionnaly physically
history_dict.pop('edit_workflow', None) # deleted
if history_dict == {} or obj.aq_parent.portal_type=='Preference': object_to_remove_list.append(obj)
# templates inside preference will be unconditionnaly physically else:
# deleted # If a workflow manage a history,
object_to_remove_list.append(obj) # object should not be removed, but only put in state deleted
else: object_to_delete_list.append(obj)
# If a workflow manage a history,
# object should not be removed, but only put in state deleted # Remove some objects
object_to_delete_list.append(obj) try:
if object_to_remove_list:
# Remove some objects if context.portal_type == 'Preference':
try: # Templates inside preference are not indexed, so we cannot pass
if object_to_remove_list: # uids= to manage_delObjects and have to use ids=
if context.portal_type == 'Preference': context.manage_delObjects(
# Templates inside preference are not indexed, so we cannot pass ids=[x.getId() for x in object_to_remove_list],
# uids= to manage_delObjects and have to use ids= REQUEST=REQUEST)
context.manage_delObjects( portal.portal_caches.clearCacheFactory('erp5_ui_medium')
ids=[x.getId() for x in object_to_remove_list], else:
REQUEST=REQUEST) context.manage_delObjects(
portal.portal_caches.clearCacheFactory('erp5_ui_medium') uids=[x.getUid() for x in object_to_remove_list],
else: REQUEST=REQUEST)
context.manage_delObjects( except ConflictError:
uids=[x.getUid() for x in object_to_remove_list], raise
REQUEST=REQUEST) except Exception as error:
except ConflictError: return context.Base_renderMessage(str(error), "error")
raise
except Exception as error: object_ids = [x.getId() for x in object_to_remove_list]
return context.Base_renderMessage(str(error), "error") comment = Base_translateString('Deleted objects: ${object_ids}',
else: # in the case of no exception raised report sucess mapping={'object_ids': object_ids})
object_ids = [x.getId() for x in object_to_remove_list] try:
comment = Base_translateString('Deleted objects: ${object_ids}', # record object deletion in workflow history
mapping={'object_ids': object_ids}) portal.portal_workflow.doActionFor(context, 'edit_action',
try: comment=comment)
# record object deletion in workflow history except WorkflowException:
portal.portal_workflow.doActionFor(context, 'edit_action', # no 'edit_action' transition for this container
comment=comment) pass
except WorkflowException:
# no 'edit_action' transition for this container message = Base_translateString("Deleted.")
pass
# Try to call "delete_action" workflow transition on documents which defined it
message = Base_translateString("Deleted.") # Failure of such a call is not a failure globally. The document was deleted anyway
for obj in object_to_delete_list:
# Try to call "delete_action" workflow transition on documents which defined it # Hidden transition (without a message displayed)
# Failure of such a call is not a failure globally. The document was deleted anyway # are not returned by getActionsFor
for obj in object_to_delete_list: try:
# Hidden transition (without a message displayed) portal.portal_workflow.doActionFor(obj, 'delete_action')
# are not returned by getActionsFor except ConflictError:
try: raise
portal.portal_workflow.doActionFor(obj, 'delete_action') except Exception:
except ConflictError: pass
raise
except Exception: # make sure nothing is checked after
pass if selection_name:
portal.portal_selections.setSelectionCheckedUidsFor(selection_name, ())
# make sure nothing is checked after
if selection_name:
portal.portal_selections.setSelectionCheckedUidsFor(selection_name, ())
return context.Base_redirect(form_id, keep_items={"portal_status_message": str(message)}) return context.Base_redirect(form_id, keep_items={"portal_status_message": str(message)})
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