def po_list_by_buzz_at_user_id(user_id): from model.po import Po result = BuzzAt.where( to_id=user_id, state=BUZZ_AT_SHOW ).order_by('id desc').col_list( 32, 0, 'id, from_id, po_id, reply_id' ) id_list = [] id2user = defaultdict(list) for id, from_id, po_id, reply_id in result: po_id_in = po_id in id2user if po_id_in or len(id_list)<7: if not po_id_in: id_list.append(po_id) id2user[po_id].append(from_id) po_list = Po.mc_get_list(id_list) return buzz_po_bind_user(po_list, [ id2user[i.id] for i in po_list ])
def po_list_by_buzz_reply_user_id(user_id): from model.po import Po from model.po_pos import po_pos_get_last_reply_id from model.reply import Reply from model.buzz_po_bind_user import buzz_po_bind_user id_list = po_id_list_by_buzz_reply_user_id(user_id) po_list = Po.mc_get_list(id_list) po_user_id = [] for i in po_list: pos = po_pos_get_last_reply_id(user_id, i.id) new_reply_id_list = [] for reply_id in i.reply_id_list(): if reply_id > pos: new_reply_id_list.append(reply_id) user_id_list = [] for reply in Reply.mc_get_list(reversed(new_reply_id_list)): user_id_list.append(reply.user_id) po_user_id.append(user_id_list) return buzz_po_bind_user(po_list, po_user_id, user_id)