Changeset 17530


Ignore:
Timestamp:
Sep 26, 2019, 8:53:37 AM (6 years ago)
Author:
matobaa
Message:

SnapshotPlugin: fix a bug to render with jinja2 template at trac.ticket.template.query_results

Location:
snapshotplugin/0.12
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • snapshotplugin/0.12/COPYING

    r12704 r17530  
    1 Copyright (C) 2012-2013 MATOBA Akihiro <matobaa+trac-hacks@gmail.com>
     1Copyright (C) 2012-2013, 2019 MATOBA Akihiro <matobaa+trac-hacks@gmail.com>
    22All rights reserved.
    33
  • snapshotplugin/0.12/setup.py

    r12524 r17530  
    66setup(
    77    name='Snapshot',
    8     version='0.1',
     8    version='0.2',
    99    license='Modified BSD',
    1010    author='MATOBA Akihiro',
  • snapshotplugin/0.12/snapshot/macro.py

    r16912 r17530  
    22# -*- coding: utf-8 -*-
    33#
    4 # Copyright (C) 2012-2013 MATOBA Akihiro <matobaa+trac-hacks@gmail.com>
     4# Copyright (C) 2012-2013, 2019 MATOBA Akihiro <matobaa+trac-hacks@gmail.com>
    55# All rights reserved.
    66#
     
    99
    1010from genshi.builder import tag
     11from trac import __version__ as VERSION
    1112from trac.core import Component, implements
    1213from trac.ticket.api import TicketSystem
     14from trac.util.presentation import Paginator
    1315from trac.util.translation import _
    1416from trac.web.chrome import Chrome, add_stylesheet
     
    4749            group = ''  # Sentinel
    4850            groups = {}
    49             lines = content.split('\r\n')
     51            lines = content.split('\n')
    5052            for line in lines:
    5153                if line.startswith('||= href =||= '):
     
    8890            #
    8991            data = {
    90                 'paginator': None,
     92                'paginator': Paginator([]),
    9193                'headers': headers,
    9294                'query': query,
     
    9597            }
    9698            add_stylesheet(formatter.req, 'common/css/report.css')
    97             chrome = Chrome(self.env)
    98             data = chrome.populate_data(formatter.req, data)
    99             template = chrome.load_template('query_results.html')
    100             content = template.generate(**data)
    101             # ticket id list as static
    102             tickets = ''
    103             if 'id' in cols:
    104                 ticket_id_list = [ticket.get('id') for group in groups for ticket in group[1]]
    105                 if len(ticket_id_list) > 0:
    106                     tickets = '([ticket:' + ','.join(ticket_id_list) + ' query by ticket id])'
    107             return tag.div(content, format_to_html(self.env, formatter.context, tickets))
     99
     100            if VERSION < '1.3.2':  # Genshi
     101                chrome = Chrome(self.env)
     102                data = chrome.populate_data(formatter.req, data)
     103                template = chrome.load_template('query_results.html')
     104                content = template.generate(**data)
     105                return content
     106            else: # jinja2
     107                return Chrome(self.env).render_fragment(formatter.req, 'query_results.html', data)
    108108        except StopIteration:
    109109            errorinfo = _('Not Enough fields in ticket: %s') % line
  • snapshotplugin/0.12/snapshot/query.py

    r12704 r17530  
    22# -*- coding: utf-8 -*-
    33#
    4 # Copyright (C) 2012-2013 MATOBA Akihiro <matobaa+trac-hacks@gmail.com>
     4# Copyright (C) 2012-2013, 2019 MATOBA Akihiro <matobaa+trac-hacks@gmail.com>
    55# All rights reserved.
    66#
     
    2727    @classmethod
    2828    def formatter(self, obj):
    29         return isinstance(obj, datetime) and format_datetime(obj) or str(obj)
     29        return isinstance(obj, datetime) and format_datetime(obj) or unicode(obj)
    3030
    3131    #ITemplateStreamFilter methods
     
    5454                    ' || '.join([self.formatter(ticket[col]) for col in cols]))
    5555        text += '}}}'
     56        if 'id' in cols:
     57            ticket_id_list = [str(ticket['id']) for ticket in tickets for (_, tickets) in data['groups']]
     58            if len(ticket_id_list) > 0:
     59                text += '\n([ticket:' + ','.join(ticket_id_list) + ' query by ticket id])'
    5660        div = tag.div(tag.input(value='Save as wiki:', type='submit'),
    5761                      tag.input(name='action', value='edit', type='hidden'),
     
    9397            cols_work[cols_work.index('ticket')] = 'id'  # replace 'ticket' to 'id'
    9498        text += '||= href =||= %s\n' % ' =||= '.join(cols_work)
     99        ticket_id_list = []
    95100        for  groupindex, row_group in data.get('row_groups', []):
    96101            text += '|| group: %s\n' % groupindex
     
    103108                text += '|| %s || %s\n' % (ticket['href'],
    104109                    ' || '.join([self.formatter(col, ticket[col]) for col in cols]))
     110                if 'ticket' in ticket:
     111                    ticket_id_list.append(ticket['ticket'])
    105112        text += '}}}'
     113        if len(ticket_id_list) > 0:
     114            text += '\n([ticket:' + ','.join(ticket_id_list) + ' query by ticket id])'
    106115        div = tag.div(tag.input(value='Save as wiki:', type='submit'),
    107116                      tag.input(name='action', value='edit', type='hidden'),
Note: See TracChangeset for help on using the changeset viewer.