TicketBoxMacro: TicketBox.2.diffs

File TicketBox.2.diffs, 2.9 kB (added by gotoh, 2 years ago)

Revised Gray's patch to adapt to recent code.

Line 
1 Index: TicketBox.py
2 ===================================================================
3 --- TicketBox.py        (revision 1306)
4 +++ TicketBox.py        (working copy)
5 @@ -25,6 +25,11 @@
6  {{{[report:9?PRIORITY=high&COMPONENT=ui]}}}. Of course, the special
7  variable '{{{$USER}}}' is available. The login name (or 'anonymous)
8  is used as $USER if not specified explicitly.
9 +
10 +The report should produce at least the field {{{ticket}}} containing
11 +the ticket ID.  If it also contains a {{{text}}} field a different
12 +formatting will be used showing that text after the ticket ID
13 +hyperlink.
14  """
15  
16  ## NOTE: CSS2 defines 'max-width' but it seems that only few browser
17 @@ -57,6 +62,7 @@
18      if not txt:
19          txt = ''
20      items = []
21 +    items_have_text = False
22      title = "Tickets"
23      args_re = re.compile("^(?:" + string.join(args_pat, "|") + ")$")
24      for arg in [string.strip(s) for s in txt.split(',')]:
25 @@ -96,10 +102,19 @@
26                  curs.execute(sql)
27                  rows = curs.fetchall()
28                  if rows:
29 +                    # Get the index of the fields we're interested in
30 +                    # The fields are 'ticket' (the ID) and optionally 'text'.
31                      descriptions = [desc[0] for desc in curs.description]
32                      idx = descriptions.index('ticket')
33 +                   if descriptions.count('text'):
34 +                       text = descriptions.index('text')
35 +                       items_have_text = True
36 +                    # Now get the values from each row
37                      for row in rows:
38 -                        items.append(row[idx])
39 +                        if items_have_text:
40 +                          items.append("#%d: %s"%(row[idx], row[text]))
41 +                        else:
42 +                         items.append("#%d"%row[idx])
43              finally:
44                  if not hasattr(env, 'get_cnx_pool'):
45                      # without db connection pool, we should close db.
46 @@ -110,13 +125,19 @@
47      html = ''
48      try:
49          # for trac 0.9 or later
50 -        from trac.wiki.formatter import wiki_to_oneliner
51 -        html = wiki_to_oneliner(string.join(["#%d" % c for c in items], ", "),
52 +        from trac.wiki.formatter import wiki_to_oneliner, wiki_to_html
53 +        if items_have_text:
54 +          html = wiki_to_html(string.join(["%s" % str(c) for c in items],
55 +                                          "[[BR]]"),
56                                 env, env.get_db_cnx())
57 +        else:
58 +          html = wiki_to_oneliner(string.join(["%s" % str(c) for c in items], ", "),
59 +                               env, env.get_db_cnx())
60      except:
61          # for trac 0.8.x
62          from trac.WikiFormatter import wiki_to_oneliner
63 -        html = wiki_to_oneliner(string.join(["#%d" % c for c in items], ", "),
64 +        html = wiki_to_oneliner(string.join(["%s" % str(c) for c in items],
65 +sep),
66                                  hdf, env, env.get_db_cnx())
67      if html != '':
68          try: