Changeset 2810
- Timestamp:
- 11/20/07 18:15:19 (1 year ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
componentsprocessormacro/0.11/ComponentsListMacro.py
r2809 r2810 8 8 import sys 9 9 10 from StringIO import StringIO11 10 from trac.core import Component, implements 12 11 from trac.wiki.api import IWikiMacroProvider 13 from trac.wiki .formatter import Formatter12 from trac.wiki import format_to_html 14 13 15 14 class ComponentsProcessor(Component): … … 22 21 23 22 def get_macro_description(self, name): 24 #return inspect.getdoc(inspect.getmodule(self)) # works only in py >= 2.425 23 return inspect.getdoc(sys.modules.get(self.__module__)) 26 24 27 25 def expand_macro(self, formatter, name, content): 28 content = [] 26 29 27 cursor = self.env.get_db_cnx().cursor() 30 28 31 query = "SELECT name, description from component ;"29 query = "SELECT name, description from component order by name;" 32 30 cursor.execute(query) 33 31 34 32 comps = [comp for comp in cursor] 35 comps.sort(cmp=lambda x,y: cmp(x[0], y[0]))36 33 37 # get a list of all components for which there are tickets38 query = "SELECT distinct component from ticket;"34 # get a distinct list of all components for which there are tickets 35 query = "SELECT component from ticket group by component;" 39 36 cursor.execute(query) 40 37 tickets = [page[0] for page in cursor] 38 39 content = [] 41 40 42 41 for name, descrip in comps: … … 51 50 content = '\n'.join(content) 52 51 53 out = StringIO() 54 Formatter(self.env, formatter.context).format(content, out) 55 return out.getvalue() 52 content = format_to_html(self.env, formatter.context, content) 56 53 57 def _parse_args(self, args): 58 firstArgs = None; 59 if args.rfind(")"): 60 firstArgs = args[args.find("(") + 1 : args.rfind(")")]; 61 args = args[:args.find("(")] + args[args.rfind(")") + 1:] 54 content = '<div class="component-list">%s</div>' % content 62 55 63 macros = map(lambda s: s.strip(), args.split(',')); 56 # to avoid things like the above it might be nicer to use 57 # Genshi tag() construction, but this way the wiki formatter 58 # gets to deal with '[query:component=%s tickets]' etc. 59 # if going the Genshi route you'd replace that with something 60 # like req.href.query(component="mycomp", status="open") 64 61 65 return macros, firstArgs62 return content
