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 _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_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()
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 _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_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()