def get_backlinks(environ, tiddler): """ Extract the current backlinks for this tiddler. """ from tiddlywebplugins.links.linksmanager import LinksManager store = environ['tiddlyweb.store'] usersign = environ['tiddlyweb.usersign'] links_manager = LinksManager(environ) links = links_manager.read_backlinks(tiddler) back_tiddlers = [] def _is_readable(tiddler): try: bag = store.get(Bag(tiddler.bag)) bag.policy.allows(usersign, 'read') return True except (NoBagError, PermissionsError): return False for link in links: container, title = link.split(':', 1) tiddler = Tiddler(title, container) if _is_readable(tiddler): back_tiddlers.append(tiddler) return back_tiddlers
def tiddler_put_hook(store, tiddler): """ Update the links database with data from this tiddler. """ links_manager = LinksManager(store.environ) links_manager.delete_links(tiddler) if _is_parseable(tiddler): links_manager.update_database(tiddler)
def tiddler_change_hook(store, tiddler): """ Update the links database with data from this tiddler. TODO: work with other renderable types, not just tiddlywiki text. """ links_manager = LinksManager(store.environ) links_manager.delete_links(tiddler) if not tiddler.type or tiddler.type == 'None': links_manager.update_database(tiddler)
def refreshlinksdb(args): """Refresh the back and front links database.""" store = get_store(config) links_manager = LinksManager(store.environ) for bag in store.list_bags(): LOGGER.debug('updating links for tiddlers in bag: %s', bag.name) for tiddler in store.list_bag_tiddlers(bag): tiddler = store.get(tiddler) # we must get text links_manager.delete_links(tiddler) if _is_parseable(tiddler): links_manager.update_database(tiddler)
def get_backlinks(environ, tiddler): """ Extract the current backlinks for this tiddler. """ store = environ['tiddlyweb.store'] usersign = environ['tiddlyweb.usersign'] links_manager = LinksManager(environ) links = links_manager.read_backlinks(tiddler) back_tiddlers = [] for link in links: container, title = link.split(':', 1) tiddler = Tiddler(title, container) if _is_readable(store, usersign, tiddler): back_tiddlers.append(tiddler) return back_tiddlers
def tiddler_delete_hook(store, tiddler): """ Remove links data associated with deleted tiddler. """ links_manager = LinksManager(store.environ) links_manager.delete_links(tiddler)