[Erp5-report] r12060 - /erp5/trunk/products/ERP5Form/Selection.py

nobody at svn.erp5.org nobody at svn.erp5.org
Sat Jan 13 16:16:06 CET 2007


Author: jp
Date: Sat Jan 13 16:16:04 2007
New Revision: 12060

URL: http://svn.erp5.org?rev=12060&view=rev
Log:
Make the code compatible with Sql naming  (instead of SQL). Add the possibility to combine report and domain sections by using table aliasing. 

Modified:
    erp5/trunk/products/ERP5Form/Selection.py

Modified: erp5/trunk/products/ERP5Form/Selection.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Form/Selection.py?rev=12060&r1=12059&r2=12060&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Form/Selection.py (original)
+++ erp5/trunk/products/ERP5Form/Selection.py Sat Jan 13 16:16:04 2007
@@ -190,7 +190,7 @@
         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 @@
   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 @@
                                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 @@
     #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 @@
         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




More information about the Erp5-report mailing list