Пример #1
0
    def _convert_query(self, req, query, sheet_query=True,
                       sheet_history=False):
        # no paginator
        query.max = 0
        query.has_more_pages = False
        query.offset = 0

        # extract all fields except custom fields
        cols = ['id']
        cols.extend(f['name'] for f in query.fields if not f.get('custom'))
        cols.extend(name for name in ('time', 'changetime')
                         if name not in cols)
        query.cols = cols

        if hasattr(self.env, 'get_read_db'):
            db = self.env.get_read_db()
        else:
            db = self.env.get_db_cnx()
        tickets = query.execute(req, db)
        # add custom fields to avoid error to join many tables
        custom_fields = [f['name'] for f in query.fields if f.get('custom')]
        self._fill_custom_fields(tickets, custom_fields, db)

        context = Context.from_request(req, 'query', absurls=True)
        cols.extend([name for name in custom_fields if name not in cols])
        data = query.template_data(context, tickets)

        book = Workbook(encoding='utf-8', style_compression=1)
        if sheet_query:
            self._create_sheet_query(req, context, data, book)
        if sheet_history:
            self._create_sheet_history(req, context, data, book)
        return get_workbook_content(book), 'application/vnd.ms-excel'
Пример #2
0
    def _convert_report(self, req, data):
        book = Workbook(encoding='utf-8', style_compression=1)
        sheet = book.add_sheet(dgettext('messages', 'Report'))
        writer = WorksheetWriter(sheet, req)

        writer.write_row([
            ('%s (%s)' % (data['title'],
                          dngettext('messages', '%(num)s match',
                                    '%(num)s matches', data['numrows'])),
             'header', -1, -1)
        ])

        for value_for_group, row_group in data['row_groups']:
            writer.row_idx += 1

            if value_for_group and len(row_group):
                writer.write_row([
                    ('%s (%s)' %
                     (value_for_group,
                      dngettext('messages', '%(num)s match', '%(num)s matches',
                                len(row_group))), 'header2', -1, -1)
                ])
            for header_group in data['header_groups']:
                writer.write_row([(header['title'], 'thead', None, None)
                                  for header in header_group
                                  if not header['hidden']])

            for row in row_group:
                for cell_group in row['cell_groups']:
                    cells = []
                    for cell in cell_group:
                        cell_header = cell['header']
                        if cell_header['hidden']:
                            continue
                        col = cell_header['col'].strip('_').lower()
                        value, style, width, line = \
                                self._get_cell_data(req, col, cell, row, writer)
                        cells.append((value, style, width, line))
                    writer.write_row(cells)

        writer.set_col_widths()

        content = get_workbook_content(book)
        req.send_response(200)
        req.send_header('Content-Type', 'application/vnd.ms-excel')
        req.send_header('Content-Length', len(content))
        req.send_header('Content-Disposition',
                        'filename=report_%s.xls' % req.args['id'])
        req.end_headers()
        req.write(content)
        raise RequestDone
Пример #3
0
    def _convert_report(self, req, data):
        book = Workbook(encoding='utf-8', style_compression=1)
        sheet = book.add_sheet(dgettext('messages', 'Report'))
        writer = WorksheetWriter(sheet, req)

        writer.write_row([(
            '%s (%s)' % (data['title'],
                         dngettext('messages', '%(num)s match',
                                   '%(num)s matches', data['numrows'])),
            'header', -1, -1)])

        for value_for_group, row_group in data['row_groups']:
            writer.row_idx += 1

            if value_for_group and len(row_group):
                writer.write_row([(
                    '%s (%s)' % (value_for_group,
                                 dngettext('messages', '%(num)s match',
                                           '%(num)s matches', len(row_group))),
                    'header2', -1, -1)])
            for header_group in data['header_groups']:
                writer.write_row([
                    (header['title'], 'thead', None, None)
                    for header in header_group
                    if not header['hidden']])

            for row in row_group:
                for cell_group in row['cell_groups']:
                    cells = []
                    for cell in cell_group:
                        cell_header = cell['header']
                        if cell_header['hidden']:
                            continue
                        col = cell_header['col'].strip('_').lower()
                        value, style, width, line = \
                                self._get_cell_data(req, col, cell, row, writer)
                        cells.append((value, style, width, line))
                    writer.write_row(cells)

        writer.set_col_widths()

        content = get_workbook_content(book)
        req.send_response(200)
        req.send_header('Content-Type', 'application/vnd.ms-excel')
        req.send_header('Content-Length', len(content))
        req.send_header('Content-Disposition',
                        'filename=report_%s.xls' % req.args['id'])
        req.end_headers()
        req.write(content)
        raise RequestDone
Пример #4
0
    def _convert_query(self,
                       req,
                       query,
                       sheet_query=True,
                       sheet_history=False):
        # no paginator
        query.max = 0
        query.has_more_pages = False
        query.offset = 0

        # extract all fields except custom fields
        cols = ['id']
        cols.extend(f['name'] for f in query.fields if not f.get('custom'))
        cols.extend(name for name in ('time', 'changetime')
                    if name not in cols)
        query.cols = cols

        if hasattr(self.env, 'get_read_db'):
            db = self.env.get_read_db()
        else:
            db = self.env.get_db_cnx()
        tickets = query.execute(req, db)
        # add custom fields to avoid error to join many tables
        custom_fields = [f['name'] for f in query.fields if f.get('custom')]
        self._fill_custom_fields(tickets, custom_fields, db)

        context = Context.from_request(req, 'query', absurls=True)
        cols.extend([name for name in custom_fields if name not in cols])
        data = query.template_data(context, tickets)

        book = Workbook(encoding='utf-8', style_compression=1)
        if sheet_query:
            self._create_sheet_query(req, context, data, book)
        if sheet_history:
            self._create_sheet_history(req, context, data, book)
        return get_workbook_content(book), 'application/vnd.ms-excel'