trac-wikitablemacro-0.7785/ 0000755 0000000 0000000 00000000000 11350707753 014256 5 ustar root root trac-wikitablemacro-0.7785/wikitable/ 0000755 0000000 0000000 00000000000 11350707753 016231 5 ustar root root trac-wikitablemacro-0.7785/wikitable/table.py 0000644 0000000 0000000 00000003260 11102333767 017666 0 ustar root root from pkg_resources import resource_filename
from StringIO import StringIO
from trac.core import implements
from trac.web.chrome import ITemplateProvider, add_stylesheet
from trac.wiki.macros import WikiMacroBase
from trac.util.html import Markup
class SQLTable(WikiMacroBase):
"""Draw a table from a SQL query in a wiki page.
Examples:
{{{
{{{
#!SQLTable
SELECT count(id) as 'Number of Tickets'
FROM ticket
}}}
}}}
"""
implements(ITemplateProvider)
# ITemplateProvider methods
def get_templates_dirs(self):
return []
def get_htdocs_dirs(self):
return [('wikitable', resource_filename(__name__, 'htdocs'))]
# Render macro
def render_macro(self, req, name, content):
db = self.env.get_db_cnx()
cursor = db.cursor()
cursor.execute(content)
out = StringIO()
print >>out, "
"
print >>out, " "
print >>out, " "
for desc in cursor.description:
print >>out, "%s | " % desc[0]
print >>out, "
"
print >>out, " "
print >>out, " "
for idx, row in enumerate(cursor):
css_class = (idx % 2 == 0) and 'odd' or 'even'
print >>out, " " % css_class
for col in row:
print >>out, "%s | " % col
print >>out, "
"
print >>out, " "
print >>out, "
"
add_stylesheet(req, 'wikitable/css/wikitable.css')
return Markup(out.getvalue())
trac-wikitablemacro-0.7785/wikitable/scalar.py 0000644 0000000 0000000 00000001657 11102640635 020047 0 ustar root root from pkg_resources import resource_filename
from StringIO import StringIO
from trac.core import implements
from trac.web.chrome import ITemplateProvider, add_stylesheet
from trac.wiki.macros import WikiMacroBase
from trac.util.html import Markup
class SQLScalar(WikiMacroBase):
"""Output a number from a scalar (1x1) SQL query.
Examples:
{{{
{{{
#!SQLScalar
SELECT count(id) as 'Number of Tickets'
FROM ticket
}}}
}}}
"""
# Render macro
def render_macro(self, req, name, content):
db = self.env.get_db_cnx()
cursor = db.cursor()
cursor.execute(content)
value = "Unknown"
for row in cursor:
value = unicode(row[0])
break
out = StringIO()
print >>out, u"%s" % value
add_stylesheet(req, 'wikitable/css/wikitable.css')
return Markup(out.getvalue())
trac-wikitablemacro-0.7785/wikitable/__init__.py 0000644 0000000 0000000 00000000033 11102640635 020324 0 ustar root root import table
import scalar
trac-wikitablemacro-0.7785/wikitable/htdocs/ 0000755 0000000 0000000 00000000000 11350707753 017515 5 ustar root root trac-wikitablemacro-0.7785/wikitable/htdocs/css/ 0000755 0000000 0000000 00000000000 11350707753 020305 5 ustar root root trac-wikitablemacro-0.7785/wikitable/htdocs/css/wikitable.css 0000644 0000000 0000000 00000000044 11102333767 022763 0 ustar root root table.wikitable {
width: auto;
} trac-wikitablemacro-0.7785/README.txt 0000644 0000000 0000000 00000001066 11334204740 015745 0 ustar root root =================
Wiki Table Plugin
=================
This plugin allows you to query the Trac database with a SQL query and
display the results as a table in a wiki page.
Usage::
{{{
#!SQLTable
SELECT count(id) as 'Number of Tickets'
FROM ticket
}}}
This will create a table with one row and one column. You can obviously
create more complex queries as you wish.
Installation
------------
Install as normal, using easy_install or 'python setup.py install'. Then
add this to trac.ini::
[components]
wikitable.* = enabled trac-wikitablemacro-0.7785/setup.py 0000644 0000000 0000000 00000001201 11334210430 015741 0 ustar root root #!/usr/bin/env python
# -*- coding: iso-8859-1 -*-
from setuptools import setup
setup(
name = 'WikiTableMacro',
author = 'Martin Aspeli',
author_email = 'optilude@gmail.com',
maintainer = 'Ryan J Ollos',
maintainer_email = 'ryano@physiosonics.com',
description = 'Trac plugin for drawing a table from a SQL query in a wiki page',
url = 'http://trac-hacks.org/wiki/ProgressMeterMacro',
version = '0.1',
license='BSD',
packages=['wikitable'],
package_data={'wikitable': ['htdocs/css/*.css',]},
entry_points = {
'trac.plugins': [
'wikitable = wikitable'
]
},
)