Commit a8ca89f4 authored by Nicolas Delaby's avatar Nicolas Delaby

Add DocumentMixin which implements IDocument interface


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@35743 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent d15879cb
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2010 Nexedi SA and Contributors. All Rights Reserved.
# Nicolas Delaby <nicolas@nexedi.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from Products.CMFCore.utils import getToolByName
from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions
from OFS.Image import Pdata
from cStringIO import StringIO
_MARKER = []
class DocumentMixin:
"""
Implementation of IDocument interface
convert must not be overloaded as it checks conversion
format permission
isSupportBaseDataConversion can be overriden, if base_conversion
is supported (eg. OOoDocuments, TextDocument).
"""
security = ClassSecurityInfo()
security.declareProtected(Permissions.AccessContentsInformation, 'convert')
def convert(self, format, **kw):
"""
Main content conversion function, returns result which should
be returned and stored in cache.
If format is not allowed for download, Unauthorized exception is raised.
format - the format specied in the form of an extension
string (ex. jpeg, html, text, txt, etc.)
**kw can be various things - e.g. resolution
"""
self._checkConversionFormatPermission(format, **kw)
return self._convert(format, **kw)
def _convert(self, format, **kw):
"""Private method which make the transformation.
Must be overriden !!!
"""
raise NotImplementedError
security.declareProtected(Permissions.AccessContentsInformation,
'checkConversionFormatPermission')
def checkConversionFormatPermission(self, format, **kw):
"""Public version of _checkConversionFormatPermission
Without raising return just True or False.
"""
try:
self._checkConversionFormatPermission(format, **kw)
except Unauthorized:
return False
else:
return True
def _checkConversionFormatPermission(self, format, **kw):
"""Private method to check permission when access specified format.
This method raises
"""
# XXX cache result in TV
method = self._getTypeBasedMethod('checkConversionFormatPermission',
fallback_script_id='Document_checkConversionFormatPermission')
if not method(format=format, **kw):
raise Unauthorized('Document: user does not have enough permission'\
' to access document in %s format' %\
(format or 'original'))
security.declareProtected(Permissions.AccessContentsInformation,
'isSupportBaseDataConversion')
def isSupportBaseDataConversion(self):
"""Tell if document implement IBaseConvertable Interface.
By default it doens't
"""
return False
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