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

Make the code compatible with Sql naming (instead of SQL). Add the...

Make the code compatible with Sql naming  (instead of SQL). Add the possibility to combine report and domain sections by using table aliasing. 

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@12060 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 9b702c12
......@@ -190,7 +190,7 @@ class Selection(Acquisition.Implicit, Traversable, Persistent):
if len(sort_on) > 0:
kw['sort_on'] = sort_on
elif kw.has_key('sort_on'):
del kw.params['sort_on'] # XXX JPS: Should this be really deleted ?
del kw['sort_on'] # We should not sort if no sort was defined
if method is not None:
if callable(method):
if self.domain is not None and self.report is not None:
......@@ -420,7 +420,8 @@ class DomainSelection(Acquisition.Implicit, Traversable, Persistent):
security.declarePublic('asSQLExpression')
def asSQLExpression(self, table_map=None, domain_id=None,
exclude_domain_id=None, strict_membership=0,
join_table="catalog", join_column="uid", base_category=None):
join_table="catalog", join_column="uid", base_category=None,
category_table_alias='category'):
select_expression = []
portal = self.getPortalObject()
for k, d in self.domain_dict.iteritems():
......@@ -432,13 +433,13 @@ class DomainSelection(Acquisition.Implicit, Traversable, Persistent):
strict_membership=strict_membership))
elif k is not None:
if getattr(aq_base(d), 'isPredicate', 0):
select_expression.append(d.asSQLExpression(table='%s_category' % k,
select_expression.append(d.asSQLExpression(table='%s_%s' % (k, category_table_alias),
strict_membership=strict_membership))
else:
# This is a category, we must join
select_expression.append('%s.%s = %s_category.uid' % \
(join_table, join_column, k))
select_expression.append(d.asSQLExpression(table='%s_category' % k,
select_expression.append('%s.%s = %s_%s.uid' % \
(join_table, join_column, k, category_table_alias))
select_expression.append(d.asSQLExpression(table='%s_%s' % (k, category_table_alias),
base_category=k,
strict_membership=strict_membership))
# XXX We should take into account k explicitely
......@@ -450,8 +451,12 @@ class DomainSelection(Acquisition.Implicit, Traversable, Persistent):
#LOG('DomainSelection', 0, 'asSQLExpression returns %r' % (result,))
return result
# Compatibility SQL Sql
security.declarePublic('asSqlExpression')
asSqlExpression = asSQLExpression
security.declarePublic('asSQLJoinExpression')
def asSQLJoinExpression(self, domain_id=None, exclude_domain_id=None):
def asSQLJoinExpression(self, domain_id=None, exclude_domain_id=None, category_table_alias='category'):
join_expression = []
#LOG('DomainSelection', 0, 'domain_id = %r, exclude_domain_id = %r, self.domain_dict = %r' % (domain_id, exclude_domain_id, self.domain_dict))
portal = self.getPortalObject()
......@@ -462,14 +467,18 @@ class DomainSelection(Acquisition.Implicit, Traversable, Persistent):
pass
elif k is not None:
if getattr(aq_base(d), 'isPredicate', 0):
join_expression.append(d.asSQLJoinExpression(table='%s_category' % k))
join_expression.append(d.asSQLJoinExpression(table='%s_%s' % (k, category_table_alias)))
else:
# This is a category, we must join
join_expression.append('category AS %s_category' % k)
join_expression.append('category AS %s_%s' % (k, category_table_alias))
result = "%s" % ' , '.join(join_expression)
#LOG('DomainSelection', 0, 'asSQLJoinExpression returns %r' % (result,))
return result
# Compatibility SQL Sql
security.declarePublic('asSqlJoinExpression')
asSqlJoinExpression = asSQLJoinExpression
security.declarePublic('asDomainDict')
def asDomainDict(self, domain_id=None, exclude_domain_id=None):
return self.domain_dict
......
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