Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #910 (closed enhancement: fixed)

Opened 13 years ago

Last modified 12 years ago

[PATCH] Fix CatWalk to handle SQLMultipleJoin / SQLRelatedJoin

Reported by: jacob@… Owned by: alberto
Priority: high Milestone: 1.0.1
Component: Toolbox.Catwalk Version: 1.0
Severity: normal Keywords:
Cc:

Description

When I replace an SQLObject RelatedJoin? or MultipleJoin? with an SQLRelatedJoin or SQLMultipleJoin, CatWalk doesn't give a grid on the detailed browse page. Instead, it just shows raw SQL, presumably that which would be executed to get the list of joined objects.

Shouldn't be too hard to fix, no?

Attachments

catwalk-sqljoins.patch Download (6.2 KB) - added by Chris Arndt 12 years ago.
catwalk-sqljoins-20070115.patch Download (6.2 KB) - added by Chris Arndt 12 years ago.

Change History

comment:1 Changed 13 years ago by jorge.vargas

  • Type changed from defect to enhancement
  • Severity changed from major to normal
  • Milestone changed from 0.9 to 1.0b1

in fact is just adding some code. All you need to do is

in turbogears/toolbox/catwalk/init.py

under def object_field(self,row,column):

add 2 more if with the SQL*Join and then add the proper methods below.

I have never use the SQL*Join cols so I don't know how to implement it. do you?

patches welcome :)

comment:2 Changed 13 years ago by jorge.vargas

  • Component changed from TurboGears to Toolbox

comment:3 Changed 13 years ago by jorge.vargas

  • Milestone changed from 1.0b1 to 1.0b4

comment:4 Changed 12 years ago by Chris Arndt

  • Version changed from 0.9a6 to trunk
  • Summary changed from CatWalk doesn't handle SQLMultipleJoin / SQLRelatedJoin to [PATCH] Fix CatWalk to handle SQLMultipleJoin / SQLRelatedJoin

The attached patch should add handling of SQLMultipleJoin / SQLRelatedJoin in CatWalk

I am not 100% sure, if I found all the places where a change is necessary but it seems to work for me. I have no test cases, since it is hard to test the JavsScript? stuff.

Diff against trunk r2339 (but the catwalk directoy seems to be in sync with branches/1.0 since r1903).

I can't actually attach the patch ATM, because I get a 500 HTTP error. I'll attach the diff after this is fixed.

comment:5 Changed 12 years ago by Chris Arndt

  • Component changed from Toolbox to Toolbox.Catwalk
  • Milestone changed from 1.0b4 to 1.0

Since I still can't upload the patch, I'll just paste it here:

Index: __init__.py
===================================================================
--- __init__.py	(Revision 2339)
+++ __init__.py	(Arbeitskopie)
@@ -172,9 +172,9 @@
             except:
                 return {'column':column['columnName'],'value':'None','id':'0'}
             return {'column':column['columnName'],'value':value }
-        elif column.get('type','') == 'SORelatedJoin':
+        elif column.get('type','') in ('SORelatedJoin', 'SOSQLRelatedJoin'):
             return self.related_join_count(row,column)
-        elif column.get('type','') == 'SOMultipleJoin':
+        elif column.get('type','') in ('SOMultipleJoin', 'SOSQLMultipleJoin'):
             return self.multiple_join_count(row,column)
         elif column.get('type','') == 'SOForeignKey':
             return self.object_field_for_foreign_key(row,column)
@@ -208,7 +208,7 @@
     def related_join_count(self,row,column):
         """Return the total number of related objects"""
         try:
-            value='%s'% len(getattr(row,column['joinMethodName']))
+            value='%s'% len(list(getattr(row,column['joinMethodName'])))
         except:
             value='0'
         return { 'column':column['joinMethodName'], 'value':value }
@@ -405,7 +405,7 @@
         hostObject = objectName
         obj = self.load_object(objectName)
         try:
-            rows = getattr(obj.get(id),join)
+            rows = list(getattr(obj.get(id),join))
         except:
             msg='Error, joins objectName: %s, id: %s, join: %s'% (objectName,id,join)
             raise cherrypy.HTTPRedirect(turbogears.url('error', msg=msg))
@@ -487,7 +487,8 @@

         if props['type'] == 'SOEnumCol':
             props['options'] = column.enumValues
-        if props['type'] in ('SOMultipleJoin','SORelatedJoin'):
+        if props['type'] in ('SOMultipleJoin', 'SOSQLMultipleJoin',
+          'SORelatedJoin', 'SOSQLRelatedJoin'):
             props['join'] = column.otherClassName
             props['joinMethodName'] = column.joinMethodName
         if props['type'] == 'SOSingleJoin':
@@ -847,6 +848,7 @@
            @type relatedObjectName: string
         """
         joins = self.object_joins(objectName,id,join,'SORelatedJoin',relatedObjectName)
+
         joins['allJoins'] = self.object_instances(relatedObjectName)
         return joins
     manageRelatedJoins = turbogears.expose(format="json")(manageRelatedJoins)
@@ -963,10 +965,11 @@
             colForID=col.copy()
             colForID['type']=''
             col['object_id']=id
-            if col['type'] in ('SOMultipleJoin','SORelatedJoin'):
+            if col['type'] in ('SOMultipleJoin', 'SOSQLMultipleJoin',
+              'SORelatedJoin', 'SOSQLRelatedJoin'):
                 col['id'] = id
                 try:
-                    value = '%s'% len(getattr(inst,col['columnName']))
+                    value = '%s'% len(list(getattr(inst,col['columnName'])))
                 except:
                     value = '0'
                 col['value'] = {'value':value, 'column':col['columnName']}
Index: static/javascript/catwalk.js
===================================================================
--- static/javascript/catwalk.js	(Revision 2339)
+++ static/javascript/catwalk.js	(Arbeitskopie)
@@ -215,7 +215,7 @@
                   )
                 );
   }
-  if(col.type=='SOMultipleJoin')
+  if(col.type=='SOMultipleJoin' || col.type=='SOSQLMultipleJoin')
   {
     fieldType = TD({'class':'coltype'},
                    SPAN(null,col.type +':'),
@@ -861,7 +861,8 @@

   var grid = (results['rows'].length >0)? Widget.grid.render(results['join'],data):'';
   var r = results;
-  if(results['joinType']=='SORelatedJoin')
+  if(results['joinType']=='SORelatedJoin' ||
+    results['joinType']=='SOSQLRelatedJoin')
   {
     grid = DIV(null,grid,catwalk.renderManageRelatedControl(r['hostObject'],r['id'],r['join'],r['joinObjectName']));
   }
@@ -937,7 +938,8 @@
                                            [column.objectName,column.object_id,column.join,column.id.value]) );
     }
   }
-  if(column.type=='SOMultipleJoin' || column.type=='SORelatedJoin' )
+  if(column.type=='SOMultipleJoin' || column.type=='SOSQLMultipleJoin' ||
+    column.type=='SORelatedJoin' || column.type=='SOSQLRelatedJoin')
   {
     var edit = '';
     var action = Widget.renderHandler('javascript:catwalk.retrieveJoins',
Index: browse.py
===================================================================
--- browse.py	(Revision 2339)
+++ browse.py	(Arbeitskopie)
@@ -135,7 +135,8 @@
         conn = obj._connection
         for column in obj.sqlmeta.joins:
             query = None
-            if 'SOMultipleJoin' in '%r'% type(column):
+            coltype = self.get_column_type(column)
+            if coltype in ('SOMultipleJoin', 'SOSQLMultipleJoin'):
                 query = conn.sqlrepr( Select( [
                                          column.soClass.q.id,
                                          func.Count(column.otherClass.q.id)
@@ -144,8 +145,8 @@
                                                     column.soClass.q.id==self.join_foreign_key(column),
                                                     IN(column.soClass.q.id,ids)
                                                 ), groupBy=column.soClass.q.id))
-            if 'SORelatedJoin' in '%r'% type(column):

+            elif coltype in ('SORelatedJoin', 'SOSQLRelatedJoin'):
                 d = (column.intermediateTable,
                      column.joinColumn,
                      column.intermediateTable,
@@ -159,8 +160,7 @@

                 query = "SELECT %s.%s, Count(%s.%s) FROM %s WHERE %s.%s IN(%s) GROUP BY %s.%s" % d

-
-            if 'SOSingleJoin' in '%r'% type(column):
+            elif coltype == 'SOSingleJoin':
                 alias = self.load_label_column_for_object(column.otherClassName)
                 query = conn.sqlrepr( Select( [ column.soClass.q.id,getattr(column.otherClass.q,alias)],
                                                 where=AND(

comment:6 Changed 12 years ago by alberto

  • Status changed from new to assigned
  • Owner changed from anonymous to alberto
  • Version changed from trunk to 1.0
  • Milestone changed from 1.0 to 1.0.1

comment:7 Changed 12 years ago by alberto

  • Summary changed from [PATCH] Fix CatWalk to handle SQLMultipleJoin / SQLRelatedJoin to Fix CatWalk to handle SQLMultipleJoin / SQLRelatedJoin

Chris, can you please update the patch? It doesn't apply cleanly neither to trunk or 1.0:

(Turbogears)jal:~/src/python/checkouts/turbogears/turbogears/toolbox/catwalk alberto$ patch -p0 < ~/Desktop/catwalk-sqljoins.patch 
patching file __init__.py
Hunk #1 FAILED at 172.
Hunk #4 succeeded at 487 with fuzz 2.
1 out of 6 hunks FAILED -- saving rejects to file __init__.py.rej
patching file static/javascript/catwalk.js
patching file browse.py
Hunk #3 FAILED at 160.
1 out of 3 hunks FAILED -- saving rejects to file browse.py.rej

browse.py.rej looks like this:

***************
*** 159,166 ****

                  query = "SELECT %s.%s, Count(%s.%s) FROM %s WHERE %s.%s IN(%s) GROUP BY %s.%s" % d

- 
-             if 'SOSingleJoin' in '%r'% type(column):
                  alias = self.load_label_column_for_object(column.otherClassName)
                  query = conn.sqlrepr( Select( [ column.soClass.q.id,getattr(column.otherClass.q,alias)],
                                                  where=AND(
--- 160,166 ----

                  query = "SELECT %s.%s, Count(%s.%s) FROM %s WHERE %s.%s IN(%s) GROUP BY %s.%s" % d

+             elif coltype == 'SOSingleJoin':
                  alias = self.load_label_column_for_object(column.otherClassName)
                  query = conn.sqlrepr( Select( [ column.soClass.q.id,getattr(column.otherClass.q,alias)],
                                                  where=AND(

Removing [PATCH] for the meantime

Thanks :)

BTW, please run "svn diff > patch" from the root of your turbogears checkout so I don't have to chase which are the affected dirs... :) Thanks

Changed 12 years ago by Chris Arndt

comment:8 Changed 12 years ago by Chris Arndt

  • Summary changed from Fix CatWalk to handle SQLMultipleJoin / SQLRelatedJoin to [PATCH] Fix CatWalk to handle SQLMultipleJoin / SQLRelatedJoin

Updated patch according to guidelines posted on ML

comment:9 Changed 12 years ago by alberto

I can't believe this!... Seems today is not a good day for patching TG... I'm getting the same error I mention at #1235. Can you try uploading it with a different name?

Sorry :(

Alberto

Changed 12 years ago by Chris Arndt

comment:10 Changed 12 years ago by alberto

  • Status changed from assigned to closed
  • Resolution set to fixed

Comitted at [2382]. Thanks Chris! :)

Alberto

Note: See TracTickets for help on using tickets.