Commit 69a2cede authored by Mame Coumba Sall's avatar Mame Coumba Sall

Modified to revert back to revision before 34090


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@34146 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 9e8c8a83
This diff is collapsed.
......@@ -53,8 +53,6 @@ except ImportError:
from zLOG import LOG, WARNING
from Products.CMFCore.utils import getToolByName
#Mixin import
from Products.ERP5.mixin.convertable import ConvertableMixin
default_displays_id_list = ('nano', 'micro', 'thumbnail',
'xsmall', 'small', 'medium',
......@@ -62,7 +60,7 @@ default_displays_id_list = ('nano', 'micro', 'thumbnail',
default_formats = ['jpg', 'jpeg', 'png', 'gif', 'pnm', 'ppm']
class Image(File, OFSImage, ConvertableMixin):
class Image(File, OFSImage):
"""
An Image is a File which contains image data. It supports
various conversions of format, size, resolution through
......@@ -324,36 +322,11 @@ class Image(File, OFSImage, ConvertableMixin):
return mime_type, result
# Conversion API
security.declareProtected(Permissions.View, 'getAllowedTargetItemList')
def getAllowedTargetItemList(self):
import commands
import re
import os
new_result = []
filename = os.path.abspath(self.getSourceReference())
result = commands.getstatusoutput('convert -list format %s ' % self.getSourceReference())
new_list = re.split('\n',result[1])
allowed = []
for new_str in new_list:
test_str = new_str.lstrip()
pattern = re.compile(r'''([A-z]+[*]?\s+[A-z]+\s+[rw+-]+\s+[A-z]+\s+[A-z]+\D+[A-z]+)''',re.VERBOSE)
if re.match(pattern,test_str):
new_result.append(test_str)
len_new_result = len(new_result)
for i in range(0,len_new_result):
allowed.append(list((new_result[i].split()[1].lower(),' '.join(new_result[i].split()[3:]))))
return [(y, x) for x, y in allowed]
security.declareProtected(Permissions.AccessContentsInformation, 'convert')
def convert(self, format, display=None, quality=75, resolution=None, frame=None, **kw):
"""
Implementation of conversion for Image files
"""
# Raise an error if the format is not permitted
if not self.isTargetFormatPermitted(format):
raise Unauthorized("User does not have enough permission to access document"
" in %s format" % (format or 'original'))
if format in ('text', 'txt', 'html', 'base_html', 'stripped-html'):
try:
return self.getConversion(format=format)
......
......@@ -37,13 +37,7 @@ from Products.ERP5.Document.Image import Image
from Products.ERP5.Document.Document import ConversionError
from Products.ERP5.mixin.cached_convertable import CachedConvertableMixin
from zLOG import LOG, WARNING
# Mixin import
from Products.ERP5.mixin.convertable import ConvertableMixin
class PDFDocument(Image, ConvertableMixin, CachedConvertableMixin):
class PDFDocument(Image, CachedConvertableMixin):
"""
PDFDocument is a subclass of Image which is able to
extract text content from a PDF file either as text
......@@ -104,11 +98,6 @@ class PDFDocument(Image, ConvertableMixin, CachedConvertableMixin):
resolution=resolution, frame=frame)
# Conversion API
security.declareProtected(Permissions.View, 'getAllowedTargetItemList')
def getAllowedTargetItemList(self):
return Image.getAllowedTargetItemList(self) + \
[('Text', 'txt'),('Plain Text','text'), ('HTML Document', 'html')]
security.declareProtected(Permissions.AccessContentsInformation, 'convert')
def convert(self, format, **kw):
"""
......
......@@ -43,12 +43,9 @@ try:
except ImportError:
from Products.ERP5Type.patches.string import Template
# Mixin import
from Products.ERP5.mixin.convertable import ConvertableMixin
DEFAULT_TEXT_FORMAT = 'text/html'
class TextDocument(Document, TextContent, ConvertableMixin):
class TextDocument(Document, TextContent):
"""
A Document contains text which can be formatted using
*Structured Text* or *HTML*. Text can be automatically translated
......@@ -149,10 +146,6 @@ class TextDocument(Document, TextContent, ConvertableMixin):
if format is None:
# The default is to use ERP5 Forms to render the page
return self.view()
# Raise an error if the format is not permitted
if not self.isTargetFormatPermitted(format):
raise Unauthorized("User does not have enough permission to access document"
" in %s format" % (format or 'original'))
mime, data = self.convert(format=format)
RESPONSE.setHeader('Content-Length', len(str(data))) # XXX - Not efficient
# if datastream instance
......@@ -208,24 +201,11 @@ class TextDocument(Document, TextContent, ConvertableMixin):
return self._substituteTextContent(subject, safe_substitute=safe_substitute,
**substitution_method_parameter_dict)
security.declareProtected(Permissions.View, 'getAllowedTargetItemList')
def getAllowedTargetItemList(self):
mime_type = getToolByName(self, 'mimetypes_registry')
allowed=[]
for extension in mime_type.extensions:
allowed.append((mime_type.extensions[extension].name(),extension))
return [(y, x) for x, y in allowed]
security.declareProtected(Permissions.AccessContentsInformation, 'convert')
def convert(self, format, substitution_method_parameter_dict=None, safe_substitute=True, **kw):
"""
Convert text using portal_transforms or oood
"""
# Raise an error if the format is not permitted
if not self.isTargetFormatPermitted(format):
raise Unauthorized("User does not have enough permission to access document"
" in %s format" % (format or 'original'))
# Accelerate rendering in Web mode
_setCacheHeaders(_ViewEmulator().__of__(self), {'format' : format})
# Return the raw content
......
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