|
1 |
| -from trac.core import Component, implements |
2 |
| -from trac.web.chrome import INavigationContributor |
3 |
| -from trac.web.api import IRequestFilter, IRequestHandler |
4 |
| -from trac.wiki.web_ui import WikiModule |
5 |
| -from trac.util import Markup |
6 |
| -from trac.util.html import tag |
7 |
| -from tracext.github import GitHubBrowser |
8 |
| - |
9 |
| - |
10 |
| -class CustomTheme(Component): |
11 |
| - implements(IRequestFilter) |
12 |
| - |
13 |
| - def pre_process_request(self, req, handler): |
14 |
| - return handler |
15 |
| - |
16 |
| - def post_process_request(self, req, template, data, metadata): |
17 |
| - req.chrome["theme"] = "django_theme.html" |
18 |
| - return template, data, metadata |
19 |
| - |
20 |
| - |
21 |
| -class CustomWikiModule(WikiModule): |
22 |
| - """Works in combination with the CustomNavigationBar and replaces |
23 |
| - the default wiki module. Has a different logic for active item |
24 |
| - handling. |
25 |
| - """ |
26 |
| - |
27 |
| - def get_active_navigation_item(self, req): |
28 |
| - pagename = req.args.get("page") |
29 |
| - if pagename == "Reports": |
30 |
| - return "custom_reports" |
31 |
| - return "wiki" |
32 |
| - |
33 |
| - |
34 |
| -class CustomNewTicket(Component): |
35 |
| - """Hide certain options for the new ticket page""" |
36 |
| - |
37 |
| - implements(IRequestFilter, IRequestHandler) |
38 |
| - hidden_fields = frozenset( |
39 |
| - ["stage", "needs_tests", "needs_docs", "needs_better_patch"] |
40 |
| - ) |
41 |
| - |
42 |
| - def match_request(self, req): |
43 |
| - return req.path_info == "/simpleticket" |
44 |
| - |
45 |
| - def process_request(self, req): |
46 |
| - req.redirect(req.href.newticket()) |
47 |
| - |
48 |
| - def pre_process_request(self, req, handler): |
49 |
| - return handler |
50 |
| - |
51 |
| - def post_process_request(self, req, template, data, metadata): |
52 |
| - if data is None: |
53 |
| - data = {} |
54 |
| - if req.path_info == "/newticket" and not data.get("preview_mode", False): |
55 |
| - simple_interface = "TICKET_BATCH_MODIFY" not in req.perm |
56 |
| - if simple_interface and "fields" in data: |
57 |
| - data["fields"] = [ |
58 |
| - f for f in data["fields"] if f["name"] not in self.hidden_fields |
59 |
| - ] |
60 |
| - data["simple_interface"] = simple_interface |
61 |
| - template = "custom_ticket.html" |
62 |
| - return template, data, metadata |
63 |
| - |
64 |
| - |
65 |
| -class CustomNavigationBar(Component): |
66 |
| - """Implements some more items for the navigation bar.""" |
67 |
| - |
68 |
| - implements(INavigationContributor) |
69 |
| - |
70 |
| - def get_active_navigation_item(self, req): |
71 |
| - return "custom_reports" |
72 |
| - |
73 |
| - def get_navigation_items(self, req): |
74 |
| - return [ |
75 |
| - ( |
76 |
| - "mainnav", |
77 |
| - "custom_reports", |
78 |
| - Markup('<a href="%s">Reports</a>' % req.href.wiki("Reports")), |
79 |
| - ), |
80 |
| - ] |
81 |
| - |
82 |
| - |
83 |
| -class GitHubBrowserWithSVNChangesets(GitHubBrowser): |
84 |
| - def _format_changeset_link(self, formatter, ns, chgset, label, fullmatch=None): |
85 |
| - # Dead-simple version for SVN changesets. |
86 |
| - if chgset.isnumeric(): |
87 |
| - href = formatter.href.changeset(chgset, None, "/") |
88 |
| - return tag.a(label, class_="changeset", href=href) |
89 |
| - |
90 |
| - # Fallback to the default implementation. |
91 |
| - return super(GitHubBrowserWithSVNChangesets, self)._format_changeset_link( |
92 |
| - formatter, ns, chgset, label, fullmatch |
93 |
| - ) |
0 commit comments