Changeset 4050

Show
Ignore:
Timestamp:
07/21/08 13:57:05 (4 months ago)
Author:
gotoh
Message:

Backport of r4049.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • ticketboxmacro/0.10/TicketBox.py

    r4015 r4050  
    1212[[TicketBox([report:1])]]              ... alternate format of report 
    1313[[TicketBox([report:9?name=val])]]     ... report with dynamic variable 
    14 [[TicketBox({1),#50,{2},100)]]         ... convination of above 
     14[[TicketBox({1},#50,{2},100)]]         ... convination of above 
    1515[[TicketBox(500pt,{1})]]               ... with box width as 50 point 
    1616[[TicketBox(200px,{1})]]               ... with box width as 200 pixel 
     
    1919[[TicketBox(\"Other Title\",#1,#2)]]     ... likewise 
    2020[[TicketBox('%d tickets',#1,#2)]]      ... embed ticket count in title 
     21[[TicketBox({1}, inline)]]             ... display the box as block element. 
     22[[TicketBox({1}, summary)]]            ... display with summary per line 
     23[[TicketBox({1}, summary=Titre)]]      ... specify field name of summary 
     24[[TicketBox({1}, ticket=ID)]]          ... specify field name of ticket num. 
    2125[[TicketBox({1}, nosort)]]             ... display numbers without sort 
    2226}}} 
     
    5862            r"\[report:(?P<rptnum2>\d+)(?P<dv>\?.*)?\]", 
    5963            r"(?P<width>\d+(pt|px|%))", 
    60             r"(?P<keyword>nosort|summary|inline)", 
     64            r"(?P<keyword>nosort|summary|inline|ticket)(?:=(?P<kwarg>.*))?", 
    6165            r"(?P<title1>'.*')", 
    6266            r'(?P<title2>".*")'] 
     67 
     68# default name of fields 
     69default_summary_field = 'summary' 
     70default_ticket_field = 'ticket' 
    6371 
    6472def uniq(x): 
     
    7785        txt = '' 
    7886    items = [] 
     87    summary = None 
     88    ticket = default_ticket_field 
    7989    summaries = {} 
    80     show_summary = False 
    8190    inline = False 
    8291    nosort = False 
    8392    title = "Tickets" 
    8493    args_re = re.compile("^(?:" + string.join(args_pat, "|") + ")$") 
    85     for arg in [string.strip(s) for s in txt.split(',')]: 
     94    args = [string.strip(s) for s in txt.split(',')] 
     95    # process options first 
     96    for arg in args: 
    8697        match = args_re.match(arg) 
    8798        if not match: 
     
    94105        elif match.group('width'): 
    95106            styles['width'] = match.group('width') 
    96         elif match.group('tktnum'): 
    97             items.append(int(match.group('tktnum'))) 
    98107        elif match.group('keyword'): 
    99108            kw = match.group('keyword').lower() 
     109            kwarg = match.group('kwarg') 
    100110            if kw == 'summary': 
    101                 show_summary = True 
     111                summary = kwarg or default_summary_field 
    102112            elif kw == 'inline': 
    103113                inline = True 
    104114            elif kw == 'nosort': 
    105115                nosort = True 
     116    # pick up ticket numbers and report numbers 
     117    for arg in args: 
     118        match = args_re.match(arg) 
     119        if not match: 
     120            continue 
     121        elif match.group('tktnum'): 
     122            items.append(int(match.group('tktnum'))) 
    106123        elif match.group('rptnum') or match.group('rptnum2'): 
    107124            num = match.group('rptnum') or match.group('rptnum2') 
     
    139156                if rows: 
    140157                    descriptions = [desc[0] for desc in curs.description] 
    141                     idx = descriptions.index('ticket') 
    142                     summ = descriptions.index('summary') 
     158                    try: 
     159                        idx = descriptions.index(ticket) 
     160                    except: 
     161                        raise Exception('No such column for ticket: %r' 
     162                                        % ticket ) 
     163                    if summary: 
     164                        try: 
     165                            sidx = descriptions.index(summary) 
     166                        except: 
     167                            raise Exception('No such column for summary: %r' 
     168                                            % summary) 
    143169                    for row in rows: 
    144170                        items.append(row[idx]) 
    145                         summaries[row[idx]] = row[summ] 
     171                        if summary: 
     172                            summaries[row[idx]] = row[sidx] 
    146173            finally: 
    147174                if not hasattr(env, 'get_cnx_pool'): 
     
    154181    html = '' 
    155182 
    156     if show_summary: 
     183    if summary: 
    157184        html = string.join([wiki_to_oneliner("%s (#%d)" % (summaries[n], n), 
    158185                                             env, env.get_db_cnx()) for n in items], "<br>") 
  • ticketboxmacro/0.9/TicketBox.py

    r4015 r4050  
    1212[[TicketBox([report:1])]]              ... alternate format of report 
    1313[[TicketBox([report:9?name=val])]]     ... report with dynamic variable 
    14 [[TicketBox({1),#50,{2},100)]]         ... convination of above 
     14[[TicketBox({1},#50,{2},100)]]         ... convination of above 
    1515[[TicketBox(500pt,{1})]]               ... with box width as 50 point 
    1616[[TicketBox(200px,{1})]]               ... with box width as 200 pixel 
     
    1919[[TicketBox(\"Other Title\",#1,#2)]]     ... likewise 
    2020[[TicketBox('%d tickets',#1,#2)]]      ... embed ticket count in title 
     21[[TicketBox({1}, inline)]]             ... display the box as block element. 
     22[[TicketBox({1}, summary)]]            ... display with summary per line 
     23[[TicketBox({1}, summary=Titre)]]      ... specify field name of summary 
     24[[TicketBox({1}, ticket=ID)]]          ... specify field name of ticket num. 
    2125[[TicketBox({1}, nosort)]]             ... display numbers without sort 
    2226}}} 
     
    5458            r"\[report:(?P<rptnum2>\d+)(?P<dv>\?.*)?\]", 
    5559            r"(?P<width>\d+(pt|px|%))", 
    56             r"(?P<keyword>nosort|summary|inline)", 
     60            r"(?P<keyword>nosort|summary|inline|ticket)(?:=(?P<kwarg>.*))?", 
    5761            r"(?P<title1>'.*')", 
    5862            r'(?P<title2>".*")'] 
     63 
     64# default name of fields 
     65default_summary_field = 'summary' 
     66default_ticket_field = 'ticket' 
    5967 
    6068def uniq(x): 
     
    7381        txt = '' 
    7482    items = [] 
     83    summary = None 
     84    ticket = default_ticket_field 
    7585    summaries = {} 
    76     show_summary = False 
    7786    inline = False 
    7887    nosort = False 
    7988    title = "Tickets" 
    8089    args_re = re.compile("^(?:" + string.join(args_pat, "|") + ")$") 
    81     for arg in [string.strip(s) for s in txt.split(',')]: 
     90    args = [string.strip(s) for s in txt.split(',')] 
     91    # process options first 
     92    for arg in args: 
    8293        match = args_re.match(arg) 
    8394        if not match: 
     
    90101        elif match.group('width'): 
    91102            styles['width'] = match.group('width') 
    92         elif match.group('tktnum'): 
    93             items.append(int(match.group('tktnum'))) 
    94103        elif match.group('keyword'): 
    95104            kw = match.group('keyword').lower() 
     105            kwarg = match.group('kwarg') 
    96106            if kw == 'summary': 
    97                 show_summary = True 
     107                summary = kwarg or default_summary_field 
    98108            elif kw == 'inline': 
    99109                inline = True 
    100110            elif kw == 'nosort': 
    101111                nosort = True 
     112    # pick up ticket numbers and report numbers 
     113    for arg in args: 
     114        match = args_re.match(arg) 
     115        if not match: 
     116            continue 
     117        elif match.group('tktnum'): 
     118            items.append(int(match.group('tktnum'))) 
    102119        elif match.group('rptnum') or match.group('rptnum2'): 
    103120            num = match.group('rptnum') or match.group('rptnum2') 
     
    129146                if rows: 
    130147                    descriptions = [desc[0] for desc in curs.description] 
    131                     idx = descriptions.index('ticket') 
    132                     summ = descriptions.index('summary') 
     148                    try: 
     149                        idx = descriptions.index(ticket) 
     150                    except: 
     151                        raise Exception('No such column for ticket: %r' 
     152                                        % ticket ) 
     153                    if summary: 
     154                        try: 
     155                            sidx = descriptions.index(summary) 
     156                        except: 
     157                            raise Exception('No such column for summary: %r' 
     158                                            % summary) 
    133159                    for row in rows: 
    134160                        items.append(row[idx]) 
    135                         summaries[row[idx]] = row[summ] 
     161                        if summary: 
     162                            summaries[row[idx]] = row[sidx] 
    136163            finally: 
    137164                if not hasattr(env, 'get_cnx_pool'): 
     
    144171    html = '' 
    145172 
    146     if show_summary: 
     173    if summary: 
    147174        html = string.join([wiki_to_oneliner("%s (#%d)" % (summaries[n], n), 
    148175                                             env, env.get_db_cnx()) for n in items], "<br>")