Commit b43da1e9 authored by Jérome Perrin's avatar Jérome Perrin

check that the path column is retrived when trying to get the object, not when...

check that the path column is retrived when trying to get the object, not when initializing the class, not to break compatibility whith methods that are defined to ZSQLBrain without actually using it (eg. z_count_results). Also remove commented out code


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@6071 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 1e3f75ee
...@@ -26,12 +26,6 @@ class ZSQLBrain(Acquisition.Implicit): ...@@ -26,12 +26,6 @@ class ZSQLBrain(Acquisition.Implicit):
security = ClassSecurityInfo() security = ClassSecurityInfo()
security.declareObjectPublic() security.declareObjectPublic()
def __init__(self) :
"""Init the brain and make sure path was retrieved from the RDB"""
if 'path' not in dir(self) and 'PATH' not in dir(self):
raise ValueError, "Unable to use ZSQLBrain if ZSQL Method does "\
"not retrieves the `path` column from catalog table."
def _aq_dynamic(self, name): def _aq_dynamic(self, name):
"""Acquire an attribute from a real object. """Acquire an attribute from a real object.
""" """
...@@ -40,25 +34,6 @@ class ZSQLBrain(Acquisition.Implicit): ...@@ -40,25 +34,6 @@ class ZSQLBrain(Acquisition.Implicit):
o = self.getObject() o = self.getObject()
return getattr(o, name, None) return getattr(o, name, None)
# def __getattr__(self, key):
# return "toto"
# if hasattr(self, key):
# return self.__dict__[key]
# elif hasattr(ZSQLBrain, key):
# return ZSQLBrain.__dict__[key]
# else:
# if self.o_self is None:
# self.o_self = self.getObject()
# if self.o_self is not None:
# try:
# result = self.o_self.getProperty(key)
# self.__dict__[key] = result
# except:
# result = 'Can not evaluate attribute: %s' % cname_id
# else:
# result = 'Object does not exist'
# return result
def getURL(self): def getURL(self):
return self.path return self.path
...@@ -75,17 +50,23 @@ class ZSQLBrain(Acquisition.Implicit): ...@@ -75,17 +50,23 @@ class ZSQLBrain(Acquisition.Implicit):
def getObject(self, REQUEST=None): def getObject(self, REQUEST=None):
"""Try to return the object for this record""" """Try to return the object for this record"""
if 'path' not in dir(self) and 'PATH' not in dir(self):
raise ValueError, "Unable to getObject from ZSQLBrain if ZSQL Method "\
"does not retrieves the `path` column from catalog table."
try: try:
obj = self.aq_parent.unrestrictedTraverse(self.getPath()) obj = self.aq_parent.unrestrictedTraverse(self.getPath())
if obj is None: if obj is None:
if REQUEST is None: if REQUEST is None:
REQUEST = self.REQUEST REQUEST = self.REQUEST
obj = self.aq_parent.portal_catalog.resolve_url(self.getPath(), REQUEST) obj = self.aq_parent.portal_catalog.resolve_url(
self.getPath(), REQUEST)
return obj return obj
except ConflictError: except ConflictError:
raise raise
except: except:
LOG("ZCatalog WARNING",0,"Could not access object path %s" % self.getPath(), error=sys.exc_info() ) LOG("ZCatalog WARNING", 0,
"Could not access object path %s" % self.getPath(),
error=sys.exc_info() )
return None return None
def absolute_url(self): def absolute_url(self):
......
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