[Erp5-report] r30540 - /erp5/trunk/products/ZSQLCatalog/SearchKey/RelatedKey.py

nobody at svn.erp5.org nobody at svn.erp5.org
Fri Nov 13 07:44:44 CET 2009


Author: yusuke
Date: Fri Nov 13 07:44:43 2009
New Revision: 30540

URL: http://svn.erp5.org?rev=30540&view=rev
Log:
clean up the code

Modified:
    erp5/trunk/products/ZSQLCatalog/SearchKey/RelatedKey.py

Modified: erp5/trunk/products/ZSQLCatalog/SearchKey/RelatedKey.py
URL: http://svn.erp5.org/erp5/trunk/products/ZSQLCatalog/SearchKey/RelatedKey.py?rev=30540&r1=30539&r2=30540&view=diff
==============================================================================
--- erp5/trunk/products/ZSQLCatalog/SearchKey/RelatedKey.py [utf8] (original)
+++ erp5/trunk/products/ZSQLCatalog/SearchKey/RelatedKey.py [utf8] Fri Nov 13 07:44:43 2009
@@ -158,12 +158,26 @@
         Ignored.
     """
     related_key = getattr(sql_catalog, self.related_key_id)
-    table_alias_dict = dict(
-      [('table_%s' % (x, ), column_map.getTableAlias(self.table_list[x], group=column_map.getRelatedKeyGroup(x, group)))
-       for x in xrange(len(self.table_list) - 1)])
-    x = len(table_alias_dict)
-    assert x == len(self.table_list) - 1
-    table_alias_dict['table_%s' % (x, )] = column_map.getTableAlias(self.table_list[x], group=group)
+
+    # related key is defined in catalog
+    related_table_list, destination_table = self.table_list[:-1], self.table_list[-1]
+
+    # method caching
+    getTableAlias = column_map.getTableAlias
+    getRelatedKeyGroup = column_map.getRelatedKeyGroup
+
+    # table aliases for related tables
+    table_alias_list = [(getTableAlias(related_table, group=getRelatedKeyGroup(index, group)), related_table)
+                        for (index, related_table) in enumerate(related_table_list)]
+    # table alias for destination table
+    table_alias_list.append((getTableAlias(destination_table, group=group), destination_table))
+
+    # map aliases to use in ZSQLMethod.
+    table_alias_dict = dict(('table_%s' % (index, ), table_alias[0])
+                            for (index, table_alias) in enumerate(table_alias_list))
+
+    assert len(table_alias_list) == len(table_alias_dict)
+
     rendered_related_key = related_key(
       query_table=column_map.getCatalogTableAlias(),
       src__=1,




More information about the Erp5-report mailing list