Commit 181a973a authored by Bartek Górny's avatar Bartek Górny

On re-upload to not create new object, but increase revision instead.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@13123 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 2159f3f8
...@@ -75,9 +75,7 @@ It does the following:\n ...@@ -75,9 +75,7 @@ It does the following:\n
- determines portal types appropriate for the file type uploaded, and checks if the context portal type\n - determines portal types appropriate for the file type uploaded, and checks if the context portal type\n
is one of those (this is not a complete check, but all we can do at this stage)\n is one of those (this is not a complete check, but all we can do at this stage)\n
- checks if context already has some data (we do not allow re-upload of files)\n - checks if context already has some data (we do not allow re-upload of files)\n
If the context has data, it creates a copy of context (with the same portal type most important properties\n Otherwise it just uploads the file, bumps up revision number and calls metadata discovery script.\n
copied) and uploads the file into the copy (the rest is handled by portal_contributions)\n
Otherwise it just uploads the file and calls metadata discovery script.\n
\n \n
"""\n """\n
\n \n
...@@ -101,28 +99,22 @@ if candidate_type_list and current_type not in candidate_type_list:\n ...@@ -101,28 +99,22 @@ if candidate_type_list and current_type not in candidate_type_list:\n
mapping = dict(portal_type = current_type, appropriate_type = str(candidate_type_list)))\n mapping = dict(portal_type = current_type, appropriate_type = str(candidate_type_list)))\n
return context.Base_redirect(dialog_id, keep_items = dict(portal_status_message =portal_status_message, cancel_url = kw[\'cancel_url\']), **kw)\n return context.Base_redirect(dialog_id, keep_items = dict(portal_status_message =portal_status_message, cancel_url = kw[\'cancel_url\']), **kw)\n
\n \n
if context.hasFile(): # this is a re-upload, we create a \'copy\'\n context.manage_upload(file)\n
property_list = context.portal_types[current_type].getInstanceBaseCategoryList() # all category memberships\n context.discoverMetadata(file_name=file_name)\n
# we copy many things, ingestion script may then overwrite some of these (if allowed)\n \n
# we rely on ingestion script to determine coordinates\n # increase revision\n
property_list += [\'title\', \'short_title\', \'index\', \'description\'] # maybe\n try:\n
vals = {}\n current_revision = int(context.getRevision())\n
vals[\'source_reference\'] = file_name\n except ValueError:\n
for prop in property_list:\n current_revision = 0\n
v = context.getProperty(prop)\n \n
if v is not None:\n rev = \'%03d\' % (current_revision + 1)\n
vals[prop] = v\n context.setRevision(rev)\n
# we create new ob by portal_contributions, supplying current properties as input props\n \n
ob = context.portal_contributions.newContent(portal_type = current_type, file=file, **vals)\n msg = translateString(\'File uploaded.\')\n
msg = translateString(\'Document already contained file data. A new document was created to which the file was uploaded.\')\n
else:\n
ob = context\n
ob.manage_upload(file)\n
ob.discoverMetadata(file_name=file_name)\n
msg = translateString(\'File uploaded.\')\n
\n \n
# Return to view mode\n # Return to view mode\n
return ob.Base_redirect(form_id, keep_items = {\'portal_status_message\' : msg}, **kw)\n return context.Base_redirect(form_id, keep_items = {\'portal_status_message\' : msg}, **kw)\n
</string> </value> </string> </value>
</item> </item>
<item> <item>
...@@ -182,14 +174,10 @@ return ob.Base_redirect(form_id, keep_items = {\'portal_status_message\' : msg}, ...@@ -182,14 +174,10 @@ return ob.Base_redirect(form_id, keep_items = {\'portal_status_message\' : msg},
<string>str</string> <string>str</string>
<string>portal_status_message</string> <string>portal_status_message</string>
<string>_apply_</string> <string>_apply_</string>
<string>property_list</string> <string>int</string>
<string>vals</string> <string>current_revision</string>
<string>_write_</string> <string>ValueError</string>
<string>_getiter_</string> <string>rev</string>
<string>prop</string>
<string>v</string>
<string>None</string>
<string>ob</string>
<string>msg</string> <string>msg</string>
</tuple> </tuple>
</value> </value>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<tuple>
<string>Products.Formulator.StandardFields</string>
<string>StringField</string>
</tuple>
<none/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>id</string> </key>
<value> <string>my_revision</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>
<item>
<key> <string>required_not_found</string> </key>
<value> <string>Input is required but no input given.</string> </value>
</item>
<item>
<key> <string>too_long</string> </key>
<value> <string>Too much input was given.</string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>overrides</string> </key>
<value>
<dictionary>
<item>
<key> <string>alternate_name</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>css_class</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>default</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>display_maxwidth</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>display_width</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>editable</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>enabled</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>external_validator</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>extra</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>hidden</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>max_length</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>required</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>truncate</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>unicode</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>whitespace_preserve</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>tales</string> </key>
<value>
<dictionary>
<item>
<key> <string>alternate_name</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>css_class</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>default</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>display_maxwidth</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>display_width</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>editable</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>enabled</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>external_validator</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>extra</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>hidden</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>max_length</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>required</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>truncate</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>unicode</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>whitespace_preserve</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>values</string> </key>
<value>
<dictionary>
<item>
<key> <string>alternate_name</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>css_class</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>default</string> </key>
<value> <string>000</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>display_maxwidth</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>display_width</string> </key>
<value> <int>20</int> </value>
</item>
<item>
<key> <string>editable</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>enabled</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>external_validator</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>extra</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>hidden</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>max_length</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>required</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Revision</string> </value>
</item>
<item>
<key> <string>truncate</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>unicode</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>whitespace_preserve</string> </key>
<value> <int>0</int> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
550 553
\ 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