Commit 1840301d authored by Ivan Tyagov's avatar Ivan Tyagov

Add a general purpose contribute script that will replace old ones.

Make all dialog forms use it.
Change title of an action from 'Contribute Content' to 'Contribute File' to match exact action.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@32901 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent dbfcfc38
...@@ -59,7 +59,7 @@ ...@@ -59,7 +59,7 @@
</item> </item>
<item> <item>
<key> <string>title</string> </key> <key> <string>title</string> </key>
<value> <string>Contribute Content</string> </value> <value> <string>Contribute File</string> </value>
</item> </item>
<item> <item>
<key> <string>visible</string> </key> <key> <string>visible</string> </key>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
<tuple/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>"""\n
Use to contribute file to ERP5.\n
"""\n
MARKER = [\'\', None]\n
portal = context.getPortalObject()\n
portal_contributions = portal.portal_contributions\n
\n
document_kw = {}\n
if use_context_for_container:\n
document_kw[\'container_path\'] = context.getRelativeUrl()\n
if portal_type not in MARKER:\n
document_kw[\'portal_type\'] = portal_type\n
if classification not in MARKER:\n
document_kw[\'classification\'] = classification\n
\n
if url is not None:\n
# we contribute and URL, this happens entirely asynchronous\n
document = portal_contributions.newContentFromURL(url = url, \n
**document_kw)\n
message = "URL contributed successfully."\n
else:\n
# contribute file\n
file_name = getattr(file, \'filename\', None)\n
is_existing_document_updated = False\n
document_kw.update({\'file\': file,\n
\'file_name\': file_name,\n
\'discover_metadata\': not synchronous_metadata_discovery})\n
document = portal_contributions.newContent(**document_kw)\n
if synchronous_metadata_discovery:\n
# we need to do all synchronously, in other case portal_contributions will do\n
# this in an activity\n
if document.isSupportBaseDataConversion():\n
document.processFile()\n
merged_document = document.Document_convertToBaseFormatAndDiscoverMetadata(\n
file_name=file_name)\n
is_existing_document_updated = (merged_document!=document)\n
document = merged_document\n
# XXX: introspect document and find editable properties\n
# then use kw and try to get values in two available modes the\n
# script coulb be called: from ERP5 From or directly from Python script\n
document_edit_kw = {}\n
for key in [\'title\', \'reference\', \'group\', \'source_project\', \n
\'short_title\', \'language\', \'version\', \'description\']:\n
value = kw.get(key, kw.get(\'field_your_%s\' %key, kw.get(\'field_my_%s\' %key, None)))\n
if value is not None:\n
document_edit_kw[key] = value\n
if attach_document_to_context:\n
# attach document to current context using follow_up\n
follow_up_list = document.getFollowUpValueList()\n
follow_up_list.append(context)\n
document.setFollowUpValueList([x.getRelativeUrl() for x in follow_up_list])\n
# edit document \n
if document_edit_kw is not {}:\n
document.edit(**document_edit_kw)\n
document_portal_type = document.getTranslatedPortalType()\n
if not is_existing_document_updated:\n
message = \'%s created successfully.\' %document_portal_type\n
else:\n
message = \'%s updated successfully.\' %document_portal_type\n
\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
# by ERP5 form\n
message = context.Base_translateString(message)\n
if redirect_to_document:\n
# explicitly requried to redirect to ingested document\n
return document.Base_redirect(\'view\', \n
keep_items=dict(portal_status_message=message))\n
elif redirect_url is not None:\n
# redirect URL has been supplied by caller\n
from ZTUtils import make_query\n
redirect_url= \'%s?%s\' %(redirect_url, \n
make_query(dict(portal_status_message=message)))\n
return context.REQUEST.RESPONSE.redirect(redirect_url)\n
\n
# return document (for non UI mode)\n
return document\n
</string> </value>
</item>
<item>
<key> <string>_code</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>file=None, url=None, portal_type=None, classification=None, synchronous_metadata_discovery=False, redirect_to_document=False, attach_document_to_context=False, use_context_for_container=False, redirect_url=None, **kw</string> </value>
</item>
<item>
<key> <string>errors</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>func_code</string> </key>
<value>
<object>
<klass>
<global name="FuncCode" module="Shared.DC.Scripts.Signature"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>co_argcount</string> </key>
<value> <int>9</int> </value>
</item>
<item>
<key> <string>co_varnames</string> </key>
<value>
<tuple>
<string>file</string>
<string>url</string>
<string>portal_type</string>
<string>classification</string>
<string>synchronous_metadata_discovery</string>
<string>redirect_to_document</string>
<string>attach_document_to_context</string>
<string>use_context_for_container</string>
<string>redirect_url</string>
<string>kw</string>
<string>None</string>
<string>MARKER</string>
<string>_getattr_</string>
<string>context</string>
<string>portal</string>
<string>portal_contributions</string>
<string>document_kw</string>
<string>_write_</string>
<string>_apply_</string>
<string>document</string>
<string>message</string>
<string>getattr</string>
<string>file_name</string>
<string>False</string>
<string>is_existing_document_updated</string>
<string>merged_document</string>
<string>document_edit_kw</string>
<string>_getiter_</string>
<string>key</string>
<string>value</string>
<string>follow_up_list</string>
<string>append</string>
<string>$append0</string>
<string>x</string>
<string>document_portal_type</string>
<string>dict</string>
<string>ZTUtils</string>
<string>make_query</string>
</tuple>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>func_defaults</string> </key>
<value>
<tuple>
<none/>
<none/>
<none/>
<none/>
<int>0</int>
<int>0</int>
<int>0</int>
<int>0</int>
<none/>
</tuple>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_contribute</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Contribute file or url to ERP5</string> </value>
</item>
<item>
<key> <string>warnings</string> </key>
<value>
<tuple/>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
</item> </item>
<item> <item>
<key> <string>action</string> </key> <key> <string>action</string> </key>
<value> <string>ContributionTool_newContent</string> </value> <value> <string>Base_contribute</string> </value>
</item> </item>
<item> <item>
<key> <string>description</string> </key> <key> <string>description</string> </key>
...@@ -99,6 +99,7 @@ ...@@ -99,6 +99,7 @@
<string>your_classification</string> <string>your_classification</string>
<string>your_portal_type</string> <string>your_portal_type</string>
<string>your_file</string> <string>your_file</string>
<string>your_redirect_url</string>
</list> </list>
</value> </value>
</item> </item>
...@@ -147,6 +148,10 @@ ...@@ -147,6 +148,10 @@
<key> <string>update_action</string> </key> <key> <string>update_action</string> </key>
<value> <string></string> </value> <value> <string></string> </value>
</item> </item>
<item>
<key> <string>update_action_title</string> </key>
<value> <string></string> </value>
</item>
</dictionary> </dictionary>
</pickle> </pickle>
</record> </record>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<global name="ProxyField" module="Products.ERP5Form.ProxyField"/>
<tuple/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>delegated_list</string> </key>
<value>
<list>
<string>css_class</string>
<string>default</string>
<string>hidden</string>
</list>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>your_redirect_url</string> </value>
</item>
<item>
<key> <string>message_values</string> </key>
<value>
<dictionary>
<item>
<key> <string>external_validator_failed</string> </key>
<value> <string>The input failed the external validator.</string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>overrides</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>tales</string> </key>
<value>
<dictionary>
<item>
<key> <string>css_class</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>default</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>hidden</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>values</string> </key>
<value>
<dictionary>
<item>
<key> <string>css_class</string> </key>
<value> <string>hidden_fieldset</string> </value>
</item>
<item>
<key> <string>default</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>field_id</string> </key>
<value> <string>my_string_field</string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string>Base_viewFieldLibrary</string> </value>
</item>
<item>
<key> <string>hidden</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string>Click to edit the target</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<tuple>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
<tuple/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_text</string> </key>
<value> <string>here/absolute_url</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
</item> </item>
<item> <item>
<key> <string>action</string> </key> <key> <string>action</string> </key>
<value> <string>ContributionTool_newContentFromUrl</string> </value> <value> <string>Base_contribute</string> </value>
</item> </item>
<item> <item>
<key> <string>description</string> </key> <key> <string>description</string> </key>
...@@ -99,6 +99,7 @@ ...@@ -99,6 +99,7 @@
<string>your_classification</string> <string>your_classification</string>
<string>your_portal_type</string> <string>your_portal_type</string>
<string>your_url</string> <string>your_url</string>
<string>your_redirect_url</string>
</list> </list>
</value> </value>
</item> </item>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<global name="ProxyField" module="Products.ERP5Form.ProxyField"/>
<tuple/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>delegated_list</string> </key>
<value>
<list>
<string>css_class</string>
<string>default</string>
<string>hidden</string>
</list>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>your_redirect_url</string> </value>
</item>
<item>
<key> <string>message_values</string> </key>
<value>
<dictionary>
<item>
<key> <string>external_validator_failed</string> </key>
<value> <string>The input failed the external validator.</string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>overrides</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>tales</string> </key>
<value>
<dictionary>
<item>
<key> <string>css_class</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>default</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>hidden</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>values</string> </key>
<value>
<dictionary>
<item>
<key> <string>css_class</string> </key>
<value> <string>hidden_fieldset</string> </value>
</item>
<item>
<key> <string>default</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>field_id</string> </key>
<value> <string>my_string_field</string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string>Base_viewFieldLibrary</string> </value>
</item>
<item>
<key> <string>hidden</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string>Click to edit the target</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<tuple>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
<tuple/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_text</string> </key>
<value> <string>here/absolute_url</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
60 61
\ 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