def GET(self, terms): redir = False if web.input(terms=None).terms: redir = True terms = web.input().terms terms = unquote_plus(terms) if web.input(afters=None).afters: afters = web.input(afters=None).afters[:-3] else: afters = '0' if web.input(befores=None).befores: befores = web.input(befores=None).befores else: befores = '4294967296' # 2^32 try: if int(afters) > 0 or int(befores) < 4294967296: redir = True terms += ' date:@%s..@%s' % (int(afters), int(befores)) except ValueError: pass if redir: raise web.seeother('/search/%s' % quote_plus(terms.encode('utf8'))) web.header('Content-type', 'text/html') db = Database() ts = db.threads(query=terms, sort=Database.SORT.NEWEST_FIRST) template = env.get_template('search.html') return template.generate(terms=terms, ts=ts, title=terms, prefix=prefix, sprefix=webprefix)
def thread_nav(m): if not show_thread_nav: return db = Database() thread = next(db.threads('thread:' + m.threadid)) prv = None found = False nxt = None for msg in thread: if m == msg: found = True elif not found: prv = msg else: # found message, but not on this loop nxt = msg break yield "<hr><ul>" if prv: yield "<li>Previous message (by thread): %s</li>" % link_msg(prv) if nxt: yield "<li>Next message (by thread): %s</li>" % link_msg(nxt) yield "</ul><h3>Thread:</h3>" # FIXME show now takes three queries instead of 1; # can we yield the message body while computing the thread shape? thread = next(db.threads('thread:' + m.threadid)) yield show_msgs(thread.toplevel()) return
def get_threads(self, querystring, sort='newest_first'): """ asynchronously look up thread ids matching `querystring`. :param querystring: The query string to use for the lookup :type querystring: str. :param sort: Sort order. one of ['oldest_first', 'newest_first', 'message_id', 'unsorted'] :type query: str :returns: a pipe together with the process that asynchronously writes to it. :rtype: (:class:`multiprocessing.Pipe`, :class:`multiprocessing.Process`) """ assert sort in self._sort_orders db = Database(path=self.path, mode=Database.MODE.READ_ONLY) for t in db.threads(querystring, sort=self._sort_orders[sort], exclude_tags=self.exclude_tags): yield t.threadid