diff --git a/bt5/erp5_base/SkinTemplateItem/portal_skins/erp5_base/ERP5Site_getCategoriesFullPath.xml b/bt5/erp5_base/SkinTemplateItem/portal_skins/erp5_base/ERP5Site_getCategoriesFullPath.xml new file mode 100644 index 0000000000000000000000000000000000000000..d70fa39cfd821ad96a11ee8926e56edb25ff09e8 --- /dev/null +++ b/bt5/erp5_base/SkinTemplateItem/portal_skins/erp5_base/ERP5Site_getCategoriesFullPath.xml @@ -0,0 +1,192 @@ +<?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 encoding="cdata"><![CDATA[ + +# get a dict like {\'religion\': \'MRD\', \'gender\': \'M\'} and returns {\'religion\': \'MSM/MRD\', gender: \'male\'} so that \n +# we can call an edit(category_dict) directly on the object it browse recursively the subcategories of the \n +# category (key in the dict) and find a match "Codification" (TODO: support "Reference" & \'id\' matching)\n +# Christophe Dumez <christophe@nexedi.com>\n +\n +#def getMatchingCategoryUsingCodification(root_category, codification):\n +# sub_cat_list = root_category.objectValues()\n +# for sub_cat in sub_cat_list:\n +# if sub_cat.getCodification() == codification:\n +# return sub_cat\n +# matching_cat = getMatchingCategoryUsingCodification(sub_cat, codification)\n +# if matching_cat is not None:\n +# return matching_cat\n +\n +result_dict = {}\n +for category_name in category_dict.keys():\n + subcat_code = category_dict[category_name]\n + category_object = context.getPortalObject().portal_categories[category_name]\n + result_list = context.portal_catalog(portal_type=\'Category\', reference=str(subcat_code), relative_url=category_name+\'%\')\n + if len(result_list) != 0:\n + result_cat_fullpath = \'/\'.join(result_list[0].getPath().split(\'/\')[4:])\n + result_dict[category_name]=result_cat_fullpath\n + else:\n + # XXX: this request does a LIKE "%xxxx%", We should find a way to remove the %%\n + result_list = context.portal_catalog(portal_type=\'Category\', title=str(subcat_code), relative_url=category_name+\'%\')\n + if len(result_list) != 0:\n + result_cat_fullpath = \'/\'.join(result_list[0].getPath().split(\'/\')[4:])\n + result_dict[category_name]=result_cat_fullpath\n + #result_cat = getMatchingCategoryUsingCodification(root_category=category_object, codification=subcat_code)\n + #if result_cat is not None:\n + # result_cat_fullpath = \'/\'.join(result_cat.getPath().split(\'/\')[4:])\n + # result_dict[category_name]=result_cat_fullpath\n +\n +return result_dict\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>_params</string> </key> + <value> <string>category_dict</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>category_dict</string> + <string>result_dict</string> + <string>_getiter_</string> + <string>_getattr_</string> + <string>category_name</string> + <string>_getitem_</string> + <string>subcat_code</string> + <string>context</string> + <string>category_object</string> + <string>str</string> + <string>result_list</string> + <string>len</string> + <string>result_cat_fullpath</string> + <string>_write_</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>ERP5Site_getCategoriesFullPath</string> </value> + </item> + <item> + <key> <string>warnings</string> </key> + <value> + <tuple/> + </value> + </item> + </dictionary> + </pickle> + </record> +</ZopeData> diff --git a/bt5/erp5_base/SkinTemplateItem/portal_skins/erp5_base/ERP5Site_importObjectFromOOo.xml b/bt5/erp5_base/SkinTemplateItem/portal_skins/erp5_base/ERP5Site_importObjectFromOOo.xml index 8d136f3519174311cd5c964c450fbb8c74dcf878..d6b4f2e152a6c26df38c2fafc73c5471f24173ff 100644 --- a/bt5/erp5_base/SkinTemplateItem/portal_skins/erp5_base/ERP5Site_importObjectFromOOo.xml +++ b/bt5/erp5_base/SkinTemplateItem/portal_skins/erp5_base/ERP5Site_importObjectFromOOo.xml @@ -191,10 +191,28 @@ else:\n for (module, per_portal_type_data) in object_list.items():\n for (portal_type, new_object_list) in per_portal_type_data.items():\n for new_object_property_dict in new_object_list:\n + #get portal tye objects\n + ptype_object = None\n + for allowed_ptype in module.allowedContentTypes():\n + ptype_name = \'\'.join(allowed_ptype.id.split(\' \'))\n + if ptype_name == portal_type:\n + ptype_object = allowed_ptype\n + break\n + if ptype_object is None:\n + raise \'Portal type %s not found in allowed content types\' % portal_type\n + category_list = ptype_object.getCategoryList()\n new_object = module.newContent( portal_type = portal_type\n , immediate_reindex = 1\n )\n + new_object_category_dict = {}\n + for prop_key in new_object_property_dict.keys():\n + if prop_key in category_list:\n + new_object_category_dict[prop_key] = new_object_property_dict[prop_key]\n + del new_object_property_dict[prop_key]\n new_object.edit(**new_object_property_dict)\n + # Match the categories\n + new_object_category_dict = context.ERP5Site_getCategoriesFullPath(category_dict = new_object_category_dict)\n + new_object.edit(**new_object_category_dict)\n new_path_list.append(new_object.getRelativeUrl())\n \n return request.RESPONSE.redirect(context.absolute_url() + \'/person_module/view?portal_status_message=OpenOffice+document+successfully+imported.+New+object+created:+\' + str(len(new_path_list)))\n @@ -298,7 +316,13 @@ return context.ERP5Site_importObjectFromOOoFastInput(REQUEST=request)\n <string>per_portal_type_data</string> <string>portal_type</string> <string>new_object_list</string> + <string>ptype_object</string> + <string>allowed_ptype</string> + <string>ptype_name</string> + <string>category_list</string> <string>new_object</string> + <string>new_object_category_dict</string> + <string>prop_key</string> <string>_apply_</string> <string>str</string> </tuple>