Commit f1984759 authored by Rafael Monnerat's avatar Rafael Monnerat

Unify clone behaviour between usual clone and clone in erp5_web.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@22619 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 0f7d5d16
...@@ -71,12 +71,9 @@ ...@@ -71,12 +71,9 @@
\n \n
Pretty messages are provided to the user.\n Pretty messages are provided to the user.\n
"""\n """\n
\n
translateString = context.Base_translateString\n translateString = context.Base_translateString\n
form_data = context.REQUEST.form\n form_data = context.REQUEST.form\n
\n \n
# First make sure that no document already exists with the\n
# same portal_type, reference, language and version.\n
if clone:\n if clone:\n
portal_type = context.getPortalType()\n portal_type = context.getPortalType()\n
else:\n else:\n
...@@ -94,6 +91,15 @@ if portal_type not in allowed_type_list:\n ...@@ -94,6 +91,15 @@ if portal_type not in allowed_type_list:\n
# prepare query params\n # prepare query params\n
kw = {\'portal_type\' : translateString(portal_type)}\n kw = {\'portal_type\' : translateString(portal_type)}\n
\n \n
if web_mode:\n
script = getattr(context, "Base_checkCloneConsistency", None)\n
if script is not None:\n
msg = script(**form_data)\n
if msg is not None:\n
return context.Base_redirect(form_id, \n
editable_mode=editable_mode,\n
keep_items={\'portal_status_message\': msg})\n
\n
# Standard cloning method\n # Standard cloning method\n
if clone:\n if clone:\n
# We copy contents in place if possible\n # We copy contents in place if possible\n
...@@ -106,10 +112,25 @@ if clone:\n ...@@ -106,10 +112,25 @@ if clone:\n
new_object = directory[paste_result[0][\'new_id\']]\n new_object = directory[paste_result[0][\'new_id\']]\n
message_kind = \'Clone\'\n message_kind = \'Clone\'\n
\n \n
if web_mode:\n
# Edit the objects with some properties\n
# Define a list of field name to take into account in the cloning process\n
ACCEPTABLE_FORM_ID_LIST = [ \'clone_reference\' , \'clone_language\'\n
, \'clone_version\' , \'clone_revision\'\n
, \'clone_title\' , \'clone_short_title\' ] \n
\n
# Set properties to the new object\n
edit_kw = {}\n
property_id_list = new_object.propertyIds()\n
for (key, val) in form_data.items():\n
if key in ACCEPTABLE_FORM_ID_LIST and key[len(\'clone_\'):] in property_id_list:\n
edit_kw[key[len(\'clone_\'):]] = val\n
new_object.edit(**edit_kw)\n
\n
if batch_mode:\n if batch_mode:\n
return new_object\n return new_object\n
else:\n else:\n
if not editable_mode: \n if web_mode and not editable_mode: \n
form_id = \'view\'\n form_id = \'view\'\n
msg = translateString("Created %s ${portal_type}." % message_kind, mapping = kw)\n msg = translateString("Created %s ${portal_type}." % message_kind, mapping = kw)\n
return new_object.Base_redirect(form_id, \n return new_object.Base_redirect(form_id, \n
...@@ -131,7 +152,7 @@ else:\n ...@@ -131,7 +152,7 @@ else:\n
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>clone=1, form_id, editable_mode=0, batch_mode=0</string> </value> <value> <string>clone=1, form_id, web_mode=0, editable_mode=0, batch_mode=0</string> </value>
</item> </item>
<item> <item>
<key> <string>_proxy_roles</string> </key> <key> <string>_proxy_roles</string> </key>
...@@ -157,7 +178,7 @@ else:\n ...@@ -157,7 +178,7 @@ else:\n
<dictionary> <dictionary>
<item> <item>
<key> <string>co_argcount</string> </key> <key> <string>co_argcount</string> </key>
<value> <int>4</int> </value> <value> <int>5</int> </value>
</item> </item>
<item> <item>
<key> <string>co_varnames</string> </key> <key> <string>co_varnames</string> </key>
...@@ -165,6 +186,7 @@ else:\n ...@@ -165,6 +186,7 @@ else:\n
<tuple> <tuple>
<string>clone</string> <string>clone</string>
<string>form_id</string> <string>form_id</string>
<string>web_mode</string>
<string>editable_mode</string> <string>editable_mode</string>
<string>batch_mode</string> <string>batch_mode</string>
<string>_getattr_</string> <string>_getattr_</string>
...@@ -178,13 +200,23 @@ else:\n ...@@ -178,13 +200,23 @@ else:\n
<string>None</string> <string>None</string>
<string>kw</string> <string>kw</string>
<string>getattr</string> <string>getattr</string>
<string>script</string>
<string>_apply_</string>
<string>msg</string>
<string>directory</string> <string>directory</string>
<string>original_id</string> <string>original_id</string>
<string>clipboard</string> <string>clipboard</string>
<string>paste_result</string> <string>paste_result</string>
<string>new_object</string> <string>new_object</string>
<string>message_kind</string> <string>message_kind</string>
<string>msg</string> <string>ACCEPTABLE_FORM_ID_LIST</string>
<string>edit_kw</string>
<string>property_id_list</string>
<string>_getiter_</string>
<string>key</string>
<string>val</string>
<string>len</string>
<string>_write_</string>
</tuple> </tuple>
</value> </value>
</item> </item>
...@@ -201,6 +233,7 @@ else:\n ...@@ -201,6 +233,7 @@ else:\n
<none/> <none/>
<int>0</int> <int>0</int>
<int>0</int> <int>0</int>
<int>0</int>
</tuple> </tuple>
</value> </value>
</item> </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