merge
authorEmile Anclin <emile.anclin@logilab.fr>
Wed, 11 Feb 2009 14:21:55 +0100
changeset 577 b5b32e6d496c
parent 576 b9803ed2e31d (current diff)
parent 573 9c8fd72ba6c1 (diff)
child 578 86628c564144
merge
goa/test/data/bootstrap_packages
--- a/goa/test/unittest_editcontroller.py	Wed Feb 11 14:21:17 2009 +0100
+++ b/goa/test/unittest_editcontroller.py	Wed Feb 11 14:21:55 2009 +0100
@@ -17,7 +17,7 @@
     config.global_set_option('use-google-auth', False)
     config.global_set_option('schema-type', 'yams')
     config.global_set_option('included-cubes', ())
-    config.global_set_option('included-yams-cubes', ('eblog',))
+    config.global_set_option('included-yams-cubes', ('blog',))
     
     MODEL_CLASSES = ()
     from cubicweb.web.views import editcontroller
--- a/rset.py	Wed Feb 11 14:21:17 2009 +0100
+++ b/rset.py	Wed Feb 11 14:21:55 2009 +0100
@@ -464,7 +464,8 @@
         rqlst = self.syntax_tree()
         etype = self.description[row][col]
         if self.vreg.schema.eschema(etype).is_final():
-            # final type, find a better (ambiguous) one
+            # final type, find a better one to locate the correct subquery
+            # (ambiguous if possible) 
             for i in xrange(len(rqlst.children[0].selection)):
                 if i == col:
                     continue
@@ -476,18 +477,17 @@
                     locate_query_col = i
                     if len(self.column_types(i)) > 1:
                         break
-        # UNION query, find the subquery from which this entity has been
-        # found
+        # UNION query, find the subquery from which this entity has been found
         select = rqlst.locate_subquery(locate_query_col, etype, self.args)
         try:
             myvar = select.selection[col].variable
         except AttributeError:
-            # no .selection attribute is available
+            # not a variable
             return None, None
         rel = myvar.main_relation()
         if rel is not None:
             index = rel.children[0].variable.selected_index()
-            if index is not None:
+            if index is not None and self.rows[row][index]:
                 return self.get_entity(row, index), rel.r_type
         return None, None
 
--- a/test/unittest_rset.py	Wed Feb 11 14:21:17 2009 +0100
+++ b/test/unittest_rset.py	Wed Feb 11 14:21:55 2009 +0100
@@ -300,7 +300,13 @@
             attr = etype == 'Bookmark' and 'title' or 'name'
             self.assertEquals(entity[attr], n)
         
-    
+    def test_related_entity_optional(self):
+        e = self.add_entity('Bookmark', title=u'aaaa', path=u'path')
+        rset = self.execute('Any B,U,L WHERE B bookmarked_by U?, U login L')
+        entity, rtype = rset.related_entity(0, 2)
+        self.assertEquals(entity, None)
+        self.assertEquals(rtype, None)
+        
     def test_related_entity_union_subquery(self):
         e = self.add_entity('Bookmark', title=u'aaaa', path=u'path')
         rset = self.execute('Any X,N ORDERBY N WITH X,N BEING '
--- a/web/views/baseviews.py	Wed Feb 11 14:21:17 2009 +0100
+++ b/web/views/baseviews.py	Wed Feb 11 14:21:55 2009 +0100
@@ -57,14 +57,14 @@
     """
     id = 'final'
             
-    def cell_call(self, row, col, props=None, displaytime=False):
+    def cell_call(self, row, col, props=None, displaytime=False, format='text/html'):
         etype = self.rset.description[row][col]
         value = self.rset.rows[row][col]
         if etype == 'String':
             entity, rtype = self.rset.related_entity(row, col)
             if entity is not None:
                 # yes !
-                self.w(entity.printable_value(rtype, value))
+                self.w(entity.printable_value(rtype, value, format=format))
                 return
         if etype in ('Time', 'Interval'):
             _ = self.req._
@@ -639,7 +639,7 @@
                                     row=rowindex, col=colindex)
                 else:
                     val = self.view('final', rset, displaytime=True,
-                                    row=rowindex, col=colindex)
+                                    row=rowindex, col=colindex, format='text/plain')
                 w(simple_sgml_tag(tag, val, **attrs))
             w(u' </row>\n')
         w(u'</%s>\n' % self.xml_root)
@@ -747,7 +747,8 @@
                     content = self.view('textincontext', rset, 
                                         row=rowindex, col=colindex)
                 else:
-                    content = self.view('final', rset, displaytime=True,
+                    content = self.view('final', rset,
+                                        displaytime=True, format='text/plain',
                                         row=rowindex, col=colindex)
                 csvrow.append(content)                    
             writer.writerow(csvrow)