Changeset 4049

Show
Ignore:
Timestamp:
07/21/08 12:31:03 (3 months ago)
Author:
gotoh
Message:

Now 'summary' option can take argument as field name to use.
If you change the field name of summary in report definition,
you should specify that name like:

[[TicketBox('title',{1},summary=Titre,inline)]]

This is enhancement regarding to ticket #3424.

And also the 'ticket' option is allowed to specify its field name.

Files:

Legend:

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

    r3958 r4049  
    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}}} 
     
    4852            r"\[report:(?P<rptnum2>\d+)(?P<dv>\?.*)?\]", 
    4953            r"(?P<width>\d+(pt|px|%))", 
    50             r"(?P<keyword>nosort|summary|inline)", 
     54            r"(?P<keyword>nosort|summary|inline|ticket)(?:=(?P<kwarg>.*))?", 
    5155            r"(?P<title1>'.*')", 
    5256            r'(?P<title2>".*")'] 
     57 
     58# default name of fields 
     59default_summary_field = 'summary' 
     60default_ticket_field = 'ticket' 
    5361 
    5462def uniq(x): 
     
    7078        txt = '' 
    7179    items = [] 
     80    summary = None 
     81    ticket = default_ticket_field 
    7282    summaries = {} 
    73     show_summary = False 
    7483    inline = False 
    7584    nosort = False 
    7685    title = "Tickets" 
    7786    args_re = re.compile("^(?:" + string.join(args_pat, "|") + ")$") 
    78     for arg in [string.strip(s) for s in txt.split(',')]: 
     87    args = [string.strip(s) for s in txt.split(',')] 
     88    # process options first 
     89    for arg in args: 
    7990        match = args_re.match(arg) 
    8091        if not match: 
     
    8798        elif match.group('width'): 
    8899            styles['width'] = match.group('width') 
    89         elif match.group('tktnum'): 
    90             items.append(int(match.group('tktnum'))) 
    91100        elif match.group('keyword'): 
    92101            kw = match.group('keyword').lower() 
     102            kwarg = match.group('kwarg') 
    93103            if kw == 'summary': 
    94                 show_summary = True 
     104                summary = kwarg or default_summary_field 
    95105            elif kw == 'inline': 
    96106                inline = True 
    97107            elif kw == 'nosort': 
    98108                nosort = True 
     109    # pick up ticket numbers and report numbers 
     110    for arg in args: 
     111        match = args_re.match(arg) 
     112        if not match: 
     113            continue 
     114        elif match.group('tktnum'): 
     115            items.append(int(match.group('tktnum'))) 
    99116        elif match.group('rptnum') or match.group('rptnum2'): 
    100117            num = match.group('rptnum') or match.group('rptnum2') 
     
    125142                if rows: 
    126143                    descriptions = [desc[0] for desc in curs.description] 
    127                     idx = descriptions.index('ticket') 
    128                     summ = descriptions.index('summary') 
     144                    try: 
     145                        idx = descriptions.index(ticket) 
     146                    except: 
     147                        raise Exception('No such column for ticket: %r' 
     148                                        % ticket ) 
     149                    if summary: 
     150                        try: 
     151                            sidx = descriptions.index(summary) 
     152                        except: 
     153                            raise Exception('No such column for summary: %r' 
     154                                            % summary) 
    129155                    for row in rows: 
    130156                        items.append(row[idx]) 
    131                         summaries[row[idx]] = row[summ] 
     157                        if summary: 
     158                            summaries[row[idx]] = row[sidx] 
    132159            finally: 
    133160                if not hasattr(env, 'get_cnx_pool'): 
     
    139166        items.sort() 
    140167    html = '' 
    141     if show_summary: 
     168    if summary: 
    142169        html = string.join([wiki_to_oneliner("%s (#%d)" % (summaries[n],n), 
    143170                                             env,