#2801 closed enhancement (fixed)
CSV Support for 0.11
| Reported by: | Owned by: | Ryan J Ollos | |
|---|---|---|---|
| Priority: | normal | Component: | CsvMacro |
| Severity: | normal | Keywords: | |
| Cc: | Dmitri | Trac Release: | 0.11 |
Description
I changed the file slightly to make it work as a plugin for 0.11, as seen below.
from trac.wiki.macros import WikiMacroBase from trac.util import escape import csv class CsvMacro(WikiMacroBase): def get_macros(self): yield 'CSV' def get_macro_description(self, name): return inspect.getdoc(CsvMacro) def expand_macro(self, formatter, name, txt): sniffer = csv.Sniffer() txt = txt.encode('ascii', 'replace') reader = csv.reader(StringIO(txt), sniffer.sniff(txt)) formatter.out.write('<table class="wiki">\n') for row in reader: formatter.out.write('<tr>') for col in row: formatter.out.write('<td>%s</td>' % escape(col)) formatter.out.write('</tr>\n') formatter.out.write('</table>\n')
Attachments (3)
Change History (11)
comment:1 Changed 17 years ago by
comment:2 Changed 17 years ago by
And finally a this moment for 0.11 and 0.12dev:
from trac.wiki.macros import WikiMacroBase from trac.util import escape from StringIO import StringIO import csv class CsvMacro(WikiMacroBase): """ Display CSV data in a table. Simply copy and paste the CSV data into the macro body and hope for the best. Example: {{{ {{{ #!CSV 123 123 123 123 234 234 234 234 }}} }}} Renders as || 123 || 123 || 123 || 123 || || 234 || 234 || 234 || 234 || """ def get_macros(self): yield 'CSV' def expand_macro(self, formatter, name, txt): sniffer = csv.Sniffer() txt = txt.encode('ascii', 'replace') reader = csv.reader(StringIO(txt), sniffer.sniff(txt)) formatter.out.write('<table class="wiki">\n') for row in reader: formatter.out.write('<tr>') for col in row: formatter.out.write('<td>%s</td>' % escape(col)) formatter.out.write('</tr>\n') formatter.out.write('</table>\n')
comment:3 Changed 17 years ago by
Somehow I still couldn't get 0.11 to pickup the macro that I added to the plugins directory. So again I packed it as a real plugin and attached to the ticket, you can install it using:
easy_install http://trac-hacks.org/raw-attachment/ticket/2801/CSV-0.11.zip
comment:4 follow-up: 5 Changed 15 years ago by
| Cc: | Dmitri added; anonymous removed |
|---|
Replying to sagacis@gmail.com:
So why don't you commit this code into repository? This plugin works good even for trac-0.12.
comment:5 Changed 15 years ago by
Replying to g1itch:
Replying to sagacis@gmail.com:
So why don't you commit this code into repository? This plugin works good even for trac-0.12.
Because he doesn't have permission to commit most likely!
comment:6 Changed 15 years ago by
Yup. I don't have access and submitted that plugin over two years ago. Feel free to commit, modify or otherwise use that code.
Changed 13 years ago by
Changed 13 years ago by
| Attachment: | CSV_0.11.py added |
|---|
comment:7 Changed 13 years ago by
| Owner: | changed from Alec Thomas to Ryan J Ollos |
|---|---|
| Status: | new → assigned |
Added two files that were attached to the project's wiki page.
comment:8 Changed 13 years ago by
| Resolution: | → fixed |
|---|---|
| Status: | assigned → closed |



In code above on begin missing: