source: ticketsidebarproviderplugin/0.11/ticketsidebarprovider/ticketsidebar.py

Last change on this file was 11697, checked in by Steffen Hoffmann, 11 years ago

TicketSidebarProviderPlugin: Non-maintainer change applying old patch, refs #7428.

As proposed by Dennis McRitchie, CSS definitions for this plugin should only
be added if required (ticketsidebar.py.patch).

I couldn't detect a positive effect from this change alone, but no negative
side-effects either, so this is more an excuse for a small code clean-up;
tested with Trac 0.13-r10880.

File size: 2.4 KB
RevLine 
[5529]1"""
2TicketSidebarProvider
3a plugin for Trac to provide content alongside the ticket
4http://trac.edgewall.org/wiki/TracTicketsCustomFields
5"""
6
7from genshi.builder import tag
8from genshi.filters import Transformer
[11697]9from pkg_resources import resource_filename
[5529]10
11from trac.config import Option
12from trac.core import *
13from trac.web.api import ITemplateStreamFilter
14from trac.web.chrome import add_stylesheet
15from trac.web.chrome import ITemplateProvider
16
[11697]17from ticketsidebarprovider.interface import ITicketSidebarProvider
18
19
[5529]20class TicketSidebarProvider(Component):
21
22    implements(ITemplateStreamFilter, ITemplateProvider)
[11697]23
[5529]24    providers = ExtensionPoint(ITicketSidebarProvider)
25
26    ### method for ITemplateStreamFilter :
27    ### Filter a Genshi event stream prior to rendering.
28
29    def filter_stream(self, req, method, filename, stream, data):
30        """Return a filtered Genshi event stream, or the original unfiltered
31        stream if no match.
32
33        `req` is the current request object, `method` is the Genshi render
34        method (xml, xhtml or text), `filename` is the filename of the template
35        to be rendered, `stream` is the event stream and `data` is the data for
36        the current template.
37
38        See the Genshi documentation for more information.
39        """
40
41        if filename != 'ticket.html':
42            return stream
43
44        ticket = data['ticket']
45        for provider in self.providers: # TODO : sorting
46            if provider.enabled(req, ticket):
[11697]47                add_stylesheet(req, 'common/css/ticket-sidebar.css')
48                filter = Transformer('//div[@id="content"]')
49                stream |= filter.after(tag.div(provider.content(req, ticket),
50                                               **{'class': "sidebar" }))
[5529]51        return stream
52
53    def get_htdocs_dirs(self):
54        """Return a list of directories with static resources (such as style
55        sheets, images, etc.)
56
57        Each item in the list must be a `(prefix, abspath)` tuple. The
58        `prefix` part defines the path in the URL that requests to these
59        resources are prefixed with.
60       
61        The `abspath` is the absolute path to the directory containing the
62        resources on the local file system.
63        """
64        return [('common', resource_filename(__name__, 'htdocs'))]
65
66    def get_templates_dirs(self):
67        """Return a list of directories containing the provided template
68        files.
69        """
70        return []
Note: See TracBrowser for help on using the repository browser.