Modify

Opened 6 years ago

Closed 2 years ago

Last modified 12 months ago

#2801 closed enhancement (fixed)

CSV Support for 0.11

Reported by: sagacis@… Owned by: rjollos
Priority: normal Component: CsvMacro
Severity: normal Keywords:
Cc: g1itch 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)

CSV-0.11.zip (1.3 KB) - added by kennethxu 6 years ago.
As installable plugin
CSV.py (1.0 KB) - added by rjollos 2 years ago.
CSV_0.11.py (763 bytes) - added by rjollos 2 years ago.

Download all attachments as: .zip

Change History (11)

comment:1 Changed 6 years ago by marianp@…

In code above on begin missing:

from StringIO import StringIO

comment:2 Changed 6 years ago by marianp@…

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 6 years ago by kennethxu

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
Last edited 12 months ago by rjollos (previous) (diff)

Changed 6 years ago by kennethxu

As installable plugin

comment:4 in reply to: ↑ description ; follow-up: Changed 4 years ago by g1itch

  • Cc g1itch added

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 in reply to: ↑ 4 Changed 4 years ago by anonymous

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 4 years ago by anonymous

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 2 years ago by rjollos

Changed 2 years ago by rjollos

comment:7 Changed 2 years ago by rjollos

  • Owner changed from athomas to rjollos
  • Status changed from new to assigned

Added two files that were attached to the project's wiki page.

comment:8 Changed 2 years ago by rjollos

  • Resolution set to fixed
  • Status changed from assigned to closed

(In [11827]) Fixes #2801: Added macro that supports Trac 0.11.

Add Comment

Modify Ticket

Action
as closed .
as The resolution will be set. Next status will be 'closed'.
to The owner will be changed from rjollos. Next status will be 'closed'.
The resolution will be deleted. Next status will be 'reopened'.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.