예제 #1
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
예제 #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, format, req, data):
        book = get_workbook_writer(self.env, req)
        writer = book.create_sheet(dgettext('messages', 'Report'))

        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.move_row()

            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 = book.dumps()
        req.send_response(200)
        req.send_header('Content-Type', book.mimetype)
        req.send_header('Content-Length', len(content))
        req.send_header('Content-Disposition',
                        'filename=report_%s.%s' % (req.args['id'], format))
        req.end_headers()
        req.write(content)
        raise RequestDone
예제 #4
0
 def write_headers(writer, query):
     writer.write_row([
         (u'%s (%s)' % (dgettext('messages', 'Custom Query'),
                        dngettext('messages', '%(num)s match',
                                  '%(num)s matches', query.num_items)),
          'header', -1, -1)
     ])
예제 #5
0
    def _create_sheet_query(self, req, context, data, book):
        def write_headers(writer, query):
            writer.write_row([
                (u'%s (%s)' % (dgettext('messages', 'Custom Query'),
                               dngettext('messages', '%(num)s match',
                                         '%(num)s matches', query.num_items)),
                 'header', -1, -1)
            ])

        query = data['query']
        groups = data['groups']
        fields = data['fields']
        headers = data['headers']

        sheet_count = 1
        sheet_name = dgettext("messages", "Custom Query")
        writer = book.create_sheet(sheet_name)
        write_headers(writer, query)

        for groupname, results in groups:
            results = [
                result for result in results if 'TICKET_VIEW' in req.perm(
                    context('ticket', result['id']).resource)
            ]
            if not results:
                continue

            if writer.row_idx + len(results) + 3 > writer.MAX_ROWS:
                sheet_count += 1
                writer = book.create_sheet('%s (%d)' %
                                           (sheet_name, sheet_count))
                write_headers(writer, query)

            if groupname:
                writer.move_row()
                cell = fields[query.group]['label'] + ' '
                if query.group in ('owner', 'reporter'):
                    cell += Chrome(self.env).format_author(req, groupname)
                else:
                    cell += groupname
                cell += ' (%s)' % dngettext('messages', '%(num)s match',
                                            '%(num)s matches', len(results))
                writer.write_row([(cell, 'header2', -1, -1)])

            writer.write_row((header['label'], 'thead', None, None)
                             for idx, header in enumerate(headers))

            for result in results:
                ticket_context = context('ticket', result['id'])
                cells = []
                for idx, header in enumerate(headers):
                    name = header['name']
                    value, style, width, line = self._get_cell_data(
                        name, result.get(name), req, ticket_context, writer)
                    cells.append((value, style, width, line))
                writer.write_row(cells)

        writer.set_col_widths()
예제 #6
0
    def _create_sheet_query(self, req, context, data, book):
        sheet = book.add_sheet(dgettext('messages', 'Custom Query'))
        writer = WorksheetWriter(sheet, req)
        query = data['query']
        groups = data['groups']
        fields = data['fields']
        headers = data['headers']

        writer.write_row([(
            u'%s (%s)' % (dgettext('messages', 'Custom Query'),
                          dngettext('messages', '%(num)s match',
                                    '%(num)s matches', query.num_items)),
            'header', -1, -1)])
        for groupname, results in groups:
            if groupname:
                cell = fields[query.group]['label'] + ' '
                if query.group in ('owner', 'reporter'):
                    cell += Chrome(self.env).format_author(req, groupname)
                else:
                    cell += groupname
                cell += ' (%s)' % dngettext('messages', '%(num)s match',
                                            '%(num)s matches', len(results))
                writer.write_row([(cell, 'header2', -1, -1)])

            writer.write_row(
                (header['label'], 'thead', None, None)
                for idx, header in enumerate(headers))

            for result in results:
                ticket_context = context('ticket', result['id'])
                if 'TICKET_VIEW' not in req.perm(ticket_context.resource):
                    continue
                cells = []
                for idx, header in enumerate(headers):
                    name = header['name']
                    value, style, width, line = self._get_cell_data(
                        name, result.get(name), req, ticket_context, writer)
                    cells.append((value, style, width, line))
                writer.write_row(cells)
            writer.row_idx += 1    # blank row

        writer.set_col_widths()
예제 #7
0
    def _create_sheet_query(self, req, context, data, book):
        sheet = book.add_sheet(dgettext('messages', 'Custom Query'))
        writer = WorksheetWriter(sheet, req)
        query = data['query']
        groups = data['groups']
        fields = data['fields']
        headers = data['headers']

        writer.write_row([
            (u'%s (%s)' % (dgettext('messages', 'Custom Query'),
                           dngettext('messages', '%(num)s match',
                                     '%(num)s matches', query.num_items)),
             'header', -1, -1)
        ])
        for groupname, results in groups:
            if groupname:
                cell = fields[query.group]['label'] + ' '
                if query.group in ('owner', 'reporter'):
                    cell += Chrome(self.env).format_author(req, groupname)
                else:
                    cell += groupname
                cell += ' (%s)' % dngettext('messages', '%(num)s match',
                                            '%(num)s matches', len(results))
                writer.write_row([(cell, 'header2', -1, -1)])

            writer.write_row((header['label'], 'thead', None, None)
                             for idx, header in enumerate(headers))

            for result in results:
                ticket_context = context('ticket', result['id'])
                if 'TICKET_VIEW' not in req.perm(ticket_context.resource):
                    continue
                cells = []
                for idx, header in enumerate(headers):
                    name = header['name']
                    value, style, width, line = self._get_cell_data(
                        name, result.get(name), req, ticket_context, writer)
                    cells.append((value, style, width, line))
                writer.write_row(cells)
            writer.row_idx += 1  # blank row

        writer.set_col_widths()