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)
     ])
    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()
Esempio n. 3
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()
Esempio n. 4
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()
Esempio n. 5
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
Esempio n. 6
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
    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
Esempio n. 8
0
    def _create_sheet_history(self, req, context, data, book):
        sheet = book.add_sheet(dgettext("messages", "Change History"))
        writer = WorksheetWriter(sheet, req)

        groups = data['groups']
        headers = [header for header in data['headers']
                   if header['name'] not in ('id', 'time', 'changetime')]
        headers[0:0] = [
            {'name': 'id', 'label': dgettext("messages", "Ticket")},
            {'name': 'time', 'label': dgettext("messages", "Time")},
            {'name': 'author', 'label': dgettext("messages", "Author")},
            {'name': 'comment', 'label': dgettext("messages", "Comment")},
        ]

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

        mod = TicketModule(self.env)
        for result in chain(*[results for groupname, results in groups]):
            id = result['id']
            ticket = Ticket(self.env, id)
            ticket_context = context('ticket', id)
            values = ticket.values.copy()
            changes = []

            for change in mod.rendered_changelog_entries(req, ticket):
                if change['permanent']:
                    changes.append(change)
            for change in reversed(changes):
                change['values'] = values
                values = values.copy()
                for name, field in change['fields'].iteritems():
                    if name in values:
                        values[name] = field['old']
            changes[0:0] = [{'date': ticket.time_created, 'fields': {},
                             'values': values, 'cnum': None,
                             'comment': '', 'author': ticket['reporter']}]

            for change in changes:
                cells = []
                for idx, header in enumerate(headers):
                    name = header['name']
                    if name == 'id':
                        value = id
                    elif name == 'time':
                        value = change.get('date', '')
                    elif name == 'comment':
                        value = change.get('comment', '')
                    elif name == 'author':
                        value = change.get('author', '')
                    else:
                        value = change['values'].get(name, '')
                    value, style, width, line = \
                            self._get_cell_data(name, value, req,
                                                ticket_context, writer)
                    if name in change['fields']:
                        style = '%s:change' % style
                    cells.append((value, style, width, line))
                writer.write_row(cells)

        writer.set_col_widths()
    def _create_sheet_history(self, req, context, data, book):
        def write_headers(writer, headers):
            writer.write_row((header['label'], 'thead', None, None)
                             for idx, header in enumerate(headers))

        groups = data['groups']
        headers = [
            header for header in data['headers']
            if header['name'] not in ('id', 'time', 'changetime')
        ]
        headers[0:0] = [
            {
                'name': 'id',
                'label': dgettext("messages", "Ticket")
            },
            {
                'name': 'time',
                'label': dgettext("messages", "Time")
            },
            {
                'name': 'author',
                'label': dgettext("messages", "Author")
            },
            {
                'name': 'comment',
                'label': dgettext("messages", "Comment")
            },
        ]

        sheet_name = dgettext("messages", "Change History")
        sheet_count = 1
        writer = book.create_sheet(sheet_name)
        write_headers(writer, headers)

        tkt_ids = [
            result['id']
            for result in chain(*[results for groupname, results in groups])
        ]
        tickets = BulkFetchTicket.select(self.env, tkt_ids)

        mod = TicketModule(self.env)
        for result in chain(*[results for groupname, results in groups]):
            id = result['id']
            ticket = tickets[id]
            ticket_context = context('ticket', id)
            if 'TICKET_VIEW' not in req.perm(ticket_context.resource):
                continue
            values = ticket.values.copy()
            changes = []

            for change in mod.grouped_changelog_entries(ticket, None):
                if change['permanent']:
                    changes.append(change)
            for change in reversed(changes):
                change['values'] = values
                values = values.copy()
                for name, field in change['fields'].iteritems():
                    if name in values:
                        values[name] = field['old']
            changes[0:0] = [{
                'date': ticket.time_created,
                'fields': {},
                'values': values,
                'cnum': None,
                'comment': '',
                'author': ticket['reporter']
            }]

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

            for change in changes:
                cells = []
                for idx, header in enumerate(headers):
                    name = header['name']
                    if name == 'id':
                        value = id
                    elif name == 'time':
                        value = change.get('date', '')
                    elif name == 'comment':
                        value = change.get('comment', '')
                    elif name == 'author':
                        value = change.get('author', '')
                        value = Chrome(self.env).format_author(req, value)
                    else:
                        value = change['values'].get(name, '')
                    value, style, width, line = \
                            self._get_cell_data(name, value, req,
                                                ticket_context, writer)
                    if name in change['fields']:
                        style = '%s:change' % style
                    cells.append((value, style, width, line))
                writer.write_row(cells)

        writer.set_col_widths()
Esempio n. 10
0
    def _create_sheet_history(self, req, context, data, book):
        sheet = book.add_sheet(dgettext("messages", "Change History"))
        writer = WorksheetWriter(sheet, req)

        groups = data['groups']
        headers = [
            header for header in data['headers']
            if header['name'] not in ('id', 'time', 'changetime')
        ]
        headers[0:0] = [
            {
                'name': 'id',
                'label': dgettext("messages", "Ticket")
            },
            {
                'name': 'time',
                'label': dgettext("messages", "Time")
            },
            {
                'name': 'author',
                'label': dgettext("messages", "Author")
            },
            {
                'name': 'comment',
                'label': dgettext("messages", "Comment")
            },
        ]

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

        mod = TicketModule(self.env)
        for result in chain(*[results for groupname, results in groups]):
            id = result['id']
            ticket = Ticket(self.env, id)
            ticket_context = context('ticket', id)
            values = ticket.values.copy()
            changes = []

            for change in mod.rendered_changelog_entries(req, ticket):
                if change['permanent']:
                    changes.append(change)
            for change in reversed(changes):
                change['values'] = values
                values = values.copy()
                for name, field in change['fields'].iteritems():
                    if name in values:
                        values[name] = field['old']
            changes[0:0] = [{
                'date': ticket.time_created,
                'fields': {},
                'values': values,
                'cnum': None,
                'comment': '',
                'author': ticket['reporter']
            }]

            for change in changes:
                cells = []
                for idx, header in enumerate(headers):
                    name = header['name']
                    if name == 'id':
                        value = id
                    elif name == 'time':
                        value = change.get('date', '')
                    elif name == 'comment':
                        value = change.get('comment', '')
                    elif name == 'author':
                        value = change.get('author', '')
                    else:
                        value = change['values'].get(name, '')
                    value, style, width, line = \
                            self._get_cell_data(name, value, req,
                                                ticket_context, writer)
                    if name in change['fields']:
                        style = '%s:change' % style
                    cells.append((value, style, width, line))
                writer.write_row(cells)

        writer.set_col_widths()