Commit fdc52fbd authored by Jean-Paul Smets's avatar Jean-Paul Smets

asSqlExpression can be specified table id


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@1358 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent c566864b
...@@ -311,17 +311,19 @@ class Category(Folder): ...@@ -311,17 +311,19 @@ class Category(Folder):
return "context.isMemberOf('%s')" % self.getCategoryRelativeUrl(base = 1) return "context.isMemberOf('%s')" % self.getCategoryRelativeUrl(base = 1)
security.declareProtected( Permissions.AccessContentsInformation, 'asSqlExpression' ) security.declareProtected( Permissions.AccessContentsInformation, 'asSqlExpression' )
def asSqlExpression(self, strict_membership=0): def asSqlExpression(self, strict_membership=0, table='category'):
""" """
A Predicate can be rendered as an sql expression. This A Predicate can be rendered as an sql expression. This
can be useful to create reporting trees based on the can be useful to create reporting trees based on the
ZSQLCatalog ZSQLCatalog
""" """
#LOG('asSqlExpression', 0, str(self))
#LOG('asSqlExpression parent', 0, str(self.aq_parent))
if strict_membership: if strict_membership:
sql_text = '(category.category_uid = %s AND category.base_category_uid = %s AND category.category_strict_membership = 1)' % (self.uid, self.getBaseCategory().uid) sql_text = '(%s.category_uid = %s AND %s.base_category_uid = %s AND %s.category_strict_membership = 1)' % (table, self.getUid(), table, self.getBaseCategoryUid(), table)
else: else:
sql_text = '(category.category_uid = %s AND category.base_category_uid = %s)' % (self.uid, sql_text = '(%s.category_uid = %s AND %s.base_category_uid = %s)' % (table, self.getUid(),
self.getBaseCategory().uid) table, self.getBaseCategoryUid())
# Now useless since we precompute the mapping # Now useless since we precompute the mapping
#for o in self.objectValues(): #for o in self.objectValues():
# sql_text += ' OR %s' % o.asSqlExpression() # sql_text += ' OR %s' % o.asSqlExpression()
...@@ -432,16 +434,16 @@ class BaseCategory(Category): ...@@ -432,16 +434,16 @@ class BaseCategory(Category):
# Declarative security # Declarative security
security = ClassSecurityInfo() security = ClassSecurityInfo()
def asSqlExpression(self, strict_membership=0): def asSqlExpression(self, strict_membership=0, table='category'):
""" """
A Predicate can be rendered as an sql expression. This A Predicate can be rendered as an sql expression. This
can be useful to create reporting trees based on the can be useful to create reporting trees based on the
ZSQLCatalog ZSQLCatalog
""" """
if strict_membership: if strict_membership:
sql_text = '(category.category_uid = %s AND category.base_category_uid = %s AND category.category_strict_membership = 1)' % (self.uid, self.uid) sql_text = '(%s.category_uid = %s AND %s.base_category_uid = %s AND %s.category_strict_membership = 1)' % (table, self.uid, table, self.uid, table)
else: else:
sql_text = '(category.category_uid = %s AND category.base_category_uid = %s)' % (self.uid, self.uid) sql_text = '(%s.category_uid = %s AND %s.base_category_uid = %s)' % (table, self.uid, table, self.uid)
# Now useless since we precompute the mapping # Now useless since we precompute the mapping
#for o in self.objectValues(): #for o in self.objectValues():
# sql_text += ' OR %s' % o.asSqlExpression() # sql_text += ' OR %s' % o.asSqlExpression()
...@@ -463,7 +465,7 @@ class BaseCategory(Category): ...@@ -463,7 +465,7 @@ class BaseCategory(Category):
acquired through portal categories. Very acquired through portal categories. Very
useful to implement relations and virtual categories. useful to implement relations and virtual categories.
""" """
return self.getBaseCategory().uid return self.getBaseCategory().getUid()
security.declareProtected( Permissions.AccessContentsInformation, 'getBaseCategoryValue' ) security.declareProtected( Permissions.AccessContentsInformation, 'getBaseCategoryValue' )
def getBaseCategoryValue(self): def getBaseCategoryValue(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