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,12 +15,13 @@ ...@@ -15,12 +15,13 @@
import string import string
import Acquisition import Acquisition
import sys import sys
import traceback
from ZODB.POSException import ConflictError from ZODB.POSException import ConflictError
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from AccessControl.SecurityInfo import allow_class from AccessControl.SecurityInfo import allow_class
from zLOG import LOG from zLOG import LOG, WARNING
_MARKER = [] _MARKER = []
...@@ -120,3 +121,38 @@ class ZSQLBrain(Acquisition.Implicit): ...@@ -120,3 +121,38 @@ class ZSQLBrain(Acquisition.Implicit):
pass pass
allow_class(ZSQLBrain) 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, ...@@ -2354,6 +2354,12 @@ class Catalog(Folder,
""" """
return getComparisonOperatorInstance(operator) 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 @profiler_decorator
def _queryResults(self, REQUEST=None, build_sql_query_method=None, **kw): def _queryResults(self, REQUEST=None, build_sql_query_method=None, **kw):
""" Returns a list of brains from a set of constraints on variables """ """ Returns a list of brains from a set of constraints on variables """
...@@ -2363,11 +2369,10 @@ class Catalog(Folder, ...@@ -2363,11 +2369,10 @@ class Catalog(Folder,
# XXX: decide if this should be made normal # XXX: decide if this should be made normal
ENFORCE_SEPARATION = True ENFORCE_SEPARATION = True
if ENFORCE_SEPARATION: if ENFORCE_SEPARATION:
new_kw = {}
# Some parameters must be propagated: # Some parameters must be propagated:
for parameter_id in ('selection_domain', 'selection_report'): new_kw = dict((name, kw[name])
if parameter_id in kw: for name in self.PROPAGATE_PARAMETER_SET & set(kw))
new_kw[parameter_id] = kw[parameter_id] # discard all others:
kw = new_kw kw = new_kw
kw['where_expression'] = query['where_expression'] kw['where_expression'] = query['where_expression']
kw['sort_on'] = query['order_by_expression'] kw['sort_on'] = query['order_by_expression']
...@@ -2376,6 +2381,7 @@ class Catalog(Folder, ...@@ -2376,6 +2381,7 @@ class Catalog(Folder,
kw['limit_expression'] = query['limit_expression'] kw['limit_expression'] = query['limit_expression']
kw['select_expression'] = query['select_expression'] kw['select_expression'] = query['select_expression']
kw['group_by_expression'] = query['group_by_expression'] kw['group_by_expression'] = query['group_by_expression']
# XXX: why not kw.update(query)??
return kw return kw
def queryResults(self, sql_method, REQUEST=None, src__=0, build_sql_query_method=None, **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