Beispiel #1
0
    def add_relation(app_f, app_t, weight=1):
        '''
        Adding relation between two posts.
        :return:
        '''
        recs = TabRel.select().where(
            (TabRel.post_f_id == app_f) & (TabRel.post_t_id == app_t)
        )
        if recs.count() > 1:
            for record in recs:
                MRelation.delete(record.uid)

        if recs.count() == 0:
            uid = tools.get_uuid()
            entry = TabRel.create(
                uid=uid,
                post_f_id=app_f,
                post_t_id=app_t,
                count=1,
            )
            return entry.uid
        elif recs.count() == 1:
            MRelation.update_relation(app_f, app_t, weight)
        else:
            return False
Beispiel #2
0
 def update_relation(app_f, app_t, weight=1):
     try:
         postinfo = TabRel.get((TabRel.post_f_id == app_f)
                               & (TabRel.post_t_id == app_t))
     except:
         return False
     entry = TabRel.update(count=postinfo.count +
                           weight).where((TabRel.post_f_id == app_f)
                                         & (TabRel.post_t_id == app_t))
     entry.execute()
Beispiel #3
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)
Beispiel #4
0
 def delete(uid):
     entry = TabRel.delete().where(TabRel.uid == uid)
     entry.execute()