[Erp5-report] r35743 nicolas - /erp5/trunk/products/ERP5/mixin/document.py
nobody at svn.erp5.org
nobody at svn.erp5.org
Fri May 28 17:35:06 CEST 2010
Author: nicolas
Date: Fri May 28 17:35:05 2010
New Revision: 35743
URL: http://svn.erp5.org?rev=35743&view=rev
Log:
Add DocumentMixin which implements IDocument interface
Added:
erp5/trunk/products/ERP5/mixin/document.py
Added: erp5/trunk/products/ERP5/mixin/document.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/mixin/document.py?rev=35743&view=auto
==============================================================================
--- erp5/trunk/products/ERP5/mixin/document.py (added)
+++ erp5/trunk/products/ERP5/mixin/document.py [utf8] Fri May 28 17:35:05 2010
@@ -1,0 +1,101 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# Copyright (c) 2010 Nexedi SA and Contributors. All Rights Reserved.
+# Nicolas Delaby <nicolas at 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
More information about the Erp5-report
mailing list