Commit 246fa354 authored by Jean-Paul Smets's avatar Jean-Paul Smets

2006-12-29 Rewrote DMSDocument_uploadFile with many comments for additional...

2006-12-29 Rewrote DMSDocument_uploadFile with many comments for additional improvements - requires update of erp5_core

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@11791 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 0754f9c6
No related merge requests found
...@@ -68,43 +68,55 @@ ...@@ -68,43 +68,55 @@
</item> </item>
<item> <item>
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string>f=kw.get(\'file\',None)\n <value> <string>translateString = context.Base_translateString\n
typ=context.getPortalType()\n request = context.REQUEST\n
ptype = context.getPortalType()\n
fname = file.filename\n
\n \n
if f is None or not f:\n # XXX-JPS - rename to OOoDocument_uploadFile since this is for all types which related to OOoDocument class\n
raise Exception(\'DMSDocument_uploadFile called without file argument\')\n # XXX-JPS - it would also be nice to provide this import function at any location\n
# Folder_viewOOoDocumentUploadDialog which calls Folder_uploadOOoDocumentFile\n
# this way it is easy to add a document anywhere\n
\n \n
fname=f.filename\n
# we check for appropriate file type (by extension, using content_type_registry)\n # we check for appropriate file type (by extension, using content_type_registry)\n
# we accept or suggest appropriate portal type\n # we accept or suggest appropriate portal type\n
ctype=context.content_type_registry.findTypeName(fname,None,None)\n ctype=context.content_type_registry.findTypeName(fname,None,None)\n
if ctype is None and typ!=\'File\':\n if ctype is None and ptype != \'File\':\n
raise Exception(\'This file should be uploaded into File\')\n return context.Base_redirect(dialog_id,\n
if ctype is not None and ctype!=typ:\n keep_items = dict(portal_status_message = translateString("Sorry, this is not a ${portal_type}. This file should be uploaded into a File document.", mapping = dict(portal_type = ptype)),\n
raise Exception(\'This file should be uploaded into \'+ctype)\n cancel_url = kw[\'cancel_url\']), **kw)\n
if ctype is not None and ctype != ptype:\n
return context.Base_redirect(dialog_id,\n
keep_items = dict(portal_status_message = translateString("Sorry, this is not a ${portal_type}. This file should be uploaded into a ${appropriate_type} document.",\n
mapping = dict(portal_type = ptype,\n
appropriate_type = ctype)),\n
cancel_url = kw[\'cancel_url\']), **kw)\n
\n \n
if hasattr(context,\'data\'): # this is a re-upload, we create a \'copy\'\n if hasattr(context, \'data\'): # this is a re-upload, we create a \'copy\'\n
docmod=context.aq_parent\n # XXX-JPS please create API for this. Never access attributes directly\n
newob=docmod.newContent(portal_type=typ)\n parent = context.getParentValue()\n
copylist=context.portal_types[typ].getInstanceBaseCategoryList()\n new_document = parent.newContent(portal_type = ptype)\n
property_list = context.portal_types[ptype].getInstanceBaseCategoryList()\n
# we copy many things, ingestion script may then overwrite some of these\n # we copy many things, ingestion script may then overwrite some of these\n
# we rely on ingestion script to determine coordinates\n # we rely on ingestion script to determine coordinates\n
copylist+=[\'title\',\'short_title\',\'index\',\'description\',\'subject\']\n property_list += [\'title\', \'short_title\', \'index\', \'description\', \'subject\']\n
for a in copylist:\n for prop in property_list:\n
v=context.getProperty(a)\n v = context.getProperty(prop)\n
if v is not None:\n if v is not None:\n
newob.setProperty(a,v)\n new_document.setProperty(prop,v) # XXX-JPS - This is slow - make a dict and use edit instead\n
ob=newob\n # XXX-JPS Why don\'t we copy and paste ?\n
msg=\'object already had a file - a new object has been created\'\n ob = new_document\n
msg = translateString(\'Document already contained file data. A new document was created to with the uploaded file.\')\n
else:\n else:\n
ob=context\n ob = context\n
msg=\'file uploaded\'\n msg = translateString(\'File uploaded.\')\n
\n \n
ob.manage_upload(f)\n # Upload file\n
ob.DMS_ingestFile(f.filename)\n ob.manage_upload(file)\n
url=ob.absolute_url() \n ob.DMS_ingestFile(fname)\n
\n \n
return context.REQUEST.RESPONSE.redirect(url+\'/view?portal_status_message=\'+msg)\n # Return to view mode\n
return ob.Base_redirect(form_id, keep_items = {\'portal_status_message\' : msg}, **kw)\n
</string> </value> </string> </value>
</item> </item>
<item> <item>
...@@ -121,7 +133,7 @@ return context.REQUEST.RESPONSE.redirect(url+\'/view?portal_status_message=\'+ms ...@@ -121,7 +133,7 @@ return context.REQUEST.RESPONSE.redirect(url+\'/view?portal_status_message=\'+ms
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>*a,**kw</string> </value> <value> <string>dialog_id=None,form_id=None,file=None,**kw</string> </value>
</item> </item>
<item> <item>
<key> <string>errors</string> </key> <key> <string>errors</string> </key>
...@@ -141,32 +153,36 @@ return context.REQUEST.RESPONSE.redirect(url+\'/view?portal_status_message=\'+ms ...@@ -141,32 +153,36 @@ return context.REQUEST.RESPONSE.redirect(url+\'/view?portal_status_message=\'+ms
<dictionary> <dictionary>
<item> <item>
<key> <string>co_argcount</string> </key> <key> <string>co_argcount</string> </key>
<value> <int>0</int> </value> <value> <int>3</int> </value>
</item> </item>
<item> <item>
<key> <string>co_varnames</string> </key> <key> <string>co_varnames</string> </key>
<value> <value>
<tuple> <tuple>
<string>a</string> <string>dialog_id</string>
<string>form_id</string>
<string>file</string>
<string>kw</string> <string>kw</string>
<string>_getattr_</string> <string>_getattr_</string>
<string>None</string>
<string>f</string>
<string>context</string> <string>context</string>
<string>typ</string> <string>translateString</string>
<string>Exception</string> <string>request</string>
<string>ptype</string>
<string>fname</string> <string>fname</string>
<string>None</string>
<string>ctype</string> <string>ctype</string>
<string>hasattr</string> <string>_apply_</string>
<string>docmod</string> <string>dict</string>
<string>newob</string>
<string>_getitem_</string> <string>_getitem_</string>
<string>copylist</string> <string>hasattr</string>
<string>parent</string>
<string>new_document</string>
<string>property_list</string>
<string>_getiter_</string> <string>_getiter_</string>
<string>prop</string>
<string>v</string> <string>v</string>
<string>ob</string> <string>ob</string>
<string>msg</string> <string>msg</string>
<string>url</string>
</tuple> </tuple>
</value> </value>
</item> </item>
...@@ -178,7 +194,11 @@ return context.REQUEST.RESPONSE.redirect(url+\'/view?portal_status_message=\'+ms ...@@ -178,7 +194,11 @@ return context.REQUEST.RESPONSE.redirect(url+\'/view?portal_status_message=\'+ms
<item> <item>
<key> <string>func_defaults</string> </key> <key> <string>func_defaults</string> </key>
<value> <value>
<none/> <tuple>
<none/>
<none/>
<none/>
</tuple>
</value> </value>
</item> </item>
<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