[Erp5-report] r33945 nicolas - /erp5/trunk/products/ERP5Type/Constraint/AttributeUnicity.py
nobody at svn.erp5.org
nobody at svn.erp5.org
Mon Mar 22 14:20:53 CET 2010
Author: nicolas
Date: Mon Mar 22 14:20:51 2010
New Revision: 33945
URL: http://svn.erp5.org?rev=33945&view=rev
Log:
Add uid in criterion keys to avoid fetching current object.
Modified:
erp5/trunk/products/ERP5Type/Constraint/AttributeUnicity.py
Modified: erp5/trunk/products/ERP5Type/Constraint/AttributeUnicity.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/Constraint/AttributeUnicity.py?rev=33945&r1=33944&r2=33945&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/Constraint/AttributeUnicity.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/Constraint/AttributeUnicity.py [utf8] Mon Mar 22 14:20:51 2010
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2002, 2005 Nexedi SARL and Contributors. All Rights Reserved.
@@ -31,6 +32,7 @@
from PropertyExistence import PropertyExistence
from Products.CMFCore.Expression import Expression
+from Products.ZSQLCatalog.SQLCatalog import Query, NegatedQuery
class AttributeUnicity(PropertyExistence):
"""
@@ -67,7 +69,10 @@
from Products.ERP5Type.Utils import createExpressionContext
econtext = createExpressionContext(obj)
criterion_dict = expression(econtext)
- result = obj.portal_catalog.countResults(**criterion_dict)[0][0]
+ # Add uid in criterion keys to avoid fetching current object.
+ criterion_dict['query'] = NegatedQuery(Query(uid=obj.getUid()))
+ portal = obj.portal_catalog.getPortalObject()
+ result = portal.portal_catalog.countResults(**criterion_dict)[0][0]
if result >= 1:
mapping['value'] = criterion_dict.get(attribute_name)
message_id = 'message_invalid_attribute_unicity'
More information about the Erp5-report
mailing list