Commit b9befcd7 authored by Ivan Tyagov's avatar Ivan Tyagov

Catch exception during content ingestion and show more friendly error message.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@14473 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 432bd177
......@@ -87,32 +87,39 @@ if contribute_portal_type:\n
if contribute_file is not None:\n
kw[\'file\'] = contribute_file\n
\n
kw[\'discover_metadata\'] = 0 # We want to discover metadata synchronously\n
# We want to discover metadata synchronously\n
kw[\'discover_metadata\'] = 0 \n
\n
#try:\n
if 1:\n
new_content = context.portal_contributions.newContent(**kw)\n
if hasattr(contribute_file, \'filename\'):\n
file_name = contribute_file.filename\n
else:\n
file_name = None\n
\n
merged_content = new_content.discoverMetadata(file_name=file_name) # Consider putting an exception handler\n
editable_mode = 1\n
file_name = getattr(contribute_file, \'filename\', None)\n
# try to ingest file\n
try:\n
new_content = context.portal_contributions.newContent(**kw)\n
merged_content = new_content.discoverMetadata(file_name=file_name)\n
except Exception, e:\n
# there are errors during ingestion content\n
msg = \'There was a problem during ingestion. Please try again later.\'\n
msg = context.Base_translateString(msg)\n
return context.Base_redirect(\'WebSite_viewAsSCALE\', \n
keep_items=dict(portal_status_message=msg,\n
editable_mode=0))\n
# successful ingestion, show appropriate message\n
if merged_content is not new_content:\n
msg = context.Base_translateString(\'Document successfully updated\')\n
target = merged_content\n
else:\n
msg = context.Base_translateString(\'Document successfully created\')\n
target = new_content\n
editable_mode = 1\n
else:\n
#except Exception, e:\n
msg = \'There was a problem: ${exception}\'\n
msg = context.Base_translateString(msg, mapping=dict(exception=str(e)))\n
target = context\n
editable_mode = 0\n
\n
return target.Base_redirect(\'view\', keep_items=dict(portal_status_message=msg, editable_mode=editable_mode))\n
return target.Base_redirect(\'view\', \n
keep_items=dict(portal_status_message=msg, \n
editable_mode=editable_mode))\n
</string> </value>
</item>
<item>
......@@ -127,12 +134,6 @@ return target.Base_redirect(\'view\', keep_items=dict(portal_status_message=msg,
<none/>
</value>
</item>
<item>
<key> <string>_owner</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>contribute_file=None, contribute_classification=None, contribute_source_project=None, contribute_portal_type=None, **kw</string> </value>
......@@ -168,19 +169,20 @@ return target.Base_redirect(\'view\', keep_items=dict(portal_status_message=msg,
<string>kw</string>
<string>_write_</string>
<string>None</string>
<string>editable_mode</string>
<string>getattr</string>
<string>file_name</string>
<string>_apply_</string>
<string>_getattr_</string>
<string>context</string>
<string>new_content</string>
<string>hasattr</string>
<string>file_name</string>
<string>merged_content</string>
<string>Exception</string>
<string>e</string>
<string>msg</string>
<string>target</string>
<string>editable_mode</string>
<string>dict</string>
<string>target</string>
<string>str</string>
<string>e</string>
</tuple>
</value>
</item>
......
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