Commit 0a86eb29 authored by Gabriel Monnerat's avatar Gabriel Monnerat

erp5_document_scanner: Add script to upload

parent 545767f6
"""
Use to contribute file to ERP5.
"""
from base64 import decodestring
portal = context.getPortalObject()
translateString = portal.Base_translateString
MARKER = ['', None]
portal_contributions = portal.portal_contributions
context_url = context.getRelativeUrl()
if synchronous_metadata_discovery is None:
synchronous_metadata_discovery = portal.portal_preferences.isPreferredSynchronousMetadataDiscovery(False)
user_login = portal.portal_membership.getAuthenticatedMember().getId()
document_kw = {'user_login': user_login,
'group': group,
'publication_section': publication_section}
if portal_type not in MARKER:
document_kw['portal_type'] = portal_type
document_kw['default_follow_up_uid'] = context.getUid()
for key in ('title', 'short_title', 'reference', 'language', 'version', 'description'):
value = kw.get(key, None)
if value not in MARKER:
document_kw[key] = value
document_kw.update({'discover_metadata': not synchronous_metadata_discovery})
# contribute file
document_kw.update({
'data': decodestring(document_scanner_gadget),
"filename": "{}.png".format(
document_kw.get("title") or document_scanner_gadget[:10])
})
document = portal_contributions.newContent(**document_kw)
is_existing_document_updated = False
if synchronous_metadata_discovery:
# we need to do all synchronously, in other case portal_contributions will do
# this in an activity
if document.isSupportBaseDataConversion():
document.processFile()
filename = document.getFilename()
merged_document = document.Document_convertToBaseFormatAndDiscoverMetadata(
filename=filename,
user_login=user_login,
input_parameter_dict=document_kw)
is_existing_document_updated = (merged_document!=document)
document = merged_document
document_portal_type = document.getTranslatedPortalType()
if not is_existing_document_updated:
message = translateString('${portal_type} created successfully.',
mapping=dict(portal_type=document_portal_type))
else:
message = translateString('${portal_type} updated successfully.',
mapping=dict(portal_type=document_portal_type))
if batch_mode:
return document
return document.Base_redirect('view',
keep_items={'portal_status_message': message,
'editable_mode': editable_mode})
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </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>_params</string> </key>
<value> <string>portal_type=None, classification=None, synchronous_metadata_discovery=None, cancel_url=None, batch_mode=False, editable_mode=1, group=None, publication_section=None, document_scanner_gadget=None, **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_uploadDocumentFromCamera</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Contribute file or url to ERP5</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