Commit 6da67666 authored by Tomáš Peterka's avatar Tomáš Peterka Committed by Tomáš Peterka

[erp5_dms] Improve export/import code for Image so it works with JIO

parent acb1d9c2
......@@ -16,13 +16,13 @@
<key> <string>categories</string> </key>
<value>
<tuple>
<string>action_type/object_exchange</string>
<string>action_type/object_jio_exchange</string>
</tuple>
</value>
</item>
<item>
<key> <string>category</string> </key>
<value> <string>object_exchange</string> </value>
<value> <string>object_jio_exchange</string> </value>
</item>
<item>
<key> <string>condition</string> </key>
......@@ -30,7 +30,9 @@
</item>
<item>
<key> <string>description</string> </key>
<value> <string></string> </value>
<value>
<none/>
</value>
</item>
<item>
<key> <string>icon</string> </key>
......
......@@ -8,8 +8,9 @@ It does the following:
Otherwise it just uploads the file, bumps up revision number and calls metadata discovery script.
"""
from Products.ERP5Type.Log import log, WARNING
translateString = context.Base_translateString
translate = context.Base_translateString
request = context.REQUEST
current_type = context.getPortalType()
file_name = file.filename
......@@ -20,19 +21,21 @@ file_name = file.filename
# we accept or suggest appropriate portal type
ext = file_name[file_name.rfind('.')+1:]
candidate_type_list = context.ContributionTool_getCandidateTypeListByExtension(ext)
if candidate_type_list == () and current_type != 'File':
portal_status_message = translateString("Sorry, this is not one of ${portal_type}. This file should be uploaded into a file document.",
mapping = dict(portal_type = str(candidate_type_list)))
return context.Base_redirect(dialog_id, keep_items = dict(portal_status_message=portal_status_message,cancel_url = kw['cancel_url']), **kw)
if not candidate_type_list and current_type != 'File':
log("Document {!s} does not support extension {!s}. Use generic 'File' document.".format(current_type, ext), level=WARNING)
return context.Base_redirect(dialog_id, keep_items={
'portal_status_message': translate("Current document does not support ${ext} file extension.", mapping={'ext': ext}),
'cancel_url': cancel_url})
if candidate_type_list and current_type not in candidate_type_list:
portal_status_message = translateString("Sorry, this is a ${portal_type}. This file should be uploaded into a ${appropriate_type} document.",
mapping = dict(portal_type = current_type, appropriate_type = str(candidate_type_list)))
return context.Base_redirect(dialog_id, keep_items = dict(portal_status_message =portal_status_message, cancel_url = kw['cancel_url']), **kw)
log("File extension {!s} is supported only by {!s}, not by current document {!s}.".format(ext, candidate_type_list, current_type), level=WARNING)
return context.Base_redirect(dialog_id, keep_items={
'portal_status_message': translate("Current document does not support ${ext} file extension.", mapping={'ext': ext}),
'cancel_url': cancel_url})
context.edit(file=file)
context.activate().Document_convertToBaseFormatAndDiscoverMetadata(file_name=file_name)
msg = translateString('File uploaded.')
# Return to view mode
return context.Base_redirect(form_id, keep_items = {'portal_status_message' : msg}, **kw)
return context.Base_redirect(form_id, keep_items={'portal_status_message': translateString('File uploaded.')})
......@@ -50,7 +50,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>dialog_id=None,form_id=None,file=None,**kw</string> </value>
<value> <string>dialog_id=None, form_id=None, file=None, cancel_url=\'\', **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
"""
Processes requests for conversion of and Image to a desired format.
Convert Image (context) to a desired format and return as a binary `filename` file.
Requires format and desired filename (adds extension if missing).
Sets headers and uses native Zope method to produce output.
"""
request = context.REQUEST
fname = request.get('filename')
format = request.get('format')
if fname is None or format is None:
return
if not fname.endswith('.' + format):
fname += '.' + format
if not filename.endswith('.' + format):
filename += '.' + format
request.RESPONSE.setHeader('Content-type', 'application/' + format)
request.RESPONSE.setHeader('Content-disposition', 'attachment; filename="%s"' % fname)
return context.index_html(request, request.RESPONSE, **kw)
request.RESPONSE.setHeader('Content-Type', 'application/' + format)
request.RESPONSE.setHeader('Content-Disposition', 'attachment; filename="%s"' % filename)
return context.index_html(request, request.RESPONSE) # quality, resolution, frame, image_size, crop will remain default values
......@@ -50,7 +50,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>**kw</string> </value>
<value> <string>filename, format, **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
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