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,21 +74,25 @@ if portal_type not in MARKER:\n ...@@ -74,21 +74,25 @@ 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
if synchronous_metadata_discovery:\n
# we need to do all synchronously, in other case portal_contributions will do\n # we need to do all synchronously, in other case portal_contributions will do\n
# this in an activity\n # this in an activity\n
if document.isSupportBaseDataConversion():\n if document.isSupportBaseDataConversion():\n
...@@ -97,30 +101,30 @@ else:\n ...@@ -97,30 +101,30 @@ else:\n
file_name=file_name)\n file_name=file_name)\n
is_existing_document_updated = (merged_document!=document)\n is_existing_document_updated = (merged_document!=document)\n
document = merged_document\n document = merged_document\n
# introspect document and find editable properties\n # introspect document and find editable properties\n
# then use kw and try to get values in two available modes: the\n # then use kw and try to get values in two available modes: the\n
# script coulbe be called: from ERP5 From or directly from Python script\n # script coulbe be called: from ERP5 From or directly from Python script\n
document_edit_kw = {}\n document_edit_kw = {}\n
property_id_list = document.propertyIds()\n property_id_list = document.propertyIds()\n
for key in property_id_list:\n for key in property_id_list:\n
value = kw.get(key, kw.get(\'field_your_%s\' %key, kw.get(\'field_my_%s\' %key, None)))\n value = kw.get(key, kw.get(\'field_your_%s\' %key, kw.get(\'field_my_%s\' %key, None)))\n
if value not in MARKER:\n if value not in MARKER:\n
document_edit_kw[key] = value\n document_edit_kw[key] = value\n
if attach_document_to_context:\n if attach_document_to_context:\n
# attach document to current context using follow_up\n # attach document to current context using follow_up\n
follow_up_list = document.getFollowUpValueList()\n follow_up_list = document.getFollowUpValueList()\n
if context not in follow_up_list:\n if context not in follow_up_list:\n
# attach to context only if not already attached\n # attach to context only if not already attached\n
follow_up_list.append(context)\n follow_up_list.append(context)\n
document.setFollowUpValueList([x.getRelativeUrl() for x in follow_up_list])\n document.setFollowUpValueList([x.getRelativeUrl() for x in follow_up_list])\n
# edit document \n # edit document \n
if document_edit_kw is not {}:\n if document_edit_kw is not {}:\n
document.edit(**document_edit_kw)\n document.edit(**document_edit_kw)\n
document_portal_type = document.getTranslatedPortalType()\n document_portal_type = document.getTranslatedPortalType()\n
if not is_existing_document_updated:\n if not is_existing_document_updated:\n
message = translateString(\'${portal_type} created successfully.\',\n message = translateString(\'${portal_type} created successfully.\',\n
mapping=dict(portal_type=document_portal_type))\n mapping=dict(portal_type=document_portal_type))\n
else:\n else:\n
message = translateString(\'${portal_type} updated successfully.\',\n message = translateString(\'${portal_type} updated successfully.\',\n
mapping=dict(portal_type=document_portal_type))\n mapping=dict(portal_type=document_portal_type))\n
\n \n
...@@ -129,7 +133,7 @@ if redirect_to_document or redirect_url is not None:\n ...@@ -129,7 +133,7 @@ if redirect_to_document or redirect_url is not None:\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