[Erp5-report] r20155 - in /erp5/trunk/products/ERP5: Document/ PropertySheet/ Tool/
nobody at svn.erp5.org
nobody at svn.erp5.org
Wed Mar 26 16:13:28 CET 2008
Author: yusei
Date: Wed Mar 26 16:13:27 2008
New Revision: 20155
URL: http://svn.erp5.org?rev=20155&view=rev
Log:
Add contribution registry tool and related stuff.
This tool will replace content type registry.
Added:
erp5/trunk/products/ERP5/Document/ContributionPredicate.py
erp5/trunk/products/ERP5/Document/IngestionFile.py
erp5/trunk/products/ERP5/PropertySheet/ContributionPredicate.py
erp5/trunk/products/ERP5/PropertySheet/IngestionFile.py
erp5/trunk/products/ERP5/Tool/ContributionRegistryTool.py
Added: erp5/trunk/products/ERP5/Document/ContributionPredicate.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/ContributionPredicate.py?rev=20155&view=auto
==============================================================================
--- erp5/trunk/products/ERP5/Document/ContributionPredicate.py (added)
+++ erp5/trunk/products/ERP5/Document/ContributionPredicate.py Wed Mar 26 16:13:27 2008
@@ -1,0 +1,139 @@
+#############################################################################
+#
+# Copyright (c) 2008 Nexedi SA and Contributors. All Rights Reserved.
+# Yusei TAHARA <yusei 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 Acquisition import aq_base
+from AccessControl import ClassSecurityInfo
+from Products.ERP5.Document.Predicate import Predicate
+from Products.ERP5Type.XMLObject import XMLObject
+from Products.ERP5Type import Permissions, PropertySheet, Interface
+from Products.ERP5Type.Cache import getReadOnlyTransactionCache, enableReadOnlyTransactionCache, disableReadOnlyTransactionCache
+
+
+class ContributionPredicate(Predicate, XMLObject):
+ """
+ """
+
+ meta_type = 'ERP5 Contribution Predicate'
+ portal_type = 'Contribution Predicate'
+ add_permission = Permissions.AddPortalContent
+ isPortalContent = 1
+ isRADContent = 1
+ isPredicate = 1
+
+ # Declarative security
+ security = ClassSecurityInfo()
+ security.declareObjectProtected(Permissions.AccessContentsInformation)
+
+ __implements__ = (Interface.Predicate,)
+
+ # Default Properties
+ property_sheets = ( PropertySheet.Base
+ , PropertySheet.XMLObject
+ , PropertySheet.CategoryCore
+ , PropertySheet.DublinCore
+ , PropertySheet.Predicate
+ , PropertySheet.SortIndex
+ , PropertySheet.ContributionPredicate
+ )
+
+ security.declareProtected( Permissions.AccessContentsInformation, 'test')
+ def test(self, context, tested_base_category_list=None, **kw):
+ """
+ A Predicate can be tested on a given context.
+ Parameters can passed in order to ignore some conditions.
+
+ - tested_base_category_list: this is the list of category that we do
+ want to test. For example, we might want to test only the
+ destination or the source of a predicate.
+
+ This method returns portal type name if test success, else returns False.
+ """
+ self = self.asPredicate()
+ result = 1
+ if getattr(aq_base(self), '_identity_criterion', None) is None:
+ self._identity_criterion = {}
+ self._range_criterion = {}
+ for property, value in self._identity_criterion.iteritems():
+ result = result and (context.getProperty(property) in value)
+ for property, (min, max) in self._range_criterion.iteritems():
+ value = context.getProperty(property)
+ if min is not None:
+ result = result and (value >= min)
+ if max is not None:
+ result = result and (value < max)
+ multimembership_criterion_base_category_list = \
+ self.getMultimembershipCriterionBaseCategoryList()
+ membership_criterion_base_category_list = \
+ self.getMembershipCriterionBaseCategoryList()
+ tested_base_category = {}
+ membership_criterion_category_list = \
+ self.getMembershipCriterionCategoryList()
+ if tested_base_category_list is not None:
+ membership_criterion_category_list = [x for x in \
+ membership_criterion_category_list if x.split('/', 1)[0] in \
+ tested_base_category_list]
+
+ # Test category memberships. Enable the read-only transaction cache
+ # temporarily, if not enabled, because this part is strictly read-only,
+ # and context.isMemberOf is very expensive, when the category list has
+ # many items.
+ enabled = (getReadOnlyTransactionCache(self) is not None)
+ try:
+ if not enabled:
+ enableReadOnlyTransactionCache(self)
+ for c in membership_criterion_category_list:
+ bc = c.split('/', 1)[0]
+ if (bc not in tested_base_category) and \
+ (bc in multimembership_criterion_base_category_list):
+ tested_base_category[bc] = 1
+ elif (bc not in tested_base_category) and \
+ (bc in membership_criterion_base_category_list):
+ tested_base_category[bc] = 0
+ if (bc in multimembership_criterion_base_category_list):
+ tested_base_category[bc] = tested_base_category[bc] and \
+ context.isMemberOf(c)
+ elif (bc in membership_criterion_base_category_list):
+ tested_base_category[bc] = tested_base_category[bc] or \
+ context.isMemberOf(c)
+ finally:
+ if not enabled:
+ disableReadOnlyTransactionCache(self)
+
+ result = result and (0 not in tested_base_category.values())
+ # Test method calls
+ test_method_id_list = self.getTestMethodIdList()
+ if test_method_id_list:
+ for test_method_id in test_method_id_list:
+ if (test_method_id is not None) and result:
+ method = getattr(context, test_method_id)
+ result = result and method(self)
+ else:
+ result = result and self.getDestinationPortalType()
+ return result
+
+ def asSQLExpression(self):
+ raise NotImplementedError, 'ContributionPredicate does not support asSQLExpression.'
Added: erp5/trunk/products/ERP5/Document/IngestionFile.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/IngestionFile.py?rev=20155&view=auto
==============================================================================
--- erp5/trunk/products/ERP5/Document/IngestionFile.py (added)
+++ erp5/trunk/products/ERP5/Document/IngestionFile.py Wed Mar 26 16:13:27 2008
@@ -1,0 +1,50 @@
+#############################################################################
+#
+# Copyright (c) 2008 Nexedi SA and Contributors. All Rights Reserved.
+# Yusei TAHARA <yusei 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 AccessControl import ClassSecurityInfo
+from Products.ERP5Type import Permissions, PropertySheet
+from Products.ERP5Type.Base import Base
+from Products.ERP5Type.Core.Folder import Folder
+
+
+class IngestionFile(Base, Folder):
+ """
+ This class is used only in the process of finding appropriate portal type
+ for ingested file in Contribution Registry Tool.
+ """
+
+ security = ClassSecurityInfo()
+ security.declareObjectProtected(Permissions.AccessContentsInformation)
+
+ property_sheets = (
+ PropertySheet.Base,
+ PropertySheet.Data,
+ PropertySheet.IngestionFile,
+ )
+
+ def getFileExtension(self):
+ return self.getFileName('').split('.')[-1].lower()
Added: erp5/trunk/products/ERP5/PropertySheet/ContributionPredicate.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/PropertySheet/ContributionPredicate.py?rev=20155&view=auto
==============================================================================
--- erp5/trunk/products/ERP5/PropertySheet/ContributionPredicate.py (added)
+++ erp5/trunk/products/ERP5/PropertySheet/ContributionPredicate.py Wed Mar 26 16:13:27 2008
@@ -1,0 +1,41 @@
+#############################################################################
+#
+# Copyright (c) 2008 Nexedi SA and Contributors. All Rights Reserved.
+# Yusei TAHARA <yusei 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.
+#
+##############################################################################
+
+
+class ContributionPredicate:
+ """
+ ContributionPredicate properties
+ """
+
+ _properties = (
+ {'id' : 'destination_portal_type',
+ 'description' : 'Portal type which is a result of matching',
+ 'default' : '',
+ 'type' : 'string',
+ 'mode' : 'w'},
+ )
Added: erp5/trunk/products/ERP5/PropertySheet/IngestionFile.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/PropertySheet/IngestionFile.py?rev=20155&view=auto
==============================================================================
--- erp5/trunk/products/ERP5/PropertySheet/IngestionFile.py (added)
+++ erp5/trunk/products/ERP5/PropertySheet/IngestionFile.py Wed Mar 26 16:13:27 2008
@@ -1,0 +1,49 @@
+#############################################################################
+#
+# Copyright (c) 2008 Nexedi SA and Contributors. All Rights Reserved.
+# Yusei TAHARA <yusei 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.
+#
+##############################################################################
+
+
+class IngestionFile:
+ """
+ This property sheet is for a file which is ingested into erp5 through
+ http or smtp, etc.
+ """
+
+ _properties = (
+ {'id' : 'file_name',
+ 'description' : 'Filename',
+ 'type' : 'string',
+ 'default' : '',
+ 'mode' : 'w' },
+ {'id' : 'file_extension',
+ 'description' : 'File extension',
+ 'type' : 'string',
+ 'default' : '',
+ 'mode' : 'w' },
+ )
+
+ _categories = ('mime_type',)
Added: erp5/trunk/products/ERP5/Tool/ContributionRegistryTool.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Tool/ContributionRegistryTool.py?rev=20155&view=auto
==============================================================================
--- erp5/trunk/products/ERP5/Tool/ContributionRegistryTool.py (added)
+++ erp5/trunk/products/ERP5/Tool/ContributionRegistryTool.py Wed Mar 26 16:13:27 2008
@@ -1,0 +1,54 @@
+#############################################################################
+#
+# Copyright (c) 2008 Nexedi SA and Contributors. All Rights Reserved.
+# Yusei TAHARA <yusei 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 AccessControl import ClassSecurityInfo
+from Globals import InitializeClass
+from Products.ERP5Type.Tool.BaseTool import BaseTool
+
+
+class ContributionRegistryTool(BaseTool):
+
+ id = 'portal_contribution_registry'
+ title = 'Contribution Registry Tool'
+ meta_type = 'ERP5 Contribution Registry Tool'
+ portal_type = 'Contribution Registry Tool'
+ allowed_types = ('ERP5 Contribution Predicate',)
+
+ security = ClassSecurityInfo()
+
+ security.declarePrivate('findPortalTypeName')
+ def findPortalTypeName(self, file_name='', mime_type=None, data=None):
+ from Products.ERP5Type.Document import newTempIngestionFile
+ ingestion_file = newTempIngestionFile(self, 'id')
+ ingestion_file._edit(file_name=file_name, mime_type=mime_type, data=data)
+
+ for predicate in self.objectValues(sort_on='int_index'):
+ result = predicate.test(ingestion_file)
+ if not result in (None, False):
+ return result
+
+InitializeClass(ContributionRegistryTool)
More information about the Erp5-report
mailing list