Commit 46148e8b authored by Jean-Paul Smets's avatar Jean-Paul Smets

asSqlExpression support for base_category


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@5413 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 792a1a19
...@@ -406,7 +406,7 @@ class Category(Folder): ...@@ -406,7 +406,7 @@ 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, table='category'): def asSqlExpression(self, strict_membership=0, table='category', base_category = None):
""" """
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
...@@ -414,14 +414,18 @@ class Category(Folder): ...@@ -414,14 +414,18 @@ class Category(Folder):
""" """
#LOG('asSqlExpression', 0, str(self)) #LOG('asSqlExpression', 0, str(self))
#LOG('asSqlExpression parent', 0, str(self.aq_parent)) #LOG('asSqlExpression parent', 0, str(self.aq_parent))
if base_category is None:
base_category = self
elif type(base_category) is type('a'):
base_category = self.portal_categories[base_category]
if strict_membership: if strict_membership:
sql_text = '(%s.category_uid = %s AND %s.base_category_uid = %s ' \ sql_text = '(%s.category_uid = %s AND %s.base_category_uid = %s ' \
'AND %s.category_strict_membership = 1)' % \ 'AND %s.category_strict_membership = 1)' % \
(table, self.getUid(), table, (table, self.getUid(), table,
self.getBaseCategoryUid(), table) base_category.getBaseCategoryUid(), table)
else: else:
sql_text = '(%s.category_uid = %s AND %s.base_category_uid = %s)' % \ sql_text = '(%s.category_uid = %s AND %s.base_category_uid = %s)' % \
(table, self.getUid(), table, self.getBaseCategoryUid()) (table, self.getUid(), table, base_category.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()
......
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