| 1 | """Converts `application/x-trac-ticket` data to `application/vnd.ms-excel`.""" |
|---|
| 2 | |
|---|
| 3 | from trac.core import * |
|---|
| 4 | from trac.mimeview.api import IContentConverter |
|---|
| 5 | from trac.ticket.web_ui import TicketModule |
|---|
| 6 | from trac.ticket.query import QueryModule |
|---|
| 7 | |
|---|
| 8 | EXCEL_MIMETYPE = 'application/vnd.ms-excel' |
|---|
| 9 | |
|---|
| 10 | class TicketsToExcelConverter(Component): |
|---|
| 11 | implements (IContentConverter) |
|---|
| 12 | |
|---|
| 13 | # IContentConverter methods |
|---|
| 14 | def get_supported_conversions(self): |
|---|
| 15 | yield ('exceltsv', 'Excel', 'csv', |
|---|
| 16 | 'trac.ticket.model.Ticket', EXCEL_MIMETYPE, 8) |
|---|
| 17 | yield ('exceltsv', 'Excel', 'csv', |
|---|
| 18 | 'trac.ticket.query', EXCEL_MIMETYPE, 8) |
|---|
| 19 | |
|---|
| 20 | def convert_content(self, req, mimetype, content, key, filename=None, |
|---|
| 21 | url=None): |
|---|
| 22 | output = '%s; name=%s.xls' % (EXCEL_MIMETYPE, filename) |
|---|
| 23 | if mimetype == 'trac.ticket.model.Ticket': |
|---|
| 24 | return TicketModule(self.env).export_csv(content, sep='\t', |
|---|
| 25 | mimetype=output) |
|---|
| 26 | elif mimetype == 'trac.ticket.query': |
|---|
| 27 | return QueryModule(self.env).export_csv(content, sep='\t', |
|---|
| 28 | mimetype=output) |
|---|