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: ...@@ -53,8 +53,6 @@ except ImportError:
from zLOG import LOG, WARNING from zLOG import LOG, WARNING
from Products.CMFCore.utils import getToolByName from Products.CMFCore.utils import getToolByName
#Mixin import
from Products.ERP5.mixin.convertable import ConvertableMixin
default_displays_id_list = ('nano', 'micro', 'thumbnail', default_displays_id_list = ('nano', 'micro', 'thumbnail',
'xsmall', 'small', 'medium', 'xsmall', 'small', 'medium',
...@@ -62,7 +60,7 @@ default_displays_id_list = ('nano', 'micro', 'thumbnail', ...@@ -62,7 +60,7 @@ default_displays_id_list = ('nano', 'micro', 'thumbnail',
default_formats = ['jpg', 'jpeg', 'png', 'gif', 'pnm', 'ppm'] 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 An Image is a File which contains image data. It supports
various conversions of format, size, resolution through various conversions of format, size, resolution through
...@@ -324,36 +322,11 @@ class Image(File, OFSImage, ConvertableMixin): ...@@ -324,36 +322,11 @@ class Image(File, OFSImage, ConvertableMixin):
return mime_type, result return mime_type, result
# Conversion API # 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') security.declareProtected(Permissions.AccessContentsInformation, 'convert')
def convert(self, format, display=None, quality=75, resolution=None, frame=None, **kw): def convert(self, format, display=None, quality=75, resolution=None, frame=None, **kw):
""" """
Implementation of conversion for Image files 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'): if format in ('text', 'txt', 'html', 'base_html', 'stripped-html'):
try: try:
return self.getConversion(format=format) return self.getConversion(format=format)
...@@ -366,7 +339,7 @@ class Image(File, OFSImage, ConvertableMixin): ...@@ -366,7 +339,7 @@ class Image(File, OFSImage, ConvertableMixin):
if (display is not None or resolution is not None or quality != 75 or format != ''\ if (display is not None or resolution is not None or quality != 75 or format != ''\
or frame is not None) and image_size: or frame is not None) and image_size:
kw = dict(display=display, format=format, quality=quality, kw = dict(display=display, format=format, quality=quality,
resolution=resolution, frame=frame, image_size=image_size) resolution=resolution, frame=frame, image_size=image_size)
try: try:
mime, image = self.getConversion(**kw) mime, image = self.getConversion(**kw)
except KeyError: except KeyError:
...@@ -396,7 +369,7 @@ class Image(File, OFSImage, ConvertableMixin): ...@@ -396,7 +369,7 @@ class Image(File, OFSImage, ConvertableMixin):
# display may be set from a cookie (?) # display may be set from a cookie (?)
image_size = self.getSizeFromImageDisplay(display) image_size = self.getSizeFromImageDisplay(display)
kw = dict(display=display, format=format, quality=quality, kw = dict(display=display, format=format, quality=quality,
resolution=resolution, frame=frame, image_size=image_size) resolution=resolution, frame=frame, image_size=image_size)
_setCacheHeaders(_ViewEmulator().__of__(self), kw) _setCacheHeaders(_ViewEmulator().__of__(self), kw)
if (display is not None or resolution is not None or quality != 75 or format != ''\ if (display is not None or resolution is not None or quality != 75 or format != ''\
......
...@@ -37,13 +37,7 @@ from Products.ERP5.Document.Image import Image ...@@ -37,13 +37,7 @@ from Products.ERP5.Document.Image import Image
from Products.ERP5.Document.Document import ConversionError from Products.ERP5.Document.Document import ConversionError
from Products.ERP5.mixin.cached_convertable import CachedConvertableMixin from Products.ERP5.mixin.cached_convertable import CachedConvertableMixin
class PDFDocument(Image, CachedConvertableMixin):
from zLOG import LOG, WARNING
# Mixin import
from Products.ERP5.mixin.convertable import ConvertableMixin
class PDFDocument(Image, ConvertableMixin, CachedConvertableMixin):
""" """
PDFDocument is a subclass of Image which is able to PDFDocument is a subclass of Image which is able to
extract text content from a PDF file either as text extract text content from a PDF file either as text
...@@ -104,11 +98,6 @@ class PDFDocument(Image, ConvertableMixin, CachedConvertableMixin): ...@@ -104,11 +98,6 @@ class PDFDocument(Image, ConvertableMixin, CachedConvertableMixin):
resolution=resolution, frame=frame) resolution=resolution, frame=frame)
# Conversion API # 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') security.declareProtected(Permissions.AccessContentsInformation, 'convert')
def convert(self, format, **kw): def convert(self, format, **kw):
""" """
......
...@@ -43,12 +43,9 @@ try: ...@@ -43,12 +43,9 @@ try:
except ImportError: except ImportError:
from Products.ERP5Type.patches.string import Template from Products.ERP5Type.patches.string import Template
# Mixin import
from Products.ERP5.mixin.convertable import ConvertableMixin
DEFAULT_TEXT_FORMAT = 'text/html' DEFAULT_TEXT_FORMAT = 'text/html'
class TextDocument(Document, TextContent, ConvertableMixin): class TextDocument(Document, TextContent):
""" """
A Document contains text which can be formatted using A Document contains text which can be formatted using
*Structured Text* or *HTML*. Text can be automatically translated *Structured Text* or *HTML*. Text can be automatically translated
...@@ -149,10 +146,6 @@ class TextDocument(Document, TextContent, ConvertableMixin): ...@@ -149,10 +146,6 @@ class TextDocument(Document, TextContent, ConvertableMixin):
if format is None: if format is None:
# The default is to use ERP5 Forms to render the page # The default is to use ERP5 Forms to render the page
return self.view() 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) mime, data = self.convert(format=format)
RESPONSE.setHeader('Content-Length', len(str(data))) # XXX - Not efficient RESPONSE.setHeader('Content-Length', len(str(data))) # XXX - Not efficient
# if datastream instance # if datastream instance
...@@ -207,25 +200,12 @@ class TextDocument(Document, TextContent, ConvertableMixin): ...@@ -207,25 +200,12 @@ class TextDocument(Document, TextContent, ConvertableMixin):
substitution_method_parameter_dict = {} substitution_method_parameter_dict = {}
return self._substituteTextContent(subject, safe_substitute=safe_substitute, return self._substituteTextContent(subject, safe_substitute=safe_substitute,
**substitution_method_parameter_dict) **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') security.declareProtected(Permissions.AccessContentsInformation, 'convert')
def convert(self, format, substitution_method_parameter_dict=None, safe_substitute=True, **kw): def convert(self, format, substitution_method_parameter_dict=None, safe_substitute=True, **kw):
""" """
Convert text using portal_transforms or oood 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 # Accelerate rendering in Web mode
_setCacheHeaders(_ViewEmulator().__of__(self), {'format' : format}) _setCacheHeaders(_ViewEmulator().__of__(self), {'format' : format})
# Return the raw content # 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