Commit 9115cec4 authored by Ivan Tyagov's avatar Ivan Tyagov

Split IConvertable to IFormatConvertable and IConvertable. Move implementation...

Split IConvertable to IFormatConvertable and IConvertable. Move implementation from abstract Document class to interface (IConvertable) implementation. Adjust interface doc strings accordingly. 

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@37045 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 8d40fa45
......@@ -1263,42 +1263,3 @@ class Document(PermanentURLMixIn, XMLObject, UrlMixIn, CachedConvertableMixin,
# but not in http://www.some.site/at
base_url = '/'.join(base_url_list[:-1])
return base_url
security.declareProtected(Permissions.AccessContentsInformation,
'getTargetFormatItemList')
def getTargetFormatItemList(self):
"""
Returns a list of acceptable formats for conversion
in the form of tuples (for listfield in ERP5Form)
NOTE: it is the responsability of the respecive type based script
to provide an extensive list of conversion formats.
"""
method = self._getTypeBasedMethod('getTargetFormatItemList',
fallback_script_id='Base_getTargetFormatItemList')
return method()
security.declareProtected(Permissions.AccessContentsInformation,
'getTargetFormatTitleList')
def getTargetFormatTitleList(self):
"""
Returns a list of acceptable formats for conversion
"""
return map(lambda x: x[0], self.getTargetFormatItemList())
security.declareProtected(Permissions.AccessContentsInformation,
'getTargetFormatList')
def getTargetFormatList(self):
"""
Returns a list of acceptable formats for conversion
"""
return map(lambda x: x[1], self.getTargetFormatItemList())
security.declareProtected(Permissions.ModifyPortalContent,
'isTargetFormatAllowed')
def isTargetFormatAllowed(self, format):
"""
Checks if the current document can be converted
into the specified target format.
"""
return format in self.getTargetFormatList()
......@@ -29,35 +29,14 @@
from zope.interface import Interface
class IConvertable(Interface):
class IFormatConvertable(Interface):
"""
Convertable interface specification
Format Convertable interface specification
Documents which implement IConvertable can be converted
to multiple formats. IConvertable also provides
methods to list possible formats which documents can
IFormatConvertable provides methods to list possible formats which documents can
be converted to.
"""
def convert(format, **kw):
"""
Converts the current document to the specified format
taking into account optional parameters. This method
returns a tuple of two values: a mime type string and
the converted data.
This methods raises a ConversionError if the target format
is not allowed, or an Unauthorized error if the target format
is not permitted.
format -- the target conversion format specified either as an
extension (ex. 'png') or as a mime type
string (ex. 'text/plain')
kw -- optional parameters which can be passed to the
conversion engine
"""
def isTargetFormatAllowed(format):
"""
Checks if the current document can be converted
......@@ -110,3 +89,29 @@ class IConvertable(Interface):
passed to IConvertable.convert or to IDownloadable.index_html
"""
class IConvertable(IFormatConvertable):
"""
Convertable interface specification
Documents which implement IConvertable can be converted
to multiple formats.
"""
def convert(format, **kw):
"""
Converts the current document to the specified format
taking into account optional parameters. This method
returns a tuple of two values: a mime type string and
the converted data.
This methods raises a ConversionError if the target format
is not allowed, or an Unauthorized error if the target format
is not permitted.
format -- the target conversion format specified either as an
extension (ex. 'png') or as a mime type
string (ex. 'text/plain')
kw -- optional parameters which can be passed to the
conversion engine
"""
......@@ -244,3 +244,42 @@ class CachedConvertableMixin:
self._setContentMd5(md5.new(data).hexdigest()) # Reindex is useless
else:
self._setContentMd5(None)
security.declareProtected(Permissions.AccessContentsInformation,
'getTargetFormatItemList')
def getTargetFormatItemList(self):
"""
Returns a list of acceptable formats for conversion
in the form of tuples (for listfield in ERP5Form)
NOTE: it is the responsability of the respecive type based script
to provide an extensive list of conversion formats.
"""
method = self._getTypeBasedMethod('getTargetFormatItemList',
fallback_script_id='Base_getTargetFormatItemList')
return method()
security.declareProtected(Permissions.AccessContentsInformation,
'getTargetFormatTitleList')
def getTargetFormatTitleList(self):
"""
Returns a list of acceptable formats for conversion
"""
return map(lambda x: x[0], self.getTargetFormatItemList())
security.declareProtected(Permissions.AccessContentsInformation,
'getTargetFormatList')
def getTargetFormatList(self):
"""
Returns a list of acceptable formats for conversion
"""
return map(lambda x: x[1], self.getTargetFormatItemList())
security.declareProtected(Permissions.ModifyPortalContent,
'isTargetFormatAllowed')
def isTargetFormatAllowed(self, format):
"""
Checks if the current document can be converted
into the specified target format.
"""
return format in self.getTargetFormatList()
\ No newline at end of file
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