示例#1
0
    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)
示例#2
0
    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()),
            )
示例#3
0
 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
示例#4
0
 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()
示例#5
0
 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
示例#6
0
    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
示例#7
0
    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
示例#8
0
 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
示例#10
0
    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