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