def borrow(self, item=None): """ Borrow an external item """ if not item: item = drink.get_object(drink.db.db, request.POST['item']) if item.id in self: return drink.unauthorized("An object with the same id stands here!") if self.path in item.path: return drink.unauthorized("Can't move an object to one if it's children!") try: parent = drink.get_object(drink.db.db, item.rootpath) except Exception, e: return drink.unauthorized("Unhandled error: %r"%e)
def _query(self, pattern=None, query_type=None, page_nr=1, results=10): # Fire up searcher try: searcher = indexer.searcher() except IOError: reset() self.rebuild() searcher = indexer.searcher() qpat = qparser.parse(pattern.strip()) res = searcher.search_page(qpat, page_nr, pagelen=results) items = [] result = [] auth = drink.request.identity #sentence_frag = highlight.SentenceFragmenter() whole_frag = highlight.WholeFragmenter() root = drink.db.db res.fragmenter=whole_frag for item in res: obj = drink.get_object(root, quote(item['path'].encode('utf-8')), no_raise=True) if obj == None: # TODO: add a log here continue if 'r' in auth.access(obj): match = {'path': item['path'], 'item': item['path']} items.append(obj) title = item.highlights('title') or item['title'] match['hi_title'] = title match['hi'] = item.highlights('content') result.append(match) return (res.pagecount, result)
def get_parent(self): return drink.get_object(drink.db.db, self.rootpath)