def filter_stream(self, req, method, filename, stream, data): # self.list_namespaces() # generate TracLink string resource = None if filename in ['ticket.html', 'wiki_view.html', 'report_view.html', 'milestone_view.html', 'agilo_ticket_view.html'] \ and 'context' in data: resource = copy(data['context'].resource) elif filename in ['search.html']: # search: resource = Resource('search', data['query']) elif filename in ['browser.html']: # source: resource = copy(data['context'].resource) if resource.parent and resource.parent.realm == 'repository': resource.id = '%s/%s' % (resource.parent.id, resource.id) resource.parent = None elif filename in ['revisionlog.html']: # log: resource = copy(data['context'].resource) resource.realm = 'log' if resource.parent and resource.parent.realm == 'repository': resource.id = '%s/%s' % (resource.parent.id, resource.id) resource.parent = None revranges = data.get('revranges', None) rev = data.get('rev', None) if revranges: resource.version = '%s:%s' % (revranges.a, revranges.b) elif rev: resource.version = rev elif filename in ['attachment.html']: if isinstance(data['attachment'], Attachment): # attachment: resource = copy(data['attachment'].resource) else: pass # attachment list page of the ticket; no TracLinks defined elif filename in ['timeline.html']: # timeline: resource = Resource('timeline', format_datetime(data['precisedate'], 'iso8601')) elif filename in ['changeset.html']: if data['changeset']: # changeset: resource = copy(data['context'].resource) if resource.parent and resource.parent.realm == 'repository': resource.id = '%s/%s' % (resource.id, resource.parent.id) # OK, I know resource.parent = None if data['restricted']: resource.id = '%s/%s' % (resource.id, data['new_path']) else: # diff: args = req.args old_path, new_path = args.get('old_path', ''), args.get('new_path', '') old_rev, new_rev = args.get('old'), args.get('new') if old_path == new_path: # diff:path@1:3 style resource = Resource('diff', old_path, '%s:%s' % (old_rev, new_rev)) else: # diff:path@1//path@3 style if old_rev: old_path += '@%s' % old_rev if new_rev: new_path += '@%s' % new_rev resource = Resource('diff', '%s//%s' % (old_path, new_path)) elif filename in ['query.html']: if 'report_resource' in data: resource = copy(data['report_resource']) else: resource = Resource('query', data['query'].to_string().replace("\n", "")[7:]) else: pass # link hash TODO: check wiki_view for agilo if filename in ['browser.html', 'changeset.html', 'ticket.html', 'agilo_ticket_view.html', 'wiki_view.html']: add_script(req, 'traclinks/js/jquery.ba-hashchange.js') add_script(req, 'traclinks/js/onhashchange.js') # if resource: traclinks = '%s' % (resource.id) if resource.version != None: traclinks += (resource.realm == 'ticket' and '?version=%s' or '@%s') % resource.version parent = resource.parent while parent and parent.id: traclinks += ':%s:%s' % (parent.realm, parent.id) if parent.version != None: traclinks += '@%s' % parent.version parent = parent.parent if ' ' in traclinks: traclinks = '"%s"' % traclinks # surround quote if needed traclinks = '%s:%s' % (resource.realm, traclinks) # new ticket template if resource.id == None and resource.realm == 'ticket': query_string = unicode_urlencode( [(k, v) for k, v in data['ticket'].values.iteritems() if v not in (None, '')]) traclinks = '[/newticket?%s]' % query_string #return stream | Transformer('//input[@id="proj-search"]').attr('placeholder', traclinks).attr('size', '50') _input = tag.input(value=traclinks, readonly='', style=self.style) div = tag.div(_input, id="banner-traclink", style="float:right") return stream | Transformer('//div[@id="header"]').before(div) return stream
def filter_stream(self, req, method, filename, stream, data): # self.list_namespaces() # generate TracLink string resource = None if filename in ['ticket.html', 'wiki_view.html', 'report_view.html', 'milestone_view.html', 'agilo_ticket_view.html'] \ and 'context' in data: resource = data['context'].resource elif filename in ['search.html']: # search: resource = Resource('search', data['query']) elif filename in ['browser.html']: # source: resource = data['context'].resource if resource.parent and resource.parent.realm == 'repository': resource.id = '%s/%s' % (resource.parent.id, resource.id) resource.parent = None elif filename in ['revisionlog.html']: # log: resource = data['context'].resource resource.realm = 'log' if resource.parent and resource.parent.realm == 'repository': resource.id = '%s/%s' % (resource.parent.id, resource.id) resource.parent = None revranges = data.get('revranges', None) rev = data.get('rev', None) if revranges: resource.version = '%s:%s' % (revranges.a, revranges.b) elif rev: resource.version = rev elif filename in ['attachment.html']: if isinstance(data['attachment'], Attachment): # attachment: resource = data['attachment'].resource else: pass # attachment list page of the ticket; no TracLinks defined elif filename in ['timeline.html']: # timeline: resource = Resource( 'timeline', format_datetime(data['precisedate'], 'iso8601')) elif filename in ['changeset.html']: if data['changeset']: # changeset: resource = data['context'].resource if resource.parent and resource.parent.realm == 'repository': resource.id = '%s/%s' % (resource.id, resource.parent.id ) # OK, I know resource.parent = None if data['restricted']: resource.id = '%s/%s' % (resource.id, data['new_path']) else: # diff: args = req.args old_path, new_path = args.get('old_path', ''), args.get('new_path', '') old_rev, new_rev = args.get('old'), args.get('new') if old_path == new_path: # diff:path@1:3 style resource = Resource('diff', old_path, '%s:%s' % (old_rev, new_rev)) else: # diff:path@1//path@3 style if old_rev: old_path += '@%s' % old_rev if new_rev: new_path += '@%s' % new_rev resource = Resource('diff', '%s//%s' % (old_path, new_path)) elif filename in ['query.html']: if 'report_resource' in data: resource = data['report_resource'] else: resource = Resource( 'query', data['query'].to_string().replace("\n", "")[7:]) else: pass # link hash TODO: check wiki_view for agilo if filename in [ 'browser.html', 'ticket.html', 'agilo_ticket_view.html', 'wiki_view.html' ]: add_script(req, 'traclinks/js/jquery.ba-hashchange.js') add_script(req, 'traclinks/js/onhashchange.js') # if resource: traclinks = '%s' % (resource.id) if resource.version != None: traclinks += (resource.realm == 'ticket' and '?version=%s' or '@%s') % resource.version if resource.parent and resource.parent.id: traclinks += ':%s:%s' % (resource.parent.realm, resource.parent.id) if resource.parent.version != None: traclinks += '@%s' % resource.parent.version if ' ' in traclinks: traclinks = '"%s"' % traclinks # surround quote if needed traclinks = '%s:%s' % (resource.realm, traclinks) # new ticket template if resource.id == None and resource.realm == 'ticket': query_string = unicode_urlencode([ (k, v) for k, v in data['ticket'].values.iteritems() if v not in (None, '') ]) traclinks = '[/newticket?%s]' % query_string return stream | Transformer('//input[@id="proj-search"]').attr( 'value', traclinks).attr('size', '50') return stream