605 value = value.replace('&', '&').replace('<', '<') |
605 value = value.replace('&', '&').replace('<', '<') |
606 self.w(u' <%s>%s</%s>\n' % (attr, value, attr)) |
606 self.w(u' <%s>%s</%s>\n' % (attr, value, attr)) |
607 self.w(u'</%s>\n' % (entity.e_schema)) |
607 self.w(u'</%s>\n' % (entity.e_schema)) |
608 |
608 |
609 |
609 |
|
610 |
|
611 class XMLRsetView(AnyRsetView): |
|
612 """dumps xml in CSV""" |
|
613 id = 'rsetxml' |
|
614 title = _('xml export') |
|
615 templatable = False |
|
616 content_type = 'text/xml' |
|
617 xml_root = 'rset' |
|
618 |
|
619 def call(self): |
|
620 w = self.w |
|
621 descr = self.rset.description |
|
622 labels = self.columns_labels() |
|
623 w(u'<?xml version="1.0" encoding="%s"?>\n' % self.req.encoding) |
|
624 w(u'<%s>\n' % self.xml_root) |
|
625 for rowindex, row in enumerate(self.rset): |
|
626 w(u' <row>\n') |
|
627 for colindex, val in enumerate(row): |
|
628 content = self.display_value(descr[rowindex][colindex], val) |
|
629 tag = labels[colindex] |
|
630 w(u' <%s>%s<%s>\n' % (tag, content, tag) |
|
631 writer.writerow(csvrow) |
|
632 w(u' </row>\n') |
|
633 w(u'</%s>\n' % self.xml_root) |
|
634 |
|
635 |
610 class RssView(XmlView): |
636 class RssView(XmlView): |
611 id = 'rss' |
637 id = 'rss' |
612 title = _('rss') |
638 title = _('rss') |
613 templatable = False |
639 templatable = False |
614 content_type = 'text/xml' |
640 content_type = 'text/xml' |
695 id = 'csvexport' |
721 id = 'csvexport' |
696 title = _('csv export') |
722 title = _('csv export') |
697 |
723 |
698 def call(self): |
724 def call(self): |
699 writer = self.csvwriter() |
725 writer = self.csvwriter() |
700 writer.writerow(self.get_headers_labels()) |
726 writer.writerow(self.columns_labels()) |
701 descr = self.rset.description |
727 descr = self.rset.description |
702 for rowindex, row in enumerate(self.rset): |
728 for rowindex, row in enumerate(self.rset): |
703 csvrow = [] |
729 csvrow = [] |
704 for colindex, val in enumerate(row): |
730 for colindex, val in enumerate(row): |
705 etype = descr[rowindex][colindex] |
731 content = self.display_value(descr[rowindex][colindex], val) |
706 if val is not None and not self.schema.eschema(etype).is_final(): |
|
707 # csvrow.append(val) # val is eid in that case |
|
708 content = self.view('textincontext', self.rset, |
|
709 row=rowindex, col=colindex) |
|
710 else: |
|
711 content = self.view('final', self.rset, displaytime=True, |
|
712 row=rowindex, col=colindex) |
|
713 csvrow.append(content) |
732 csvrow.append(content) |
714 writer.writerow(csvrow) |
733 writer.writerow(csvrow) |
715 |
734 |
716 def get_headers_labels(self): |
|
717 rqlstdescr = self.rset.syntax_tree().get_description()[0] # XXX missing Union support |
|
718 labels = [] |
|
719 for colindex, attr in enumerate(rqlstdescr): |
|
720 # compute column header |
|
721 if colindex == 0 or attr == 'Any': # find a better label |
|
722 label = ','.join(display_name(self.req, et) |
|
723 for et in self.rset.column_types(colindex)) |
|
724 else: |
|
725 label = display_name(self.req, attr) |
|
726 labels.append(label) |
|
727 return labels |
|
728 |
|
729 |
735 |
730 class CSVEntityView(CSVMixIn, EntityView): |
736 class CSVEntityView(CSVMixIn, EntityView): |
731 """dumps rset's entities (with full set of attributes) in CSV""" |
737 """dumps rset's entities (with full set of attributes) in CSV""" |
732 id = 'ecsvexport' |
738 id = 'ecsvexport' |
733 title = _('csv entities export') |
739 title = _('csv entities export') |