fix rset xml view
authorSylvain Thenault <sylvain.thenault@logilab.fr>
Thu, 08 Jan 2009 12:55:41 +0100
changeset 370 7e76f651314b
parent 369 c8a6edc224bb
child 371 4e849b424aaa
fix rset xml view
common/view.py
web/views/baseviews.py
--- a/common/view.py	Thu Jan 08 12:39:46 2009 +0100
+++ b/common/view.py	Thu Jan 08 12:55:41 2009 +0100
@@ -383,25 +383,21 @@
     __selectors__ = (nonempty_rset,)
     
     category = 'anyrsetview'
-
-    def display_value(self, etype, val):
-        if val is not None and not self.schema.eschema(etype).is_final():
-            # csvrow.append(val) # val is eid in that case
-            return self.view('textincontext', self.rset, 
-                             row=rowindex, col=colindex)
-        return self.view('final', self.rset, displaytime=True,
-                         row=rowindex, col=colindex)
     
-    def columns_labels(self):
+    def columns_labels(self, tr=True):
+        if tr:
+            translate = display_name
+        else:
+            translate = lambda req, val: val
         rqlstdescr = self.rset.syntax_tree().get_description()[0] # XXX missing Union support
         labels = []
         for colindex, attr in enumerate(rqlstdescr):
             # compute column header
             if colindex == 0 or attr == 'Any': # find a better label
-                label = ','.join(display_name(self.req, et)
+                label = ','.join(translate(self.req, et)
                                  for et in self.rset.column_types(colindex))
             else:
-                label = display_name(self.req, attr)
+                label = translate(self.req, attr)
             labels.append(label)
         return labels
     
--- a/web/views/baseviews.py	Thu Jan 08 12:39:46 2009 +0100
+++ b/web/views/baseviews.py	Thu Jan 08 12:55:41 2009 +0100
@@ -618,17 +618,25 @@
         
     def call(self):
         w = self.w
-        descr = self.rset.description
-        labels = self.columns_labels()
+        rset, descr = self.rset, self.rset.description
+        eschema = self.schema.eschema
+        labels = self.columns_labels(False)
         w(u'<?xml version="1.0" encoding="%s"?>\n' % self.req.encoding)
         w(u'<%s>\n' % self.xml_root)
         for rowindex, row in enumerate(self.rset):
             w(u' <row>\n')
             for colindex, val in enumerate(row):
-                content = self.display_value(descr[rowindex][colindex], val)
+                etype = descr[rowindex][colindex]
                 tag = labels[colindex]
-                w(u' <%s>%s<%s>\n' % (tag, content, tag)
-            writer.writerow(csvrow)
+                if val is not None and not eschema(etype).is_final():
+                    # csvrow.append(val) # val is eid in that case
+                    content = self.view('textincontext', rset, 
+                                        row=rowindex, col=colindex)
+                    w(u'  <%s eid="%s">%s</%s>\n' % (tag, val, html_escape(content), tag))
+                else:
+                    content = self.view('final', rset, displaytime=True,
+                                        row=rowindex, col=colindex)
+                    w(u'  <%s>%s</%s>\n' % (tag, html_escape(content), tag))
             w(u' </row>\n')
         w(u'</%s>\n' % self.xml_root)
     
@@ -724,11 +732,19 @@
     def call(self):
         writer = self.csvwriter()
         writer.writerow(self.columns_labels())
-        descr = self.rset.description
-        for rowindex, row in enumerate(self.rset):
+        rset, descr = self.rset, self.rset.description
+        eschema = self.schema.eschema
+        for rowindex, row in enumerate(rset):
             csvrow = []
             for colindex, val in enumerate(row):
-                content = self.display_value(descr[rowindex][colindex], val)
+                etype = descr[rowindex][colindex]
+                if val is not None and not eschema(etype).is_final():
+                    # csvrow.append(val) # val is eid in that case
+                    content = self.view('textincontext', rset, 
+                                        row=rowindex, col=colindex)
+                else:
+                    content = self.view('final', rset, displaytime=True,
+                                        row=rowindex, col=colindex)
                 csvrow.append(content)                    
             writer.writerow(csvrow)