TicketBoxMacro: summary_inline.patch

File summary_inline.patch, 3.1 kB (added by laas@eenet.ee, 1 year ago)

Adds support to tickets' summary field and 'inline' rendering. Alternative to Gary's and gotoh's patches

  • TicketBox.py

    old new  
    3838           "background": "#f7f7f0", 
    3939           "width": "25%", 
    4040           } 
     41inline_styles = { 
     42                 "background": "#f7f7f0", 
     43                 } 
    4144 
    4245args_pat = [r"#?(?P<tktnum>\d+)", 
    4346            r"{(?P<rptnum>\d+)}", 
    4447            r"\[report:(?P<rptnum2>\d+)(?P<dv>\?.*)?\]", 
    4548            r"(?P<width>\d+(pt|px|%))", 
     49            r"(?P<summary>summary)", 
     50            r"(?P<inline>inline)", 
    4651            r"(?P<title1>'.*')", 
    4752            r'(?P<title2>".*")'] 
    4853 
     
    6166    if not txt: 
    6267        txt = '' 
    6368    items = [] 
     69    long_items = {} 
     70    show_summary = False 
     71    inline = False 
    6472    title = "Tickets" 
    6573    args_re = re.compile("^(?:" + string.join(args_pat, "|") + ")$") 
    6674    for arg in [string.strip(s) for s in txt.split(',')]: 
     
    7684            styles['width'] = match.group('width') 
    7785        elif match.group('tktnum'): 
    7886            items.append(int(match.group('tktnum'))) 
     87        elif match.group('summary'): 
     88            show_summary = True 
     89        elif match.group('inline'): 
     90            inline = True 
    7991        elif match.group('rptnum') or match.group('rptnum2'): 
    8092            num = match.group('rptnum') or match.group('rptnum2') 
    8193            dv = {} 
     
    103115                if rows: 
    104116                    descriptions = [desc[0] for desc in curs.description] 
    105117                    idx = descriptions.index('ticket') 
     118                    summ = descriptions.index('summary') 
    106119                    for row in rows: 
    107120                        items.append(row[idx]) 
     121                        long_items[row[idx]] = row[summ] 
    108122            finally: 
    109123                if not hasattr(env, 'get_cnx_pool'): 
    110124                    # without db connection pool, we should close db. 
     
    116130    try: 
    117131        # for trac 0.9 or later 
    118132        from trac.wiki.formatter import wiki_to_oneliner 
    119         html = wiki_to_oneliner(string.join(["#%d" % c for c in items], ", "), 
    120                                env, env.get_db_cnx()) 
    121133    except: 
    122134        # for trac 0.8.x 
    123135        from trac.WikiFormatter import wiki_to_oneliner 
     136 
     137    if show_summary: 
     138        html = string.join([wiki_to_oneliner("%s (#%d)" % (v,k), 
     139                env, env.get_db_cnx()) for k,v in long_items.iteritems()], "<br>") 
     140    else: 
    124141        html = wiki_to_oneliner(string.join(["#%d" % c for c in items], ", "), 
    125                                 hdf, env, env.get_db_cnx()) 
     142                              env, env.get_db_cnx()) 
     143 
    126144    if html != '': 
    127145        try: 
    128146            title = title % len(items)  # process %d in title 
    129147        except: 
    130148            pass 
    131         style = string.join(["%s:%s" % (k,v) for k,v in styles.items() if v <> ""], "; ") 
     149        if inline: 
     150                style = string.join(["%s:%s" % (k,v) for k,v in inline_styles.items() if v <> ""], "; ") 
     151        else: 
     152                style = string.join(["%s:%s" % (k,v) for k,v in styles.items() if v <> ""], "; ") 
    132153        return '<fieldset class="ticketbox" style="%s"><legend>%s</legend>%s</fieldset>' % \ 
    133154               (style, title, html) 
    134155    else: