source: peerreviewplugin/trunk/codereview/report.py

Last change on this file was 18261, checked in by Cinc-th, 2 years ago

PeerReviewPlugin: no longer use CamelCase URLs. Fixed a testcase using unicode strings for Python3.

Refs #14005

File size: 2.4 KB
RevLine 
[15496]1# -*- coding: utf-8 -*-
2#
[18242]3# Copyright (C) 2016-2021 Cinc
[15496]4# All rights reserved.
5#
6# This software is licensed as described in the file COPYING.txt, which
7# you should have received as part of this distribution.
8#
9# Author: Cinc
10#
11
12from trac.core import Component, implements
[18242]13from trac.web.chrome import add_stylesheet, Chrome, INavigationContributor
[15496]14from trac.web.main import IRequestHandler
[17442]15from codereview.peerReviewMain import add_ctxt_nav_items
[15496]16
17
18class PeerReviewReport(Component):
[17265]19    """Show a page with reports for getting data from code reviews.
20
21    [[BR]]
22    Code review reports are normal Trac SQL reports. A report will be shown on the code review report page when the
23    report description starts with the following comment:
24
25    {{{
26    {{{
27    #!comment
28    codereview=1
29    }}}
30    }}}
31    """
[15496]32    implements(INavigationContributor, IRequestHandler)
33
34    # INavigationContributor methods
35
36    def get_active_navigation_item(self, req):
[18261]37        return 'peerreviewmain'
[15496]38
39    def get_navigation_items(self, req):
40        return
41
42    # IRequestHandler methods
43
44    def match_request(self, req):
45        return req.path_info == '/peerreviewreport'
46
47    def process_request(self, req):
48        def is_codereview_report(desc):
49            """Check if wiki comment section holds 'codereview = 1' as first line."""
50            lst = desc.splitlines()
51            if '{{{' not in lst or '}}}' not in lst or '#!comment' not in lst:
52                return False
[17442]53            lst = lst[lst.index('#!comment') + 1: lst.index('}}}')]  # contents of comment section
[15496]54            if ''.join(lst[0].split()) == 'codereview=1':
55                return True
56            return False
57
58        req.perm.require('CODE_REVIEW_DEV')
59
60        reports = []
[17442]61        for row in self.env.db_query("SELECT id, title, description FROM report"):
[15496]62            if is_codereview_report(row[2]):
63                reports.append({
64                    'id': row[0],
65                    'title': row[1],
66                    'desc': row[2]
67                })
68
69        data = {
70            'reports': reports
71        }
72
73        add_stylesheet(req, 'common/css/report.css')
74        add_ctxt_nav_items(req)
[18242]75
76        if hasattr(Chrome, 'jenv'):
77            return 'peerreview_report_jinja.html', data
78        else:
79            return 'peerreview_report.html', data, None
Note: See TracBrowser for help on using the repository browser.