Commit 64ac265f authored by Ivan Tyagov's avatar Ivan Tyagov

Handle possible exception in document ingestion. Inform user with nice message.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@14835 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent aca22447
......@@ -74,6 +74,11 @@
\n
**kw -- remaining params passed to the constructor\n
"""\n
\n
from Products.ERP5.Document.Document import ConversionError\n
from xmlrpclib import Fault\n
from socket import error as SocketError\n
\n
# Do some processing of parameters cause we do not use ERP5 Form here\n
if contribute_classification:\n
kw[\'classification\'] = contribute_classification\n
......@@ -93,13 +98,25 @@ kw[\'discover_metadata\'] = 0 \n
editable_mode = 1\n
file_name = getattr(contribute_file, \'filename\', None)\n
# try to ingest file\n
failure = 0\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
except ConversionError, Fault:\n
# there are errors during ingestion content\n
msg = \'There was a problem during ingestion: ${exception}. Please try again later.\'\n
msg = context.Base_translateString(msg, mapping=dict(exception=str(e)))\n
failure = 1\n
msg = \'Sorry, there was a problem during conversion of your document.\'\n
except SocketError:\n
# conversion server is down\n
failure = 1\n
msg = \'Sorry, the conversion server is down. Please try again later.\'\n
except (TypeError, KeyError, AttributeError):\n
# there\'s an unknow error occured\n
failure = 1\n
msg = \'Sorry, unknow error occured.\'\n
\n
if failure:\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
......@@ -161,21 +178,29 @@ return target.Base_redirect(\'view\', \n
<string>contribute_source_project</string>
<string>contribute_portal_type</string>
<string>kw</string>
<string>Products.ERP5.Document.Document</string>
<string>ConversionError</string>
<string>xmlrpclib</string>
<string>Fault</string>
<string>socket</string>
<string>error</string>
<string>SocketError</string>
<string>_write_</string>
<string>None</string>
<string>editable_mode</string>
<string>getattr</string>
<string>file_name</string>
<string>failure</string>
<string>_apply_</string>
<string>_getattr_</string>
<string>context</string>
<string>new_content</string>
<string>merged_content</string>
<string>Exception</string>
<string>e</string>
<string>msg</string>
<string>TypeError</string>
<string>KeyError</string>
<string>AttributeError</string>
<string>dict</string>
<string>str</string>
<string>target</string>
</tuple>
</value>
......
549
\ No newline at end of file
552
\ 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