From e3b20a4f0c857592362d8d17553ad552e33c9dbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com> Date: Thu, 18 Oct 2012 15:17:57 +0200 Subject: [PATCH] Base_contribute: treat what the user put in the dialog as user input We cannot wait for the document to be created to introspect its properties, because we need to pass the input parameters to newContent. Instead use a fixed list of common parameters --- .../erp5_ingestion/Base_contribute.xml | 23 ++++++++----------- bt5/erp5_ingestion/bt/revision | 2 +- product/ERP5OOo/tests/testDms.py | 21 +++++++++++++++++ 3 files changed, 32 insertions(+), 14 deletions(-) diff --git a/bt5/erp5_ingestion/SkinTemplateItem/portal_skins/erp5_ingestion/Base_contribute.xml b/bt5/erp5_ingestion/SkinTemplateItem/portal_skins/erp5_ingestion/Base_contribute.xml index ed2494f248..ecb935ceb2 100644 --- a/bt5/erp5_ingestion/SkinTemplateItem/portal_skins/erp5_ingestion/Base_contribute.xml +++ b/bt5/erp5_ingestion/SkinTemplateItem/portal_skins/erp5_ingestion/Base_contribute.xml @@ -86,6 +86,16 @@ if classification not in MARKER:\n if follow_up_list:\n document_kw[\'follow_up_list\'] = follow_up_list\n \n +\n +form = portal.REQUEST.form\n +# Lookup for input values in request.form or kw to try to get values in two available modes: the\n +# script coulbe be called from ERP5 Form or directly from Python.\n +# FIXME: this list of properties should not be hardcoded.\n +for key in (\'title\', \'short_title\', \'reference\', \'language\', \'version\', \'description\', ):\n + value = form.get(key, kw.get(key, None))\n + if value not in MARKER:\n + document_kw[key] = value\n +\n if attach_document_to_context:\n # attach document to current context using follow_up\n follow_up_list = document_kw.setdefault(\'follow_up_list\', [])\n @@ -126,20 +136,7 @@ if synchronous_metadata_discovery:\n input_parameter_dict=document_kw)\n is_existing_document_updated = (merged_document!=document)\n document = merged_document\n -# introspect document and find editable properties\n -# then use form or kw and try to get values in two available modes: the\n -# script coulbe be called: from ERP5 From or directly from Python script\n -document_edit_kw = {}\n -property_id_list = document.propertyIds()\n -form = context.REQUEST.form\n -for key in property_id_list:\n - value = form.get(key, kw.get(key, None))\n - if value not in MARKER:\n - document_edit_kw[key] = value\n \n -# edit document \n -if document_edit_kw is not {}:\n - document.edit(**document_edit_kw)\n document_portal_type = document.getTranslatedPortalType()\n if not is_existing_document_updated:\n message = translateString(\'${portal_type} created successfully.\',\n diff --git a/bt5/erp5_ingestion/bt/revision b/bt5/erp5_ingestion/bt/revision index acfba60953..83248fb9df 100644 --- a/bt5/erp5_ingestion/bt/revision +++ b/bt5/erp5_ingestion/bt/revision @@ -1 +1 @@ -141 \ No newline at end of file +142 \ No newline at end of file diff --git a/product/ERP5OOo/tests/testDms.py b/product/ERP5OOo/tests/testDms.py index 6c9d7a56da..17491b2601 100644 --- a/product/ERP5OOo/tests/testDms.py +++ b/product/ERP5OOo/tests/testDms.py @@ -1411,6 +1411,27 @@ class TestDocument(TestDocumentMixin): file=makeFileUpload('TEST-en-002.odt')) self.assertEquals('PDF', contributed_document.getPortalType()) + def test_Base_contribute_input_parameter_dict(self): + """Test contributing while entering input parameters. + """ + person = self.portal.person_module.newContent(portal_type='Person') + contributed_document = person.Base_contribute( + title='user supplied title', + file=makeFileUpload('TEST-en-002.pdf')) + self.tic() + self.assertEquals('user supplied title', contributed_document.getTitle()) + + def test_Base_contribute_input_parameter_dict_request(self): + """Test contributing while entering input parameters through the dialog. + """ + person = self.portal.person_module.newContent(portal_type='Person') + self.portal.REQUEST.form['title'] = 'user supplied title' + contributed_document = person.Base_contribute( + file=makeFileUpload('TEST-en-002.pdf')) + self.tic() + self.assertEquals('user supplied title', contributed_document.getTitle()) + + def test_HTML_to_ODT_conversion_keep_enconding(self): """This test perform an PDF conversion of HTML content then to plain text. -- 2.30.9