Commit 14097487 authored by Jérome Perrin's avatar Jérome Perrin

ingestion: extend contribute dialog to support "Publication State"

Extend "Attach Document" to have the same feature as in "Scan Document"
so that user can directly choose the state when uploading a document.

This simplifies a bit document_scanner, which can reuse the code that is
now in Base_contribute
parent 3238df27
...@@ -1551,6 +1551,71 @@ class TestDocument(TestDocumentMixin): ...@@ -1551,6 +1551,71 @@ class TestDocument(TestDocumentMixin):
self.tic() self.tic()
self.assertEqual('user supplied title', contributed_document.getTitle()) self.assertEqual('user supplied title', contributed_document.getTitle())
def test_Base_contribute_publication_state(self):
"""Test contributing and choosing the publication state
"""
person = self.portal.person_module.newContent(portal_type='Person')
contributed_document = person.Base_contribute(
publication_state=None,
# we use as_name, to prevent regular expression from detecting a
# reference during ingestion, so that we can upload multiple documents
# in one test.
file=makeFileUpload('TEST-en-002.pdf', as_name='doc.pdf'))
self.tic()
self.assertEqual(contributed_document.getValidationState(), 'draft')
contributed_document = person.Base_contribute(
publication_state='shared',
file=makeFileUpload('TEST-en-002.pdf', as_name='doc.pdf'))
self.tic()
self.assertEqual(contributed_document.getValidationState(), 'shared')
contributed_document = person.Base_contribute(
publication_state='released',
file=makeFileUpload('TEST-en-002.pdf', as_name='doc.pdf'))
self.tic()
self.assertEqual(contributed_document.getValidationState(), 'released')
def test_Base_contribute_publication_state_vs_finishIngestion_script(self):
"""Contribute dialog allow choosing a publication state, but there's
also a "finishIngestion" type based script that can be configured to
force change the state. If user selects a publication_state, the state is
changed before the finishIngestion can operate.
"""
createZODBPythonScript(
self.portal.portal_skins.custom,
'PDF_finishIngestion',
'',
'if context.getValidationState() == "draft":\n'
' context.publish()')
try:
person = self.portal.person_module.newContent(portal_type='Person')
contributed_document = person.Base_contribute(
publication_state='shared',
synchronous_metadata_discovery=True,
file=makeFileUpload('TEST-en-002.pdf', as_name='doc.pdf'))
self.tic()
self.assertEqual(contributed_document.getValidationState(), 'shared')
contributed_document.setReference(None)
self.tic()
contributed_document = person.Base_contribute(
publication_state='shared',
synchronous_metadata_discovery=False,
file=makeFileUpload('TEST-en-002.pdf', as_name='doc.pdf'))
self.tic()
self.assertEqual(contributed_document.getValidationState(), 'shared')
contributed_document.setReference(None)
contributed_document = person.Base_contribute(
publication_state=None,
file=makeFileUpload('TEST-en-002.pdf', as_name='doc.pdf'))
self.tic()
self.assertEqual(contributed_document.getValidationState(), 'published')
finally:
self.portal.portal_skins.custom.manage_delObjects(ids=['PDF_finishIngestion'])
self.commit()
def test_HTML_to_ODT_conversion_keep_enconding(self): def test_HTML_to_ODT_conversion_keep_enconding(self):
"""This test perform an PDF conversion of HTML content """This test perform an PDF conversion of HTML content
then to plain text. then to plain text.
......
...@@ -11,13 +11,10 @@ pdf_data_list = context.Base_getTempImageList(active_process, image_list) ...@@ -11,13 +11,10 @@ pdf_data_list = context.Base_getTempImageList(active_process, image_list)
pdf_data = context.ERP5Site_mergePDFList(pdf_data_list=pdf_data_list) pdf_data = context.ERP5Site_mergePDFList(pdf_data_list=pdf_data_list)
file_object = StringIOWithFileName(pdf_data) file_object = StringIOWithFileName(pdf_data)
doc = context.Base_contribute(file=file_object, context.Base_contribute(
batch_mode=True, file=file_object,
redirect_to_document=False, batch_mode=True,
follow_up_list=[context.getRelativeUrl(),], redirect_to_document=False,
**kw) follow_up_list=[context.getRelativeUrl(),],
publication_state=publication_state,
if publication_state == "shared": **kw)
doc.share()
elif publication_state == "released":
doc.release()
...@@ -70,6 +70,12 @@ else: ...@@ -70,6 +70,12 @@ else:
document_kw.update({'file': file}) document_kw.update({'file': file})
document = portal_contributions.newContent(**document_kw) document = portal_contributions.newContent(**document_kw)
if document.getValidationState() == 'draft':
if publication_state == "shared":
document.share()
elif publication_state == "released":
document.release()
is_existing_document_updated = False is_existing_document_updated = False
if synchronous_metadata_discovery: if synchronous_metadata_discovery:
# we need to do all synchronously, in other case portal_contributions will do # we need to do all synchronously, in other case portal_contributions will do
......
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>file=None, url=None, portal_type=None, classification=None, synchronous_metadata_discovery=None, redirect_to_document=None, attach_document_to_context=False, use_context_for_container=False, redirect_url=None, redirect_to_context=False, cancel_url=None, batch_mode=False, max_repeat=0, editable_mode = 1, follow_up_list=None, user_login=None, group=None, publication_section=None, **kw</string> </value> <value> <string>file=None, url=None, portal_type=None, classification=None, synchronous_metadata_discovery=None, redirect_to_document=None, attach_document_to_context=False, use_context_for_container=False, redirect_url=None, redirect_to_context=False, cancel_url=None, batch_mode=False, max_repeat=0, editable_mode=1, follow_up_list=None, user_login=None, group=None, publication_section=None, publication_state=None,**kw</string> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
......
...@@ -100,6 +100,7 @@ ...@@ -100,6 +100,7 @@
<string>your_attach_document_to_context</string> <string>your_attach_document_to_context</string>
<string>your_group</string> <string>your_group</string>
<string>your_publication_section</string> <string>your_publication_section</string>
<string>your_publication_state</string>
</list> </list>
</value> </value>
</item> </item>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ProxyField" module="Products.ERP5Form.ProxyField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>delegated_list</string> </key>
<value>
<list>
<string>items</string>
<string>title</string>
</list>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>your_publication_state</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>
</dictionary>
</value>
</item>
<item>
<key> <string>overrides</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>tales</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>items</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>values</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string>my_dialog_mode_category</string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string>Base_viewFieldLibrary</string> </value>
</item>
<item>
<key> <string>items</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string>Click to edit the target</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Publication State</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_text</string> </key>
<value> <string>python: [("", ""),] + [(here.Base_translateString(x), y) for x,y in [("Draft", "draft"), ("Shared", "shared"), ("Released", "released"),]]</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
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