Commit eb88a002 authored by Bartek Górny's avatar Bartek Górny

1) option to get portal type from filename (by mapping id to type), utility tools for it

2) objects are created in appropriate modules, found automagically (this closes #81)

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@11666 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 2e88ffb8
......@@ -73,6 +73,13 @@ def generateFile(self,name,data,format):
res=base64.decodestring(kw['data'])
return res
def getAttrFromFilename(self,fname):
rx_parse=re.compile(self.portal_preferences.getPreferredDmsFilenameRegexp())
m=rx_parse.match(fname)
if m is None:
return {}
return m.groupdict()
# vim: syntax=python shiftwidth=2
......@@ -73,14 +73,31 @@
#if not doctype:\n
# doctype=context.Document_getDoctypeFromContent(data)\n
# then from filename\n
if not doctype:\n
\n
if doctype is None or doctype==\'\':\n
props=context.Document_getPropertiesFromFilename(context,fname)\n
context.log(props)\n
doctype_id=props.get(\'doctype_id\')\n
if doctype_id is not None:\n
doctype=context.Document_idToType(doctype_id)\n
context.log(doctype)\n
if doctype is None or doctype==\'\':\n
doctype=context.content_type_registry.findTypeName(fname,None,None)\n
context.log(fname,doctype)\n
if not doctype:\n
if doctype is None or doctype==\'\':\n
raise Exception("content type for file %s not registered" % fname)\n
\n
# create content\n
ob=context.document_module.newContent(portal_type=doctype)\n
# find appropriate module\n
mod=None\n
modlist=[m for m in context.getPortalObject().contentValues() if m.getId().endswith(\'_module\')]\n
for mod in modlist:\n
if doctype in context.portal_types[mod.getPortalType()].allowed_content_types:\n
break\n
if mod is None:\n
raise Exception(\'could not find module for \'+doctype)\n
# create and populate object\n
ob=mod.newContent(portal_type=doctype)\n
ob.manage_upload(data)\n
ob.DMS_ingestFile(fname,data)\n
return ob\n
......@@ -129,10 +146,19 @@ return ob\n
<string>fname</string>
<string>data</string>
<string>doctype</string>
<string>None</string>
<string>_getattr_</string>
<string>context</string>
<string>None</string>
<string>props</string>
<string>doctype_id</string>
<string>Exception</string>
<string>mod</string>
<string>append</string>
<string>$append0</string>
<string>_getiter_</string>
<string>m</string>
<string>modlist</string>
<string>_getitem_</string>
<string>ob</string>
</tuple>
</value>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<tuple>
<string>Products.ExternalMethod.ExternalMethod</string>
<string>ExternalMethod</string>
</tuple>
<none/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>__ac_local_roles__</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_function</string> </key>
<value> <string>getAttrFromFilename</string> </value>
</item>
<item>
<key> <string>_module</string> </key>
<value> <string>documentUtils</string> </value>
</item>
<item>
<key> <string>_owner</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Document_getPropertiesFromFilename</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<tuple>
<string>Products.PythonScripts.PythonScript</string>
<string>PythonScript</string>
</tuple>
<none/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Python_magic</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>__ac_local_roles__</string> </key>
<value>
<none/>
</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># implementation specific layer\n
# map document type id to portal type\n
# in stock dms not used\n
return\n
</string> </value>
</item>
<item>
<key> <string>_code</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_filepath</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_owner</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>doctype_id</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>1</int> </value>
</item>
<item>
<key> <string>co_varnames</string> </key>
<value>
<tuple>
<string>doctype_id</string>
</tuple>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>func_defaults</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Document_idToType</string> </value>
</item>
<item>
<key> <string>warnings</string> </key>
<value>
<tuple/>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
384
\ No newline at end of file
387
\ 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