Esempio n. 1
0
    def show(self, view: "View", rows: Rows) -> None:
        csv_separator = request.get_str_input_mandatory("csv_separator", ";")
        first = True
        resp = []
        for cell in view.group_cells + view.row_cells:
            if first:
                first = False
            else:
                resp.append(csv_separator)
            title = cell.export_title()
            resp.append('"%s"' % self._format_for_csv(title))

        for row in rows:
            resp.append("\n")
            first = True
            for cell in view.group_cells + view.row_cells:
                if first:
                    first = False
                else:
                    resp.append(csv_separator)
                joined_row = join_row(row, cell)
                content = cell.render_for_export(joined_row)
                resp.append('"%s"' % self._format_for_csv(content))

        response.set_data("".join(resp))
Esempio n. 2
0
    def render(self, rows, view, group_cells, cells, num_columns,
               show_checkboxes):
        painted_rows = []

        header_row = []
        for cell in cells:
            header_row.append(escaping.strip_tags(cell.export_title()))
        painted_rows.append(header_row)

        for row in rows:
            painted_row = []
            for cell in cells:
                joined_row = join_row(row, cell)
                content = cell.render_for_export(joined_row)
                if isinstance(content, (list, dict)):
                    # Allow painters to return lists and dicts, then json encode them
                    # as such data structures without wrapping them into strings
                    pass

                else:
                    content = "%s" % content
                    content = escaping.strip_tags(content.replace(
                        "<br>", "\n"))

                painted_row.append(content)

            painted_rows.append(painted_row)

        html.write(json.dumps(painted_rows, indent=True))
Esempio n. 3
0
def _get_json_body(view: "View", rows: Rows) -> str:
    painted_rows: List[List] = []

    header_row = []
    for cell in view.row_cells:
        header_row.append(escaping.strip_tags(cell.export_title()))
    painted_rows.append(header_row)

    for row in rows:
        painted_row: List[Union[str, Dict]] = []
        for cell in view.row_cells:
            joined_row = join_row(row, cell)
            content = cell.render_for_export(joined_row)
            if isinstance(content, dict):
                # Allow painters to return lists and dicts, then json encode them
                # as such data structures without wrapping them into strings
                pass

            else:
                content = escaping.strip_tags(content.replace("<br>", "\n"))

            painted_row.append(content)

        painted_rows.append(painted_row)

    return json.dumps(painted_rows, indent=True)
Esempio n. 4
0
def _show_json(view: "View", rows: Rows) -> None:
    painted_rows = []

    header_row = []
    for cell in view.row_cells:
        header_row.append(escaping.strip_tags(cell.export_title()))
    painted_rows.append(header_row)

    for row in rows:
        painted_row = []
        for cell in view.row_cells:
            joined_row = join_row(row, cell)
            content = cell.render_for_export(joined_row)
            if isinstance(content, (list, dict)):
                # Allow painters to return lists and dicts, then json encode them
                # as such data structures without wrapping them into strings
                pass

            else:
                content = escaping.strip_tags(
                    str(content).replace("<br>", "\n"))

            painted_row.append(content)

        painted_rows.append(painted_row)

    html.write(json.dumps(painted_rows, indent=True))
Esempio n. 5
0
 def render(self, rows, view, group_cells, cells, num_columns,
            show_checkboxes):
     html.write_text("[\n")
     html.write(repr([cell.export_title() for cell in cells]))
     html.write_text(",\n")
     for row in rows:
         html.write_text("[")
         for cell in cells:
             joined_row = join_row(row, cell)
             _tdclass, content = cell.render_content(joined_row)
             html.write(repr(html.strip_tags(content)))
             html.write_text(",")
         html.write_text("],")
     html.write_text("\n]\n")
Esempio n. 6
0
def _export_python(view: "View", rows: Rows) -> None:
    html.write_text("[\n")
    html.write(repr([cell.export_title() for cell in view.row_cells]))
    html.write_text(",\n")
    for row in rows:
        html.write_text("[")
        for cell in view.row_cells:
            joined_row = join_row(row, cell)
            content = cell.render_for_export(joined_row)

            # The aggr_treestate painters are returning a dictionary data structure (see
            # paint_aggregated_tree_state()) in case the output_format is not HTML. Only
            # remove the HTML tags from the top level strings produced by painters.
            if isinstance(content, (HTML, str)):
                content = escaping.strip_tags(content)

            html.write(repr(content))
            html.write_text(",")
        html.write_text("],")
    html.write_text("\n]\n")
Esempio n. 7
0
    def render(self, rows, view, group_cells, cells, num_columns,
               show_checkboxes):
        html.write_text("[\n")
        html.write(repr([cell.export_title() for cell in cells]))
        html.write_text(",\n")
        for row in rows:
            html.write_text("[")
            for cell in cells:
                joined_row = join_row(row, cell)
                content = cell.render_for_export(joined_row)

                # The aggr_treestate painters are returning a dictionary data structure (see
                # paint_aggregated_tree_state()) in case the output_format is not HTML. Only
                # remove the HTML tags from the top level strings produced by painters.
                if isinstance(content, (HTML, six.string_types)):
                    content = escaping.strip_tags(content)

                html.write(repr(content))
                html.write_text(",")
            html.write_text("],")
        html.write_text("\n]\n")
Esempio n. 8
0
    def show(self, view: "View", rows: Rows) -> None:
        csv_separator = html.request.get_str_input_mandatory("csv_separator", ";")
        first = True
        for cell in view.group_cells + view.row_cells:
            if first:
                first = False
            else:
                html.write(csv_separator)
            content = cell.export_title()
            html.write('"%s"' % self._format_for_csv(content))

        for row in rows:
            html.write_text("\n")
            first = True
            for cell in view.group_cells + view.row_cells:
                if first:
                    first = False
                else:
                    html.write(csv_separator)
                joined_row = join_row(row, cell)
                content = cell.render_for_export(joined_row)
                html.write('"%s"' % self._format_for_csv(content))
Esempio n. 9
0
    def render(self, rows, view, group_cells, cells, num_columns,
               show_checkboxes):
        csv_separator = html.request.var("csv_separator", ";")
        first = True
        for cell in group_cells + cells:
            if first:
                first = False
            else:
                html.write(csv_separator)
            content = cell.export_title()
            html.write('"%s"' % self._format_for_csv(content))

        for row in rows:
            html.write_text("\n")
            first = True
            for cell in group_cells + cells:
                if first:
                    first = False
                else:
                    html.write(csv_separator)
                joined_row = join_row(row, cell)
                _tdclass, content = cell.render_content(joined_row)
                html.write('"%s"' % self._format_for_csv(content))