Edgewall Software

Ticket #1791: 1791-wikiformatting-text-textarea-r7495.patch

File 1791-wikiformatting-text-textarea-r7495.patch, 6.4 KB (added by rblank, 3 years ago)

Patch agianst trunk adding configurable WikiFormatting for text and textarea custom fields

  • trac/htdocs/css/report.css

    diff --git a/trac/htdocs/css/report.css b/trac/htdocs/css/report.css
    a b  
    5050/* Styles for the report list and the report results table 
    5151   (extends the styles for "table.listing") */ 
    5252.reports td.title { width: 100% } 
    53 .reports tbody td :link, .reports tbody td :visited, 
    54 .tickets tbody td :link, .tickets tbody td :visited { display: block } 
    5553.tickets { border-bottom: none } 
    5654.tickets thead th { text-transform: capitalize; white-space: nowrap; } 
    5755.tickets tbody td, .reports tbody td { padding: .1em .5em !important } 
  • trac/htdocs/css/ticket.css

    diff --git a/trac/htdocs/css/ticket.css b/trac/htdocs/css/ticket.css
    a b  
    5656 width: 20%; 
    5757} 
    5858#ticket table.properties td { width: 30% } 
     59#ticket table.properties td p:first-child { margin-top: 0 } 
     60#ticket table.properties td p:last-child { margin-bottom: 0 } 
    5961#ticket table.properties .description { border-top: 1px solid #dd9 } 
    6062 
    6163#ticket .description h3 { 
  • trac/ticket/api.py

    diff --git a/trac/ticket/api.py b/trac/ticket/api.py
    a b  
    271271                if '' in field['options']: 
    272272                    field['optional'] = True 
    273273                    field['options'].remove('') 
     274            elif field['type'] == 'text': 
     275                field['format'] = config.get(name + '.format', 'plain') 
    274276            elif field['type'] == 'textarea': 
     277                field['format'] = config.get(name + '.format', 'plain') 
    275278                field['width'] = config.getint(name + '.cols') 
    276279                field['height'] = config.getint(name + '.rows') 
    277280            fields.append(field) 
  • trac/ticket/query.py

    diff --git a/trac/ticket/query.py b/trac/ticket/query.py
    a b  
    575575 
    576576        cols = self.get_columns() 
    577577        labels = dict([(f['name'], f['label']) for f in self.fields]) 
     578        wikify = dict((f['name'], f['type'] == 'text' and f.get('format') == 'wiki') for f in self.fields) 
    578579 
    579580        # TODO: remove after adding time/changetime to the api.py 
    580581        labels['changetime'] = _('Modified') 
     
    582583 
    583584        headers = [{ 
    584585            'name': col, 'label': labels.get(col, _('Ticket')), 
     586            'wikify': wikify.get(col, False), 
    585587            'href': self.get_href(context.href, order=col, 
    586588                                  desc=(col == self.order and not self.desc)) 
    587589        } for col in cols] 
  • trac/ticket/templates/query_results.html

    diff --git a/trac/ticket/templates/query_results.html b/trac/ticket/templates/query_results.html
    a b  
    6262                      <py:when test="name == 'reporter'">${authorinfo(value)}</py:when> 
    6363                      <py:when test="name == 'cc'">${format_emails(ticket_context, value)}</py:when> 
    6464                      <py:when test="name == 'owner' and value">${authorinfo(value)}</py:when> 
     65                      <py:when test="header.wikify">${wiki_to_oneliner(ticket_context, value)}</py:when> 
    6566                      <py:otherwise>$value</py:otherwise> 
    6667                    </td> 
    6768                  </py:with> 
  • trac/ticket/templates/ticket.html

    diff --git a/trac/ticket/templates/ticket.html b/trac/ticket/templates/ticket.html
    a b  
    155155                    colspan="${fullrow and 3 or None}"> 
    156156                  <py:if test="field"> 
    157157                    <py:choose test=""> 
    158                       <py:when test="'rendered' in field">${field.rendered}</py:when> 
    159                       <py:otherwise>${ticket[field.name]}</py:otherwise> 
     158                      <py:when test="field.type == 'textarea' and field.format == 'wiki'"> 
     159                        ${wiki_to_html(context, ticket[field.name], escape_newlines=preserve_newlines)} 
     160                      </py:when> 
     161                      <py:when test="field.type == 'text' and field.format == 'wiki'"> 
     162                        ${wiki_to_oneliner(context, ticket[field.name])} 
     163                      </py:when> 
     164                      <py:otherwise> 
     165                        <py:choose test=""> 
     166                          <py:when test="'rendered' in field">${field.rendered}</py:when> 
     167                          <py:otherwise>${ticket[field.name]}</py:otherwise> 
     168                        </py:choose> 
     169                      </py:otherwise> 
    160170                    </py:choose> 
    161171                  </py:if> 
    162172                </td> 
     
    324334                    </select> 
    325335                    <textarea py:when="'textarea'" id="field-${field.name}" name="field_${field.name}" 
    326336                              cols="${field.width}" rows="${field.height}" 
     337                              class="${field.format == 'wiki' and 'wikitext' or None}" 
    327338                              py:content="value"></textarea> 
    328339                    <span py:when="'checkbox'"> 
    329340                      <input type="checkbox" id="field-${field.name}" name="field_${field.name}" 
  • trac/ticket/tests/api.py

    diff --git a/trac/ticket/tests/api.py b/trac/ticket/tests/api.py
    a b  
    2424        self.env.config.set('ticket-custom', 'test', 'text') 
    2525        self.env.config.set('ticket-custom', 'test.label', 'Test') 
    2626        self.env.config.set('ticket-custom', 'test.value', 'Foo bar') 
     27        self.env.config.set('ticket-custom', 'test.format', 'wiki') 
    2728        fields = TicketSystem(self.env).get_custom_fields() 
    2829        self.assertEqual({'name': 'test', 'type': 'text', 'label': 'Test', 
    29                           'value': 'Foo bar', 'order': 0}, 
     30                          'value': 'Foo bar', 'order': 0, 'format': 'wiki'}, 
    3031                         fields[0]) 
    3132 
    3233    def test_custom_field_select(self): 
     
    5758        self.env.config.set('ticket-custom', 'test.value', 'Foo bar') 
    5859        self.env.config.set('ticket-custom', 'test.cols', '60') 
    5960        self.env.config.set('ticket-custom', 'test.rows', '4') 
     61        self.env.config.set('ticket-custom', 'test.format', 'wiki') 
    6062        fields = TicketSystem(self.env).get_custom_fields() 
    6163        self.assertEqual({'name': 'test', 'type': 'textarea', 'label': 'Test', 
    6264                          'value': 'Foo bar', 'width': 60, 'height': 4, 
    63                           'order': 0}, 
     65                          'order': 0, 'format': 'wiki'}, 
    6466                         fields[0]) 
    6567 
    6668    def test_custom_field_order(self):