def process_request(self, req): from tractags.api import TagEngine from trac.web.chrome import add_stylesheet add_stylesheet(req, 'tags/css/tractags.css') pagename = req.args.get('page', 'WikiStart') action = req.args.get('action', 'view') engine = TagEngine(self.env) wikitags = engine.tagspace.wiki tags = list(wikitags.get_tags([pagename])) tags.sort() if action == 'edit': req.hdf['tags'] = req.args.get('tags', ', '.join(tags)) elif action == 'view': hdf_tags = [] for tag in tags: href, title = engine.get_tag_link(tag) hdf_tags.append({'name': tag, 'href': href, 'title': title}) req.hdf['tags'] = hdf_tags result = WikiModule.process_request(self, req) if result is None: return None if result[0] == 'wiki.cs': return 'tagswiki.cs', None return result
def process_stream(self, req, stream, method): page_name = req.path_info[6:] or 'WikiStart' tags = TagEngine(self.env).tagspace.wiki.get_tags([page_name]) action = req.args.get('action', 'view') if action == 'edit': return self._process_edit(req, stream, method, tags) elif action == 'view': return self._process_view(req, stream, method, tags)
def _prepare_wiki(self, req): from tractags.api import TagEngine page = req.path_info[6:] or 'WikiStart' engine = TagEngine(self.env) wikitags = engine.tagspace.wiki tags = list(wikitags.get_tags(page)) tags.sort() action = req.args.get('action', 'view') if action == 'edit': req.hdf['tags'] = req.args.get('tags', ', '.join(tags)) elif action == 'view': hdf_tags = [] for tag in tags: href, title = engine.get_tag_link(tag) hdf_tags.append({'name': tag, 'href': href, 'title': title}) req.hdf['tags'] = hdf_tags
def _do_save(self, req, db, page): # This method is overridden so the user doesn't get "Page not modified" # exceptions when updating tags but not wiki content. from tractags.api import TagEngine if 'tags' in req.args: newtags = set([t.strip() for t in _tag_split.split(req.args.get('tags')) if t.strip()]) wikitags = TagEngine(self.env).tagspace.wiki oldtags = wikitags.get_tags([page.name]) if oldtags != newtags: wikitags.replace_tags(req, page.name, newtags) # No changes, just redirect if req.args.get('text') == page.text: req.redirect(self.env.href.wiki(page.name)) return return WikiModule._do_save(self, req, db, page)
def _do_save(self, req, db, page): # This method is overridden so the user doesn't get "Page not modified" # exceptions when updating tags but not wiki content. from tractags.api import TagEngine if 'tags' in req.args: newtags = set([ t.strip() for t in _tag_split.split(req.args.get('tags')) if t.strip() ]) wikitags = TagEngine(self.env).tagspace.wiki oldtags = wikitags.get_tags([page.name]) if oldtags != newtags: wikitags.replace_tags(req, page.name, newtags) # No changes, just redirect if req.args.get('text') == page.text: req.redirect(self.env.href.wiki(page.name)) return return WikiModule._do_save(self, req, db, page)
def pre_process_request(self, req, handler): tags = req.args.get('tags') if isinstance(handler, WikiModule): add_stylesheet(req, 'tags/css/tractags.css') if req.method == 'POST' and tags is not None: page_name = req.path_info[6:] or 'WikiStart' new_tags = set( [t.strip() for t in tags.split(',') if t.strip()]) old_tags = TagEngine(self.env).tagspace.wiki.get_tags( [page_name]) if old_tags != new_tags: TagEngine(self.env).tagspace.wiki.replace_tags( req, page_name, new_tags) if req.args.get('text') == WikiPage(self.env, page_name).text: # The wiki module would think this is wasn't changed, # so redirect around it. req.redirect(req.href.wiki(page_name)) return handler
def tag_data(): engine = TagEngine(self.env) for t in tags: href, title = engine.get_tag_link(t) yield t, href, title