def list_tiddlers(self, tiddlers): """ Turn the contents of a Tiddlers into an Atom Feed. """ authors = set() try: from tiddlyweb.model.collections import Tiddlers config = self.environ['tiddlyweb.config'] default_filter = config['atom.default_filter'] filters, _ = parse_for_filters(default_filter, self.environ) new_tiddlers = Tiddlers() new_tiddlers.is_search = tiddlers.is_search new_tiddlers.is_revisions = tiddlers.is_revisions new_tiddlers.bag = tiddlers.bag new_tiddlers.recipe = tiddlers.recipe new_tiddlers.link = tiddlers.link for tiddler in recursive_filter(filters, tiddlers): new_tiddlers.add(tiddler) authors.add(tiddler.modifier) new_tiddlers.title = tiddlers.title new_tiddlers.is_search = tiddlers.is_search new_tiddlers.is_revisions = tiddlers.is_revisions tiddlers = new_tiddlers except (KeyError, ImportError): pass author_name = None author_link = None author_avatar = None if len(authors) == 1: author_name = authors.pop() author_link = self._get_author_link(author_name) author_avatar = self._get_author_avatar(author_name) hub = self.environ.get('tiddlyweb.config', {}).get('atom.hub', None) if tiddlers.link: link = tiddlers.link else: link = self._current_url() if not link.startswith('http'): link = u'%s%s' % (self._host_url(), link) feed = AtomFeed(link=link, language=u'en', hub=hub, author_name=author_name, author_link=author_link, author_avatar=author_avatar, title=tiddlers.title, description=tiddlers.title) for tiddler in tiddlers: self._add_tiddler_to_feed(feed, tiddler) # can we avoid sending utf-8 and let the wrapper handle it? return feed.writeString('utf-8')
def get(environ, start_response): """ Perform a search on the store. What search means and what results are returned is dependent on the search implementation (if any) in the chosen store. """ store = environ['tiddlyweb.store'] search_query = get_search_query(environ) title = 'Search for %s' % search_query title = environ['tiddlyweb.query'].get('title', [title])[0] try: tiddlers = get_tiddlers(environ) usersign = environ['tiddlyweb.usersign'] candidate_tiddlers = Tiddlers(title=title, store=store) candidate_tiddlers.is_search = True for tiddler in readable_tiddlers_by_bag(store, tiddlers, usersign): candidate_tiddlers.add(tiddler) except StoreMethodNotImplemented: raise HTTP400('Search system not implemented') except StoreError, exc: raise HTTP400('Error while processing search: %s' % exc)
def send_tiddlers(environ, start_response, tiddlers=None): """ Output the tiddlers contained in the provided Tiddlers collection in a Negotiated representation. Often, but not always, a wiki. """ last_modified = None etag = None download = environ['tiddlyweb.query'].get('download', [None])[0] filters = environ['tiddlyweb.filters'] store = environ['tiddlyweb.store'] if tiddlers.store is None and not filters: logging.warn('Incoming tiddlers no store set %s', inspect.stack()[1]) if filters: candidate_tiddlers = Tiddlers(store=store) try: candidate_tiddlers.title = tiddlers.title candidate_tiddlers.link = tiddlers.link candidate_tiddlers.is_search = tiddlers.is_search candidate_tiddlers.is_revisions = tiddlers.is_revisions except AttributeError: pass try: for tiddler in recursive_filter(filters, tiddlers): candidate_tiddlers.add(tiddler) except FilterError, exc: raise HTTP400('malformed filter: %s' % exc)
def send_tiddlers(environ, start_response, tiddlers=None): """ Output the tiddlers contained in the provided Tiddlers collection in a Negotiated representation. Often, but not always, a wiki. """ last_modified = None etag = None download = environ['tiddlyweb.query'].get('download', [None])[0] filters = environ['tiddlyweb.filters'] store = environ['tiddlyweb.store'] if filters: candidate_tiddlers = Tiddlers(store=store) try: candidate_tiddlers.title = tiddlers.title candidate_tiddlers.is_search = tiddlers.is_search candidate_tiddlers.is_revisions = tiddlers.is_revisions except AttributeError: pass try: for tiddler in recursive_filter(filters, tiddlers): recipe = tiddler.recipe if not tiddler.store: tiddler = store.get(tiddler) if recipe: tiddler.recipe = recipe candidate_tiddlers.add(tiddler) except FilterError, exc: raise HTTP400('malformed filter: %s' % exc)
def send_tiddlers(environ, start_response, tiddlers=None): """ Output the tiddlers contained in the provided Tiddlers collection in a Negotiated representation. Often, but not always, a wiki. """ last_modified = None etag = None download = environ['tiddlyweb.query'].get('download', [None])[0] filters = environ['tiddlyweb.filters'] store = environ['tiddlyweb.store'] if filters: candidate_tiddlers = Tiddlers(store=store) try: candidate_tiddlers.title = tiddlers.title candidate_tiddlers.is_search = tiddlers.is_search candidate_tiddlers.is_revisions = tiddlers.is_revisions except AttributeError: pass try: for tiddler in recursive_filter(filters, tiddlers): recipe = tiddler.recipe if not tiddler.store: tiddler = store.get(tiddler) if recipe: tiddler.recipe = recipe candidate_tiddlers.add(tiddler) except FilterError, exc: raise HTTP400('malformed filter: %s' % exc)
def whoosher_search(environ, start_response): store = environ['tiddlyweb.store'] filters = environ['tiddlyweb.filters'] search_query = get_search_query(environ) title = 'Search for %s' % search_query title = environ['tiddlyweb.query'].get('title', [title])[0] try: tiddlers = whoosh_search(environ) usersign = environ['tiddlyweb.usersign'] if filters: candidate_tiddlers = Tiddlers(title=title) else: candidate_tiddlers = Tiddlers(title=title, store=store) candidate_tiddlers.is_search = True for tiddler in readable_tiddlers_by_bag(store, tiddlers, usersign): candidate_tiddlers.add(tiddler) except StoreMethodNotImplemented: raise HTTP400('Search system not implemented') except StoreError as exc: raise HTTP400('Error while processing search: %s' % exc) return send_tiddlers(environ, start_response, tiddlers=candidate_tiddlers)
def send_tiddlers(environ, start_response, tiddlers=None): """ Output the tiddlers contained in the provided Tiddlers collection in a Negotiated representation. Often, but not always, a wiki. """ last_modified = None etag = None download = environ['tiddlyweb.query'].get('download', [None])[0] filters = environ['tiddlyweb.filters'] store = environ['tiddlyweb.store'] if tiddlers.store is None and not filters: logging.warn('Incoming tiddlers no store set %s', inspect.stack()[1]) if filters: candidate_tiddlers = Tiddlers(store=store) try: candidate_tiddlers.title = tiddlers.title candidate_tiddlers.link = tiddlers.link candidate_tiddlers.is_search = tiddlers.is_search candidate_tiddlers.is_revisions = tiddlers.is_revisions except AttributeError: pass try: for tiddler in recursive_filter(filters, tiddlers): candidate_tiddlers.add(tiddler) except FilterError, exc: raise HTTP400('malformed filter: %s' % exc)
def _filter_tiddlers(filters, store, tiddlers): """ Filter the tiddlers by filters provided by the enviornment. """ candidate_tiddlers = Tiddlers(store=store) try: candidate_tiddlers.title = tiddlers.title candidate_tiddlers.link = tiddlers.link candidate_tiddlers.is_search = tiddlers.is_search candidate_tiddlers.is_revisions = tiddlers.is_revisions candidate_tiddlers.bag = tiddlers.bag candidate_tiddlers.recipe = tiddlers.recipe except AttributeError: pass try: for tiddler in recursive_filter(filters, tiddlers): candidate_tiddlers.add(tiddler) except FilterError, exc: raise HTTP400('malformed filter: %s' % exc)
def _filter_tiddlers(filters, store, tiddlers): """ Filter the tiddlers by filters provided by the environment. """ candidate_tiddlers = Tiddlers(store=store) try: candidate_tiddlers.title = tiddlers.title candidate_tiddlers.link = tiddlers.link candidate_tiddlers.is_search = tiddlers.is_search candidate_tiddlers.is_revisions = tiddlers.is_revisions candidate_tiddlers.bag = tiddlers.bag candidate_tiddlers.recipe = tiddlers.recipe except AttributeError: pass try: for tiddler in recursive_filter(filters, tiddlers): candidate_tiddlers.add(tiddler) except FilterError as exc: raise HTTP400('malformed filter: %s' % exc) return candidate_tiddlers
def get(environ, start_response): """ Perform a search on the store. What search means and what results are returned is dependent on the search implementation (if any) in the chosen store. """ store = environ['tiddlyweb.store'] search_query = get_search_query(environ) title = 'Search for %s' % search_query title = environ['tiddlyweb.query'].get('title', [title])[0] try: tiddlers = get_tiddlers(environ) usersign = environ['tiddlyweb.usersign'] candidate_tiddlers = Tiddlers(title=title, store=store) candidate_tiddlers.is_search = True bag_readable = {} for tiddler in tiddlers: try: if bag_readable[tiddler.bag]: candidate_tiddlers.add(tiddler) except KeyError: bag = Bag(tiddler.bag) bag = store.get(bag) try: bag.policy.allows(usersign, 'read') candidate_tiddlers.add(tiddler) bag_readable[tiddler.bag] = True except(ForbiddenError, UserRequiredError): bag_readable[tiddler.bag] = False except StoreMethodNotImplemented: raise HTTP400('Search system not implemented') except StoreError, exc: raise HTTP400('Error while processing search: %s' % exc)
def get(environ, start_response): """ Handle ``GET`` on the search URI. Perform a search against the :py:class:`store <tiddlyweb.store.Store>`. What search means and what results are returned is dependent on the search implementation (if any) in the :py:class:`chosen store <tiddlyweb.stores.StorageInterface>`. """ store = environ['tiddlyweb.store'] filters = environ['tiddlyweb.filters'] search_query = get_search_query(environ) title = 'Search for %s' % search_query title = environ['tiddlyweb.query'].get('title', [title])[0] try: tiddlers = get_tiddlers(environ) usersign = environ['tiddlyweb.usersign'] if filters: candidate_tiddlers = Tiddlers(title=title) else: candidate_tiddlers = Tiddlers(title=title, store=store) candidate_tiddlers.is_search = True for tiddler in readable_tiddlers_by_bag(store, tiddlers, usersign): candidate_tiddlers.add(tiddler) except StoreMethodNotImplemented: raise HTTP400('Search system not implemented') except StoreError as exc: raise HTTP400('Error while processing search: %s' % exc) return send_tiddlers(environ, start_response, tiddlers=candidate_tiddlers)
def get(environ, start_response): """ Handle ``GET`` on the search URI. Perform a search against the :py:class:`store <tiddlyweb.store.Store>`. What search means and what results are returned is dependent on the search implementation (if any) in the :py:class:`chosen store <tiddlyweb.stores.StorageInterface>`. """ store = environ['tiddlyweb.store'] filters = environ['tiddlyweb.filters'] search_query = get_search_query(environ) title = 'Search for %s' % search_query title = environ['tiddlyweb.query'].get('title', [title])[0] try: tiddlers = get_tiddlers(environ) usersign = environ['tiddlyweb.usersign'] if filters: candidate_tiddlers = Tiddlers(title=title) else: candidate_tiddlers = Tiddlers(title=title, store=store) candidate_tiddlers.is_search = True for tiddler in readable_tiddlers_by_bag(store, tiddlers, usersign): candidate_tiddlers.add(tiddler) except StoreMethodNotImplemented: raise HTTP400('Search system not implemented') except StoreError as exc: raise HTTP400('Error while processing search: %s' % exc) return send_tiddlers(environ, start_response, tiddlers=candidate_tiddlers)