def delete(uid): ''' Delete by uid :param uid: :return: ''' q_u1 = TabPostHist.delete().where(TabPostHist.post_id == uid) q_u1.execute() q_u2 = TabRel.delete().where(TabRel.post_f_id == uid or TabRel.post_t_id == uid) q_u2.execute() q_u3 = TabCollect.delete().where(TabCollect.post_id == uid) q_u3.execute() q_u4 = TabPost2Tag.delete().where(TabPost2Tag.post_id == uid) q_u4.execute() q_u5 = TabUsage.delete().where(TabUsage.post_id == uid) q_u5.execute() reply_arr = [] for reply in TabUser2Reply.select().where( TabUser2Reply.reply_id == uid): reply_arr.append(reply.reply_id.uid) q_u6 = TabUser2Reply.delete().where(TabUser2Reply.reply_id == uid) q_u6.execute() for replyid in reply_arr: TabReply.delete().where(TabReply.uid == replyid).execute() q_u7 = TabEvaluation.delete().where(TabEvaluation.post_id == uid) q_u7.execute() q_u8 = TabRating.delete().where(TabRating.post_id == uid) q_u8.execute() return MHelper.delete(TabPost, uid)
def add_or_update(user_id, app_id): ''' Add the collection or update. ''' rec = MCollect.get_by_signature(user_id, app_id) if rec: entry = TabCollect.update(timestamp=int(time.time())).where( TabCollect.uid == rec.uid) entry.execute() else: TabCollect.create( uid=tools.get_uuid(), user_id=user_id, post_id=app_id, timestamp=int(time.time()), )
def get_by_signature(user_id, app_id): ''' Get the collection. ''' try: return TabCollect.get((TabCollect.user_id == user_id) & (TabCollect.post_id == app_id)) except: return None
def count_of_user(user_id): ''' Get the cound of views. ''' return TabCollect.select( TabCollect, TabPost.uid.alias('post_uid'), TabPost.title.alias('post_title'), TabPost.view_count.alias('post_view_count')).where( TabCollect.user_id == user_id).join( TabPost, on=(TabCollect.post_id == TabPost.uid)).count()
def get_by_signature(user_id, app_id): ''' Get the collection. ''' try: return TabCollect.get((TabCollect.user_id == user_id) & (TabCollect.post_id == app_id)) except Exception as err: print(repr(err)) return None
def query_pager_by_userid(user_id, kind, num=10): recs = TabCollect.select( TabCollect, TabPost.uid.alias('post_uid'), TabPost.title.alias('post_title'), TabPost.kind.alias('post_kind'), TabPost.view_count.alias('post_view_count')).where( (TabCollect.user_id == user_id) & (TabPost.kind == kind)).join( TabPost, on=(TabCollect.post_id == TabPost.uid)).order_by( TabCollect.timestamp.desc()).limit(num) return recs
def query_pager_by_all(user_id, current_page_num=1): recs = TabCollect.select( TabCollect, TabPost.uid.alias('post_uid'), TabPost.title.alias('post_title'), TabPost.view_count.alias('post_view_count')).where( TabCollect.user_id == user_id).join( TabPost, on=(TabCollect.post_id == TabPost.uid)).order_by( TabCollect.timestamp.desc()).paginate( current_page_num, CMS_CFG['list_num']) return recs
def query_recent(user_id, num=10): ''' Collection of recent. ''' return TabCollect.select( TabCollect, TabPost.uid.alias('post_uid'), TabPost.title.alias('post_title'), TabPost.view_count.alias('post_view_count')).where( TabCollect.user_id == user_id).join( TabPost, on=(TabCollect.post_id == TabPost.uid)).order_by( TabCollect.timestamp.desc()).limit(num)
def get_by_signature(user_id, app_id): ''' :param user_id: :param app_id: :return: ''' try: return TabCollect.get( (TabCollect.user_id == user_id) & (TabCollect.post_id == app_id) ) except: return None
def remove_collect(user_id, app_id): ''' Cancel collection ''' rec = MCollect.get_by_signature(user_id, app_id) if rec: entry = TabCollect.delete().where( TabCollect.uid == rec.uid) entry.execute() else: return None