Attachment 'todo.py'

Download

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