Modify

Opened 9 years ago

Closed 9 years ago

#12385 closed defect (fixed)

[PATCH] Plugin breaks stream for subsequent plugins

Reported by: Cinc-th Owned by: falkb
Priority: normal Component: ComponentHierarchyPlugin
Severity: normal Keywords:
Cc: Trac Release: 0.12

Description

The line

...
html_stream = HTML(stream)
...

in filter_stream() prevents subsequent plugins from adding stylesheets using add_stylesheet(). As soon as one uses HTML() on a stream this happens. I didn't find the cause for that.

For testing just insert add_stylesheet(req, "foo.css"):

    def filter_stream(self, req, method, filename, stream, data):

        if req.path_info.startswith('/admin/ticket/components/'):
            trans = Transformer('//form[@id="modcomp"]/fieldset/div[1]')
            stream = stream | trans.after(self._parent_component_select(req, data)) 

        elif req.path_info.startswith('/admin/ticket/components'):
            # add a "parent component" column to the components table
            stream = stream | Transformer('//table[@id="complist"]/thead/tr/th[3]').after(tag.th("Parent"))

            html_stream = HTML(stream)
            # Try adding a stylesheet here
            add_stylesheet(req, "foo.css")
            html_comp_list = HTML(html_stream.select('//table[@id="complist"]/tbody'))
            
            return html_stream | Transformer('//table[@id="complist"]/tbody').replace(self._insert_parent_column(html_comp_list))
                            
        return stream

You'll notice that foo.css isn't included as a link in the web page delivered by Trac (use the developer tools of your browser, or just look at the head section of the page source).

I suspect the stream is altered in a way that Trac can't inject the link when preparing the page. I noticed that this statement causes XML namespace information to vanish from tag data in the stream when fixing a compatibility problem with SimpleMultiProjectPlugin, see #12367, [14639].

The attached patch uses another method to insert the parent column into the table. This fixes this problem for me.

Attachments (4)

admin.diff (4.3 KB) - added by Cinc-th 9 years ago.
Patch for adding parent column using injector transformation.
admin.py (5.4 KB) - added by Cinc-th 9 years ago.
File admin.py with patch applied.
admin-2.diff (4.3 KB) - added by Cinc-th 9 years ago.
Revised patch which inserts a parent column even for components without a name.
admin-3.diff (4.3 KB) - added by Cinc-th 9 years ago.
Add the correct CSS class to empty table cells, too

Download all attachments as: .zip

Change History (11)

Changed 9 years ago by Cinc-th

Attachment: admin.diff added

Patch for adding parent column using injector transformation.

Changed 9 years ago by Cinc-th

Attachment: admin.py added

File admin.py with patch applied.

comment:1 Changed 9 years ago by Cinc-th

Trac Release: 0.12

comment:2 Changed 9 years ago by falkb

Status: newaccepted

Thanks! Seems to work properly. Lets see what the activities in sibling ticket #12367 will still bring, and if they may change this patch again...

comment:3 Changed 9 years ago by Cinc-th

Revised patch which inserts a parent column even for components without a name. Should finally fix #12367, too.

Changed 9 years ago by Cinc-th

Attachment: admin-2.diff added

Revised patch which inserts a parent column even for components without a name.

Changed 9 years ago by Cinc-th

Attachment: admin-3.diff added

Add the correct CSS class to empty table cells, too

comment:4 Changed 9 years ago by falkb

Thanks! Could you attach the whole .py file, please? I'm doing this in parallel to other urgent things, so it would ease things here :)

comment:5 Changed 9 years ago by falkb

Yeah, in combination with [14640] of SimpleMultiProjectPlugin, it works properly now with admin-3.diff. Many thanks!!

Last edited 9 years ago by falkb (previous) (diff)

comment:6 Changed 9 years ago by falkb

In 14642:

see #12385: no mixed up columns on Admin->components page anymore for the case when SimpleMultiProjectPlugin also injects a new column into the HTML stream (Thanks to Cinc-th!)

comment:7 Changed 9 years ago by falkb

Resolution: fixed
Status: acceptedclosed

Tested and great.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain falkb.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.