Edgewall Software

Ticket #9494: ticket_props_formatting.patch

File ticket_props_formatting.patch, 2.9 KB (added by Andrew C Martin <andrew.c.martin@…>, 23 months ago)
  • trac/ticket/notification.py

     
    183183            if fval.find('\n') != -1: 
    184184                continue 
    185185            idx = 2 * (i % 2) 
    186             if len(f['label']) > width[idx]: 
    187                 width[idx] = len(f['label']) 
    188             if len(fval) > width[idx + 1]: 
    189                 width[idx + 1] = len(fval) 
     186            width[idx] = max(len(f['label']), width[idx]) 
     187            width[idx + 1] = max(len(fval), width[idx + 1]) 
    190188            i += 1 
    191         format = (u'%%%is:  %%-%is  |  ' % (width[0], width[1]), 
    192                   u' %%%is:  %%-%is%s' % (width[2], width[3], CRLF)) 
    193         l = (width[0] + width[1] + 5) 
    194         sep = l * '-' + '+' + (self.COLS - l) * '-' 
     189        width_l = width[0] + width[1] + 5 
     190        width_r = width[2] + width[3] + 5 
     191        half_cols = (self.COLS - 1) / 2 
     192        if width_l + width_r + 1 > self.COLS: 
     193          if ((width_l > half_cols and width_r > half_cols) or  
     194              (width[0] > half_cols / 2 or width[2] > half_cols / 2)): 
     195            width_l = half_cols 
     196            width_r = half_cols 
     197          elif width_l > width_r: 
     198            width_l = min((self.COLS - 1) * 2 / 3, width_l) 
     199            width_r = self.COLS - width_l - 1 
     200          else: 
     201            width_r = min((self.COLS - 1) * 2 / 3, width_r)          
     202            width_l = self.COLS - width_r - 1 
     203        sep = width_l * '-' + '+' + width_r * '-' 
    195204        txt = sep + CRLF 
     205        cell_tmp = [u'', u''] 
    196206        big = [] 
    197207        i = 0 
     208        width_lr = [width_l, width_r] 
    198209        for f in [f for f in fields if f['name'] != 'description']: 
    199210            fname = f['name'] 
    200211            if not tkt.values.has_key(fname): 
     
    207218            else: 
    208219                # Note: f['label'] is a Babel's LazyObject, make sure its 
    209220                # __str__ method won't be called. 
    210                 txt += format[i % 2] % (f['label'], unicode(fval)) 
     221                str_tmp = u'%s:  %s' % (f['label'], unicode(fval)) 
     222                idx = i % 2 
     223                cell_tmp[idx] += wrap(str_tmp, width_lr[idx] - 2 + 2 * idx, 
     224                    (width[2 * idx] - len(f['label']) + 2 * idx) * ' ', 
     225                    2 * ' ', CRLF) 
     226                cell_tmp[idx] += CRLF 
    211227                i += 1 
    212         if i % 2: 
    213             txt += CRLF 
     228        cell_l = cell_tmp[0].splitlines() 
     229        cell_r = cell_tmp[1].splitlines() 
     230        format = u'%%-%is|%%s%%s' % (width_l) 
     231        for i in range(max(len(cell_l), len(cell_r))): 
     232          if i >= len(cell_l): 
     233              cell_l.append(width_l * ' ') 
     234          elif i >= len(cell_r): 
     235              cell_r.append('') 
     236          txt += format % (cell_l[i], cell_r[i], CRLF) 
    214237        if big: 
    215238            txt += sep 
    216239            for name, value in big: