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): ...@@ -190,7 +190,7 @@ class Selection(Acquisition.Implicit, Traversable, Persistent):
if len(sort_on) > 0: if len(sort_on) > 0:
kw['sort_on'] = sort_on kw['sort_on'] = sort_on
elif kw.has_key('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 method is not None:
if callable(method): if callable(method):
if self.domain is not None and self.report is not None: if self.domain is not None and self.report is not None:
...@@ -420,7 +420,8 @@ class DomainSelection(Acquisition.Implicit, Traversable, Persistent): ...@@ -420,7 +420,8 @@ class DomainSelection(Acquisition.Implicit, Traversable, Persistent):
security.declarePublic('asSQLExpression') security.declarePublic('asSQLExpression')
def asSQLExpression(self, table_map=None, domain_id=None, def asSQLExpression(self, table_map=None, domain_id=None,
exclude_domain_id=None, strict_membership=0, 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 = [] select_expression = []
portal = self.getPortalObject() portal = self.getPortalObject()
for k, d in self.domain_dict.iteritems(): for k, d in self.domain_dict.iteritems():
...@@ -432,13 +433,13 @@ class DomainSelection(Acquisition.Implicit, Traversable, Persistent): ...@@ -432,13 +433,13 @@ class DomainSelection(Acquisition.Implicit, Traversable, Persistent):
strict_membership=strict_membership)) strict_membership=strict_membership))
elif k is not None: elif k is not None:
if getattr(aq_base(d), 'isPredicate', 0): 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)) strict_membership=strict_membership))
else: else:
# This is a category, we must join # This is a category, we must join
select_expression.append('%s.%s = %s_category.uid' % \ select_expression.append('%s.%s = %s_%s.uid' % \
(join_table, join_column, k)) (join_table, join_column, k, category_table_alias))
select_expression.append(d.asSQLExpression(table='%s_category' % k, select_expression.append(d.asSQLExpression(table='%s_%s' % (k, category_table_alias),
base_category=k, base_category=k,
strict_membership=strict_membership)) strict_membership=strict_membership))
# XXX We should take into account k explicitely # XXX We should take into account k explicitely
...@@ -450,8 +451,12 @@ class DomainSelection(Acquisition.Implicit, Traversable, Persistent): ...@@ -450,8 +451,12 @@ class DomainSelection(Acquisition.Implicit, Traversable, Persistent):
#LOG('DomainSelection', 0, 'asSQLExpression returns %r' % (result,)) #LOG('DomainSelection', 0, 'asSQLExpression returns %r' % (result,))
return result return result
# Compatibility SQL Sql
security.declarePublic('asSqlExpression')
asSqlExpression = asSQLExpression
security.declarePublic('asSQLJoinExpression') 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 = [] join_expression = []
#LOG('DomainSelection', 0, 'domain_id = %r, exclude_domain_id = %r, self.domain_dict = %r' % (domain_id, exclude_domain_id, self.domain_dict)) #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() portal = self.getPortalObject()
...@@ -462,14 +467,18 @@ class DomainSelection(Acquisition.Implicit, Traversable, Persistent): ...@@ -462,14 +467,18 @@ class DomainSelection(Acquisition.Implicit, Traversable, Persistent):
pass pass
elif k is not None: elif k is not None:
if getattr(aq_base(d), 'isPredicate', 0): 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: else:
# This is a category, we must join # 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) result = "%s" % ' , '.join(join_expression)
#LOG('DomainSelection', 0, 'asSQLJoinExpression returns %r' % (result,)) #LOG('DomainSelection', 0, 'asSQLJoinExpression returns %r' % (result,))
return result return result
# Compatibility SQL Sql
security.declarePublic('asSqlJoinExpression')
asSqlJoinExpression = asSQLJoinExpression
security.declarePublic('asDomainDict') security.declarePublic('asDomainDict')
def asDomainDict(self, domain_id=None, exclude_domain_id=None): def asDomainDict(self, domain_id=None, exclude_domain_id=None):
return self.domain_dict 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