def get_doc(self, key): if key.startswith("/subjects/"): s = worksearch.get_subject(key) if s.work_count > 0: return s else: return None else: return web.ctx.site.get(key)
def GET(self, path): if path.startswith("/subjects/"): doc = worksearch.get_subject(path) else: doc = web.ctx.site.get(path) if not doc: raise web.notfound() i = web.input(offset=0, limit=50) i.offset = h.safeint(i.offset, 0) i.limit = h.safeint(i.limit, 50) i.limit = min(i.limit, 100) i.offset = max(i.offset, 0) lists = self.get_lists(doc, limit=i.limit, offset=i.offset) return delegate.RawText(self.dumps(lists))
def get_subject(key): global worksearch if worksearch is None: from openlibrary.plugins.worksearch import code as worksearch return worksearch.get_subject(key)