Attachment 'todo-1.6.py'

Download

   1 # -*- coding: iso-8859-1 -*-
   2 """
   3     MoinMoin - ToDo Parser
   4 
   5     @copyright: 2007, 2008 Terry Brown <terry_n_brown@yahoo.com>
   6     @license: GNU GPL
   7     @version: 200803112319
   8 
   9 """
  10 
  11 from MoinMoin.parser._ParserBase import ParserBase
  12 from MoinMoin.parser import text_moin_wiki
  13 
  14 Dependencies = []
  15 
  16 class Parser (ParserBase):
  17     """
  18         Format todo items
  19     """
  20 
  21     parsername = "Todo"
  22     extensions = '*'
  23     Dependencies = []
  24 
  25     def __init__(self, raw, request, **kw):
  26         ParserBase.__init__(self, raw, request, **kw)
  27         self.form = request.form
  28         self._ = request.getText
  29 
  30     def format(self, formatter):
  31         """ Send the text. """
  32 
  33         _ = self._
  34 
  35         tmplt = (
  36             'title', 'Item', 'T', True, _('Task'),
  37             'percent', 0, '%', True, '%',
  38             'who', 'Unassigned', 'W', True, _('Who'),
  39             'due', '', 'D', False, _('Due'),
  40             'starts', '', 'S', False, _('Start'),
  41             'priority', '', 'P', False, _('Priority'),
  42             'units', '', 'U', False, _('Effort'),
  43             'description', '', 'E', False, _('Details'),
  44             )
  45 
  46         t = 5  # update this to match columns in data above
  47         flds = tmplt[0::t]  # ordered list of fields
  48         keys = dict(zip(tmplt[2::t], flds))  # map tag to field name
  49         showDefault = dict(zip(flds, tmplt[3::t]))
  50         # should column appear if no data supplied?
  51         headings = dict(zip(flds, tmplt[4::t]))  # map field name to headings
  52 
  53         tmplt = dict(zip(flds, tmplt[1::t]))  # default item
  54 
  55         present = set([k for k in showDefault.keys() if showDefault[k]])
  56         # fields with showDefault == True are always shown / present
  57 
  58         items = []
  59 
  60         for line in self.raw.split('\n'):
  61 
  62             if line.startswith('#'): continue  # a comment
  63 
  64             if line.startswith((' ','\t')) or line == '':  # extra material
  65                 if items:
  66                     item = items[-1]
  67                     if 'log' not in item:
  68                         item['log'] = ''
  69                         x = 0  # strip same whitespace of all lines in block
  70                         while x < len(line) and line[x] in ' \t': x+=1
  71                     txt = line[x:].replace('<<<', '{{{')
  72                     txt = txt.replace('>>>', '}}}')
  73                     item['log'] = item['log'] + '\n' + txt
  74                 continue
  75 
  76             tagMode = ':' in line.split('|')[0]
  77 
  78             if not tagMode:
  79                 item = dict(zip(flds,
  80                     [i.strip() for i in line.split('|')]))
  81             else:
  82                 item = {}
  83                 for spec in line.split('|'):
  84                     k,v = [i.strip() for i in spec.split(':', 1)]
  85                     item[keys[k]] = v
  86 
  87             # track present fields, set defaults
  88             for k in flds:
  89                 v = None
  90                 if k in item:
  91                     present.add(k)
  92                 else:
  93                     item[k] = tmplt[k]
  94 
  95             items.append(item)
  96 
  97         def emit(x):
  98             self.request.write(x)
  99 
 100         def wemit(x):
 101             """emit something using wiki parser"""
 102             wk = text_moin_wiki.Parser(x, self.request)
 103             wk.format(formatter)
 104 
 105         f = formatter
 106 
 107         emit(f.table(1))
 108 
 109         # show headings
 110         emit(f.table_row(1))
 111         for k in [fld for fld in flds if fld in present]:
 112             emit(f.table_cell(1))
 113             wemit("'''"+str(headings[k])+"'''")
 114             emit(f.table_cell(0))
 115         emit(f.table_row(0))
 116 
 117         for item in items:
 118             try:
 119                 done = '2611' if int(item['percent']) == 100 else '2610'
 120             except:  # int() raised something
 121                 done = '2610'
 122 
 123             emit(f.table_row(1))
 124 
 125             for k in [fld for fld in flds if fld in present]:
 126 
 127                 emit(f.table_cell(1))
 128                 txt = unicode(item[k])
 129                 if k == 'title': txt = u'&#x%s; %s' % (done, txt)
 130                 wemit(txt)
 131                 emit(f.table_cell(0))
 132 
 133             emit(f.table_row(0))
 134 
 135             if 'log' in item:
 136                 emit(f.table_row(1))
 137                 emit(f.table_cell(1))  # empty cell
 138                 emit(f.table_cell(0))
 139                 emit(f.table_cell(1, colspan = len(present)-1))
 140                 wemit(unicode(item['log']))
 141                 emit(f.table_cell(0))
 142                 emit(f.table_row(0))
 143 
 144         emit(f.table(0))

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2011-11-21 00:05:25, 4.3 KB) [[attachment:todo-1.6.py]]
  • [get | view] (2011-11-21 00:00:33, 4.2 KB) [[attachment:todo.py]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.