allow passing the zsql_brain for ZSQLMethods and provide a brain that never...

allow passing the zsql_brain for ZSQLMethods and provide a brain that never gets the original object

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@39357 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 7fdae824
......@@ -15,26 +15,27 @@
import string
import Acquisition
import sys
import traceback
from ZODB.POSException import ConflictError
from AccessControl import ClassSecurityInfo
from AccessControl.SecurityInfo import allow_class
from zLOG import LOG
from zLOG import LOG, WARNING
_MARKER = []
class ZSQLBrain(Acquisition.Implicit):
class ZSQLBrain(Acquisition.Implicit):
security = ClassSecurityInfo()
security.declareObjectPublic()
def _aq_dynamic(self, name):
"""Acquire an attribute from a real object.
"""
if name.startswith('__') :
return None
o = self.getObject()
return getattr(o, name, None)
"""Acquire an attribute from a real object.
"""
if name.startswith('__') :
return None
o = self.getObject()
return getattr(o, name, None)
def getURL(self):
return self.path
......@@ -120,3 +121,38 @@ class ZSQLBrain(Acquisition.Implicit):
pass
allow_class(ZSQLBrain)
class ZSQLBrainNoObject(ZSQLBrain):
security = ClassSecurityInfo()
security.declareObjectPublic()
def getObject(self):
stack = ''.join(traceback.format_stack())
LOG('Products.ZSQLCatalog.Extentions.zsqlbrain.ZSQLBrainNoObject', WARNING,
"Attempted direct access to object %r:\n%s" % (self.getPath(), stack))
return None
def getProperty(self, name, d=_MARKER, **kw):
value = None
if hasattr(self, name):
value = getattr(self, name)
else:
stack = ''.join(traceback.format_stack())
LOG('Products.ZSQLCatalog.Extentions.zsqlbrain.ZSQLBrainNoObject',
WARNING,
"Non-existing property %r on record for %r:\n%s" % (name,
self.getPath(),
stack))
return None
return value
def _aq_dynamic(self, name):
"""Do not acquire an attribute from a real object.
"""
stack = ''.join(traceback.format_stack(limit=5))
LOG('Products.ZSQLCatalog.Extentions.zsqlbrain.ZSQLBrainNoObject', WARNING,
"Non-existing attribute %r on record for %r:\n%s" % (name,
self.getPath(),
stack))
allow_class(ZSQLBrainNoObject)
......@@ -2354,6 +2354,12 @@ class Catalog(Folder,
"""
return getComparisonOperatorInstance(operator)
PROPAGATE_PARAMETER_SET = set(['selection_domain',
'selection_report',
# XXX should get the next parameters from
# the ZSQLMethod class itself
'zsql_brain',
])
@profiler_decorator
def _queryResults(self, REQUEST=None, build_sql_query_method=None, **kw):
""" Returns a list of brains from a set of constraints on variables """
......@@ -2363,11 +2369,10 @@ class Catalog(Folder,
# XXX: decide if this should be made normal
ENFORCE_SEPARATION = True
if ENFORCE_SEPARATION:
new_kw = {}
# Some parameters must be propagated:
for parameter_id in ('selection_domain', 'selection_report'):
if parameter_id in kw:
new_kw[parameter_id] = kw[parameter_id]
new_kw = dict((name, kw[name])
for name in self.PROPAGATE_PARAMETER_SET & set(kw))
# discard all others:
kw = new_kw
kw['where_expression'] = query['where_expression']
kw['sort_on'] = query['order_by_expression']
......@@ -2376,6 +2381,7 @@ class Catalog(Folder,
kw['limit_expression'] = query['limit_expression']
kw['select_expression'] = query['select_expression']
kw['group_by_expression'] = query['group_by_expression']
# XXX: why not kw.update(query)??
return kw
def queryResults(self, sql_method, REQUEST=None, src__=0, build_sql_query_method=None, **kw):
......
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