def post_process_request(self, req, template, data, content_type): if data and req.path_info == '/timeline' and \ 'TAGS_VIEW' in req.perm(Resource('tags')): def realm_handler(_, node, context): return query.match(node, [context.realm]) query_str = req.args.getfirst(self.key) if query_str is None and req.args.get('format') != 'rss': query_str = req.session.get('timeline.%s' % self.key) else: query_str = (query_str or '').strip() # Record tag query expression between visits. req.session['timeline.%s' % self.key] = query_str if data.get('events') and query_str: tag_system = TagSystem(self.env) try: query = Query(query_str, attribute_handlers={'realm': realm_handler}) except InvalidQuery as e: add_warning(req, _("Tag query syntax error: %s" % e)) else: all_realms = tag_system.get_taggable_realms(req.perm) query_realms = set() for m in REALM_RE.finditer(query.as_string()): query_realms.add(m.group(1)) # Don't care about resources from non-taggable realms. realms = not query_realms and all_realms or \ query_realms.intersection(all_realms) events = [] self.log.info("Filtering timeline events by tags '%s'", query_str) for event in data['events']: resource = resource_from_event(event) if resource and resource.realm in realms: # Shortcut view permission checks here. tags = tag_system.get_tags(None, resource) if query(tags, context=resource): events.append(event) # Overwrite with filtered list. data['events'] = events if query_str: # Add current value for next form rendering. data[self.key] = query_str elif self.key in req.session: del req.session[self.key] filter_lst = [] # xpath = '//form[@id="prefs"]/div[1]' xform = JTransformer('form#prefs > div:nth-of-type(1)') insert = builder(Markup('<br />'), tag_("matching tags "), builder.input(type='text', name=self.key, value=data.get(self.key))) filter_lst.append(xform.append(Markup(insert))) add_script_data(req, {'tags_filter': filter_lst}) add_script(req, 'tags/js/tags_jtransform.js') return template, data, content_type
def filter_stream(self, req, method, filename, stream, data): if req.path_info == '/timeline': insert = builder(Markup('<br />'), tag_("matching tags "), builder.input(type='text', name=self.key, value=data.get(self.key))) xpath = '//form[@id="prefs"]/div[1]' stream = stream | Transformer(xpath).append(insert) return stream
def render_timeline_event(self, context, field, event): resource = event[3][0] if field == 'url': return get_resource_url(self.env, resource, context.href) elif field == 'title': name = builder.em(get_resource_name(self.env, resource)) return tag_("Tag change on %(resource)s", resource=name) elif field == 'description': return render_tag_changes(event[3][1], event[3][2])
def render_timeline_event(self, context, field, event): resource = event[3][0] if field == 'url': return get_resource_url(self.env, resource, context.href) elif field == 'title': name = builder.em(get_resource_name(self.env, resource)) return tag_("Tag change on %(resource)s", resource=name) elif field == 'description': return render_tag_changes(event[3][1], event[3][2])
def filter_stream(self, req, method, filename, stream, data): if req.path_info == '/timeline': insert = builder( Markup('<br />'), tag_("matching tags "), builder.input(type='text', name=self.key, value=data.get(self.key))) xpath = '//form[@id="prefs"]/div[1]' stream = stream | Transformer(xpath).append(insert) return stream
def get_navigation_items(self, req): if 'TAGS_VIEW' in req.perm: label = tag_("Tags") yield ('mainnav', 'tags', builder.a(label, href=req.href.tags(), accesskey='T'))
def get_navigation_items(self, req): if 'TAGS_VIEW' in req.perm: label = tag_("Tags") yield ('mainnav', 'tags', builder.a(label, href=req.href.tags(), accesskey='T'))
def get_navigation_items(self, req): if "TAGS_VIEW" in req.perm: label = tag_("Tags") yield ("mainnav", "tags", builder.a(label, href=req.href.tags(), accesskey="T"))