From df083b549751776b8dc09d96135273f87d95d1c7 Mon Sep 17 00:00:00 2001 From: Nicolas Delaby <nicolas@nexedi.com> Date: Wed, 11 Jun 2008 15:15:14 +0000 Subject: [PATCH] Filter category Accessors generation if base_category is missing git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@21505 20353a03-c40f-0410-a6d1-a30d3c3de9de --- product/ERP5Type/Utils.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/product/ERP5Type/Utils.py b/product/ERP5Type/Utils.py index c37477f1ed..9facfcb4cb 100644 --- a/product/ERP5Type/Utils.py +++ b/product/ERP5Type/Utils.py @@ -50,6 +50,7 @@ from Products.ZCatalog.Lazy import LazyMap from Products.ERP5Type import Permissions from Products.ERP5Type import Constraint +from Products.ERP5Type.Cache import getReadOnlyTransactionCache from zLOG import LOG, BLATHER, PROBLEM @@ -1057,6 +1058,26 @@ def createExpressionContext(object, portal=None): } return getEngine().getContext(data) +def getExistingBaseCategoryList(portal, base_cat_list): + cache = getReadOnlyTransactionCache(portal) + if cache is None: + from Products.ERP5Type.TransactionalVariable import getTransactionalVariable + cache = getTransactionalVariable(portal) + category_tool = portal.portal_categories + new_base_cat_list = [] + for base_cat in base_cat_list: + key = (base_cat,) + try: + value = cache[key] + except KeyError: + value = category_tool._getOb(base_cat, None) + if value is None: + LOG('ERP5Type.Utils.getExistingBaseCategoryList', PROBLEM, 'base_category "%s" is missing, can not generate Accessors' % (base_cat)) + cache[key] = value + if value is not None: + new_base_cat_list.append(base_cat) + return tuple(new_base_cat_list) + def setDefaultProperties(property_holder, object=None, portal=None): """ This methods sets default accessors for this object as well @@ -1121,7 +1142,7 @@ def setDefaultProperties(property_holder, object=None, portal=None): new_cat_list.append(result) else: new_cat_list.append(cat) - cat_list = new_cat_list + cat_list = getExistingBaseCategoryList(portal, new_cat_list) for const in constraint_list: for key,value in const.items(): -- 2.30.9