Commit 12c32cf4 authored by Fabien Morin's avatar Fabien Morin

make synchronous_metadata_discovery applicable for both doc & url. And add new...

make synchronous_metadata_discovery applicable for both doc & url. And add new parameter follow_up_list.

Reviewed by Ivan

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@35673 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 8a905fc6
...@@ -74,62 +74,66 @@ if portal_type not in MARKER:\n ...@@ -74,62 +74,66 @@ if portal_type not in MARKER:\n
document_kw[\'portal_type\'] = portal_type\n document_kw[\'portal_type\'] = portal_type\n
if classification not in MARKER:\n if classification not in MARKER:\n
document_kw[\'classification\'] = classification\n document_kw[\'classification\'] = classification\n
if follow_up_list:\n
document_kw[\'follow_up_list\'] = follow_up_list\n
\n \n
document_kw.update({\'discover_metadata\': not synchronous_metadata_discovery})\n
if url is not None:\n if url is not None:\n
# we contribute and URL, this happens entirely asynchronous\n # we contribute and URL, this happens entirely asynchronous\n
document = portal_contributions.newContentFromURL(url = url, \n document = portal_contributions.newContentFromURL(url = url,\n
**document_kw)\n **document_kw)\n
file_name=document.getId()\n
message = translateString("URL contributed successfully.")\n message = translateString("URL contributed successfully.")\n
else:\n else:\n
# contribute file\n # contribute file\n
file_name = getattr(file, \'filename\', None)\n file_name = getattr(file, \'filename\', None)\n
is_existing_document_updated = False\n is_existing_document_updated = False\n
document_kw.update({\'file\': file,\n document_kw.update({\'file\': file,\n
\'file_name\': file_name,\n \'file_name\': file_name,})\n
\'discover_metadata\': not synchronous_metadata_discovery})\n
document = portal_contributions.newContent(**document_kw)\n document = portal_contributions.newContent(**document_kw)\n
if synchronous_metadata_discovery:\n \n
# we need to do all synchronously, in other case portal_contributions will do\n if synchronous_metadata_discovery:\n
# this in an activity\n # we need to do all synchronously, in other case portal_contributions will do\n
if document.isSupportBaseDataConversion():\n # this in an activity\n
document.processFile()\n if document.isSupportBaseDataConversion():\n
merged_document = document.Document_convertToBaseFormatAndDiscoverMetadata(\n document.processFile()\n
file_name=file_name)\n merged_document = document.Document_convertToBaseFormatAndDiscoverMetadata(\n
is_existing_document_updated = (merged_document!=document)\n file_name=file_name)\n
document = merged_document\n is_existing_document_updated = (merged_document!=document)\n
# introspect document and find editable properties\n document = merged_document\n
# then use kw and try to get values in two available modes: the\n # introspect document and find editable properties\n
# script coulbe be called: from ERP5 From or directly from Python script\n # then use kw and try to get values in two available modes: the\n
document_edit_kw = {}\n # script coulbe be called: from ERP5 From or directly from Python script\n
property_id_list = document.propertyIds()\n document_edit_kw = {}\n
for key in property_id_list:\n property_id_list = document.propertyIds()\n
value = kw.get(key, kw.get(\'field_your_%s\' %key, kw.get(\'field_my_%s\' %key, None)))\n for key in property_id_list:\n
if value not in MARKER:\n value = kw.get(key, kw.get(\'field_your_%s\' %key, kw.get(\'field_my_%s\' %key, None)))\n
document_edit_kw[key] = value\n if value not in MARKER:\n
if attach_document_to_context:\n document_edit_kw[key] = value\n
# attach document to current context using follow_up\n if attach_document_to_context:\n
follow_up_list = document.getFollowUpValueList()\n # attach document to current context using follow_up\n
if context not in follow_up_list:\n follow_up_list = document.getFollowUpValueList()\n
# attach to context only if not already attached\n if context not in follow_up_list:\n
follow_up_list.append(context)\n # attach to context only if not already attached\n
document.setFollowUpValueList([x.getRelativeUrl() for x in follow_up_list])\n follow_up_list.append(context)\n
# edit document \n document.setFollowUpValueList([x.getRelativeUrl() for x in follow_up_list])\n
if document_edit_kw is not {}:\n # edit document \n
document.edit(**document_edit_kw)\n if document_edit_kw is not {}:\n
document_portal_type = document.getTranslatedPortalType()\n document.edit(**document_edit_kw)\n
if not is_existing_document_updated:\n document_portal_type = document.getTranslatedPortalType()\n
message = translateString(\'${portal_type} created successfully.\',\n if not is_existing_document_updated:\n
mapping=dict(portal_type=document_portal_type))\n message = translateString(\'${portal_type} created successfully.\',\n
else:\n mapping=dict(portal_type=document_portal_type))\n
message = translateString(\'${portal_type} updated successfully.\',\n else:\n
mapping=dict(portal_type=document_portal_type))\n message = translateString(\'${portal_type} updated successfully.\',\n
mapping=dict(portal_type=document_portal_type))\n
\n \n
if redirect_to_document or redirect_url is not None:\n if redirect_to_document or redirect_url is not None:\n
# this is an UI mode where script should handle HTTP redirects and is likely used\n # this is an UI mode where script should handle HTTP redirects and is likely used\n
# by ERP5 form\n # by ERP5 form\n
if redirect_to_document and document is not None:\n if redirect_to_document and document is not None:\n
# explicitly required to view ingested document\n # explicitly required to view ingested document\n
return document.Base_redirect(\'view\', \n return document.Base_redirect(\'view\',\n
keep_items={\'portal_status_message\': message,\n keep_items={\'portal_status_message\': message,\n
\'editable_mode\': editable_mode})\n \'editable_mode\': editable_mode})\n
elif redirect_url is not None:\n elif redirect_url is not None:\n
...@@ -151,7 +155,7 @@ return document\n ...@@ -151,7 +155,7 @@ return document\n
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>file=None, url=None, portal_type=None, classification=None, synchronous_metadata_discovery=None, redirect_to_document=None, attach_document_to_context=False, use_context_for_container=False, redirect_url=None, editable_mode = 1, **kw</string> </value> <value> <string>file=None, url=None, portal_type=None, classification=None, synchronous_metadata_discovery=None, redirect_to_document=None, attach_document_to_context=False, use_context_for_container=False, redirect_url=None, editable_mode = 1, follow_up_list=None, **kw</string> </value>
</item> </item>
<item> <item>
<key> <string>errors</string> </key> <key> <string>errors</string> </key>
...@@ -171,7 +175,7 @@ return document\n ...@@ -171,7 +175,7 @@ return document\n
<dictionary> <dictionary>
<item> <item>
<key> <string>co_argcount</string> </key> <key> <string>co_argcount</string> </key>
<value> <int>10</int> </value> <value> <int>11</int> </value>
</item> </item>
<item> <item>
<key> <string>co_varnames</string> </key> <key> <string>co_varnames</string> </key>
...@@ -187,6 +191,7 @@ return document\n ...@@ -187,6 +191,7 @@ return document\n
<string>use_context_for_container</string> <string>use_context_for_container</string>
<string>redirect_url</string> <string>redirect_url</string>
<string>editable_mode</string> <string>editable_mode</string>
<string>follow_up_list</string>
<string>kw</string> <string>kw</string>
<string>Products.ERP5Type.Message</string> <string>Products.ERP5Type.Message</string>
<string>translateString</string> <string>translateString</string>
...@@ -201,9 +206,9 @@ return document\n ...@@ -201,9 +206,9 @@ return document\n
<string>_write_</string> <string>_write_</string>
<string>_apply_</string> <string>_apply_</string>
<string>document</string> <string>document</string>
<string>file_name</string>
<string>message</string> <string>message</string>
<string>getattr</string> <string>getattr</string>
<string>file_name</string>
<string>is_existing_document_updated</string> <string>is_existing_document_updated</string>
<string>merged_document</string> <string>merged_document</string>
<string>document_edit_kw</string> <string>document_edit_kw</string>
...@@ -211,7 +216,6 @@ return document\n ...@@ -211,7 +216,6 @@ return document\n
<string>_getiter_</string> <string>_getiter_</string>
<string>key</string> <string>key</string>
<string>value</string> <string>value</string>
<string>follow_up_list</string>
<string>append</string> <string>append</string>
<string>$append0</string> <string>$append0</string>
<string>x</string> <string>x</string>
...@@ -241,6 +245,7 @@ return document\n ...@@ -241,6 +245,7 @@ return document\n
<int>0</int> <int>0</int>
<none/> <none/>
<int>1</int> <int>1</int>
<none/>
</tuple> </tuple>
</value> </value>
</item> </item>
......
94 93
\ 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