def get_threads(board, page=0, fmt_name="page"): _fmt = "thread_" + fmt_name if _fmt in globals(): fmt = globals()[_fmt] else: fmt = thread_plain threads = [] board_db = Board.get_by_key_name(board) if board_db: threads = board_db.linked if not threads: threads = [ (board, th) for th in board_db.thread] per_page = get_config('aib.ib', 'thread_per_page') threads = threads[per_page*page:per_page*(page+1)] logging.info("threadlist in %r : %r" % (board, threads)) # grab data from cache data = Thread.load_list(threads) return [ fmt(th) for th in data if th ]
def get(self, board): key = "posts-%s" % board post = memcache.get(key) if post != None: return json_response(post) board = Board.get_by_key_name(board) if board: post = board.counter memcache.set(key, post) else: post = None return json_response(post)
def bump(boards, thread): board_db = Board.get_by_key_name(boards) main = boards[0] per_page = get_config('aib.ib', 'thread_per_page') pages = get_config('aib.ib', 'board_pages') threads = per_page * pages def hide(linked, board): for _board, thread in list(linked): if board == _board: linked.remove((board, thread)) add = 0 for x,(name,board) in enumerate(zip(boards,board_db)): if not board: board = Board(key_name=name) board.linked = [] board_db[x] = board if not board.linked and board.thread: board.linked = [ (board.code, th) for th in board.thread ] if main[-1] == '~': hide(board.linked, main) add = per_page/3 if (main,thread) in board.linked: board.linked.remove((main,thread)) board.linked.insert(add, (main,thread)) board.linked = board.linked[:threads] main_db = board_db[0] if thread in main_db.thread: main_db.thread.remove(thread) main_db.thread.insert(add, thread) main_db.thread = main_db.thread[:threads] db.put(board_db)
def get(self, board): board = Board.get_by_key_name(board) return json_response(board.counter if board else None)
def save_post(request, data, board, thread): board_db = Board.get_by_key_name(board) if not board_db: board_db = Board(key_name = board, thread = []) board_db.counter += 1 # create new thread new = False if thread == 'new': new = True if data.get("sage"): raise NotFound() # FIXME: move to form thread = board_db.counter posts = [] thread_db = Thread.create(thread, board) thread_db.posts = [] thread_db.subject = data.get("subject")[:SUBJECT_MAX] else: thread = int(thread) #if thread not in board_db.thread: # raise NotFound() if thread in board_db.thread and not data.get("sage"): board_db.thread.remove(thread) thread_db = Thread.load(thread, board) if not thread_db: raise NotFound() if not data.get("sage"): board_db.thread.insert(0, thread) board_db.thread = board_db.thread[:THREAD_PER_PAGE*BOARD_PAGES] rb = rainbow.make_rainbow(request.remote_addr, board, thread) data['rainbow'] = rb data['rainbow_html'] = rainbow.rainbow(rb) data['text_html'] = markup( board=board, postid=board_db.counter, data=escape(data.get('text', '')), ) # FIXME: move to field data['name'] = data.get("name") or "Anonymous" # save thread and post number data['post'] = board_db.counter data['thread'] = thread now = datetime.now() data['time'] = now.strftime("%Y-%m-%d, %H:%M") data['timestamp'] = int(now.strftime("%s")) img_key = data.get("key") if img_key: blob_key = blobstore.BlobKey(img_key) blob_info = blobstore.BlobInfo.get(blob_key) data['image'] = { "size" : blob_info.size, "content_type" : blob_info.content_type, "full" : images.get_serving_url(img_key), "thumb" : images.get_serving_url(img_key, 200), } for fname in board_options.get(board, []): func = globals().get('option_'+fname) if func: func(request, data) thread_db.posts.append(data) db.put( (thread_db, board_db)) Cache.delete( ( dict(Board=board), ) ) memcache.set("threadlist-%s" % board, board_db.thread) memcache.set("post-%s-%d" %(board, board_db.counter), data) r = Render(board, thread) r.add(data, new) r.save() key = "update-thread-%s-%d" % (board, thread) if not new: send = { "html" : r.post_html, "evt" : "newpost" , "count" : len(thread_db.posts), "last" : board_db.counter, } watchers = memcache.get(key) or [] for person in watchers: logging.info("send data to key %s" % (person+key)) channel.send_message(person+key, dumps(send)) return board_db.counter, thread
def save_post(request, data, board, thread): board_db = Board.get_by_key_name(board) if not board_db: board_db = Board(key_name = board, thread = []) board_db.counter += 1 # create new thread new = False if thread == 'new': new = True if data.get("sage"): raise NotFound() # FIXME: move to form thread = board_db.counter posts = [] thread_db = Thread.create(thread, board) thread_db.posts = [] thread_db.subject = data.get("subject")[:SUBJECT_MAX] else: thread = int(thread) if thread in board_db.thread and not data.get("sage"): board_db.thread.remove(thread) thread_db = Thread.load(thread, board) if not thread_db: raise NotFound() if not data.get("sage"): board_db.thread.insert(0, thread) per_page = get_config('aib.ib', 'thread_per_page') pages = get_config('aib.ib', 'board_pages') board_db.thread = board_db.thread[:per_page*pages] rb = rainbow.make_rainbow(request.remote_addr, board, thread) data['rainbow'] = rb data['overlay'] = board in OVER data['text_html'] = markup( board=board, postid=board_db.counter, data=escape(data.get('text', '')), ) # save thread and post number data['post'] = board_db.counter data['thread'] = thread now = datetime.now() data['time'] = now.strftime("%Y-%m-%d, %H:%M") data['timestamp'] = int(now.strftime("%s")) img_key = data.get("key") if img_key: blob_key = blobstore.BlobKey(img_key) blob_info = blobstore.BlobInfo.get(blob_key) data['image'] = { "size" : blob_info.size, "content_type" : blob_info.content_type, "full" : images.get_serving_url(img_key), "thumb" : images.get_serving_url(img_key, 200), } for fname in OPTIONS.get(board, []): func = globals().get('option_'+fname) if func: func(request, data) thread_db.posts.append(data) db.put( (thread_db, board_db)) Cache.remove("board", board) r = Render(board, thread) r.add(data, new) r.save() deferred.defer(rss.add, board, thread, board_db.counter, data.get("text_html") ) if not new: deferred.defer( watchers_post_notify, board, thread, r.post_html, len(thread_db.posts), board_db.counter ) return board_db.counter, thread