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,28 +32,25 @@ if not listbox_uid:
'portal_status_level': "warning"})
if True:
# already filters out documents with relations that cannot be deleted
object_list = context.Folder_getDeleteObjectList(uid=listbox_uid)
object_not_deletable_len = len(listbox_uid) - len(object_list)
# already filters out documents with relations that cannot be deleted
object_list = context.Folder_getDeleteObjectList(uid=listbox_uid)
object_not_deletable_len = len(listbox_uid) - len(object_list)
# some documents cannot be deleted thus we stop and warn the user
if object_not_deletable_len == 1:
# some documents cannot be deleted thus we stop and warn the user
if object_not_deletable_len == 1:
return context.Base_redirect(keep_items={
'portal_status_message': translate("Sorry, 1 item is in use."),
'portal_status_level': "warning"})
elif object_not_deletable_len > 1:
elif object_not_deletable_len > 1:
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_level': "warning"})
if True:
# Do not delete objects which have a workflow history
object_to_remove_list = []
object_to_delete_list = []
# Do not delete objects which have a workflow history
object_to_remove_list = []
object_to_delete_list = []
for obj in object_list:
for obj in object_list:
history_dict = obj.Base_getWorkflowHistory()
history_dict.pop('edit_workflow', None)
......@@ -66,8 +63,8 @@ if True:
# object should not be removed, but only put in state deleted
object_to_delete_list.append(obj)
# Remove some objects
try:
# Remove some objects
try:
if object_to_remove_list:
if context.portal_type == 'Preference':
# Templates inside preference are not indexed, so we cannot pass
......@@ -80,27 +77,27 @@ if True:
context.manage_delObjects(
uids=[x.getUid() for x in object_to_remove_list],
REQUEST=REQUEST)
except ConflictError:
except ConflictError:
raise
except Exception as error:
except Exception as error:
return context.Base_renderMessage(str(error), "error")
else: # in the case of no exception raised report sucess
object_ids = [x.getId() for x in object_to_remove_list]
comment = Base_translateString('Deleted objects: ${object_ids}',
object_ids = [x.getId() for x in object_to_remove_list]
comment = Base_translateString('Deleted objects: ${object_ids}',
mapping={'object_ids': object_ids})
try:
try:
# record object deletion in workflow history
portal.portal_workflow.doActionFor(context, 'edit_action',
comment=comment)
except WorkflowException:
except WorkflowException:
# no 'edit_action' transition for this container
pass
message = Base_translateString("Deleted.")
message = Base_translateString("Deleted.")
# Try to call "delete_action" workflow transition on documents which defined it
# 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
# Failure of such a call is not a failure globally. The document was deleted anyway
for obj in object_to_delete_list:
# Hidden transition (without a message displayed)
# are not returned by getActionsFor
try:
......@@ -110,8 +107,8 @@ if True:
except Exception:
pass
# make sure nothing is checked after
if 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)})
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