def get_id_by_name(tag_name, kind='z'): ''' Get ID by tag_name of the label. ''' recs = TabTag.select().where((TabTag.name == tag_name) & (TabTag.kind == kind)) logger.info('tag count of {0}: {1} '.format(tag_name, recs.count())) # the_id = '' if recs.count() == 1: the_id = recs.get().uid elif recs.count() > 1: rec0 = None for rec in recs: # Only keep one. if rec0: TabPost2Tag.delete().where( TabPost2Tag.tag_id == rec.uid).execute() TabTag.delete().where(TabTag.uid == rec.uid).execute() else: rec0 = rec the_id = rec0.uid else: the_id = MLabel.create_tag(tag_name) return the_id
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 remove_relation(post_id, tag_id): ''' Remove the relation of post and label. ''' entry = TabPost2Tag.delete().where((TabPost2Tag.post_id == post_id) & (TabPost2Tag.tag_id == tag_id)) entry.execute()
def get_by_info(post_id, catalog_id): tmp_recs = TabPost2Tag.select().join( TabTag, on=(TabPost2Tag.tag_id == TabTag.uid )).where((TabPost2Tag.post_id == post_id) & (TabPost2Tag.tag_id == catalog_id) & (TabTag.kind == 'z')) if tmp_recs.count() > 1: ''' Remove the rests if the count greater than 1. ''' out_rec = None for tmp_rec in tmp_recs: if out_rec: entry = TabPost2Tag.delete().where( TabPost2Tag.uid == tmp_rec.uid) entry.execute() else: out_rec = tmp_rec elif tmp_recs.count() == 1: out_rec = tmp_recs.get() else: out_rec = None return out_rec
def get_by_info(post_id, catalog_id): tmp_recs = TabPost2Tag.select().join( TabTag, on=(TabPost2Tag.tag_id == TabTag.uid )).where((TabPost2Tag.post_id == post_id) & (TabPost2Tag.tag_id == catalog_id) & (TabTag.kind == 'z')) if tmp_recs.count() > 1: ''' 如果多于1个,则全部删除 ''' idx = 0 out_rec = None for tmp_rec in tmp_recs: if idx == 0: out_rec = tmp_rec else: entry = TabPost2Tag.delete().where( TabPost2Tag.uid == tmp_rec.uid) entry.execute() idx += 1 return out_rec elif tmp_recs.count() == 1: return tmp_recs.get() else: return None
def remove_tag(tag_id): ''' Delete the records of certain tag. ''' entry = TabPost2Tag.delete().where( TabPost2Tag.tag_id == tag_id ) entry.execute()
def remove_relation(post_id, tag_id): ''' Delete the record of post 2 tag. ''' entry = TabPost2Tag.delete().where((TabPost2Tag.post_id == post_id) & (TabPost2Tag.tag_id == tag_id)) entry.execute() MCategory.update_count(tag_id)
def del_by_uid(uid): ''' Just Query all the records from TabPost2Tag. ''' entry = TabPost2Tag.delete().where(TabPost2Tag.uid == uid) try: entry.execute() return True except: return False
def del_by_uid(uid): ''' Just Query all the records from TabPost2Tag. ''' entry = TabPost2Tag.delete().where(TabPost2Tag.uid == uid) try: entry.execute() return True except Exception as err: print(repr(err)) return False
def get_id_by_name(tag_name, kind='z'): recs = TabTag.select().where((TabTag.name == tag_name) & (TabTag.kind == kind)) logger.info('tag count of {0}: {1} '.format(tag_name, recs.count())) if recs.count() == 1: return recs.get().uid elif recs.count() > 1: idx = 0 rec0 = None for rec in recs: rec0 = rec # Only keep one. if idx == 0: pass else: TabPost2Tag.delete().where( TabPost2Tag.tag_id == rec.uid).execute() TabTag.delete().where(TabTag.uid == rec.uid).execute() idx += 1 return rec0.uid else: return MLabel.create_tag(tag_name)
def __get_by_info(post_id, catalog_id): ''' Geo the record by post and catalog. ''' recs = TabPost2Tag.select().where((TabPost2Tag.post_id == post_id) & (TabPost2Tag.tag_id == catalog_id)) if recs.count() == 1: return recs.get() elif recs.count() > 1: # return the first one, and delete others. out_rec = None for rec in recs: if out_rec: entry = TabPost2Tag.delete().where( TabPost2Tag.uid == rec.uid) entry.execute() else: out_rec = rec return out_rec return None
def __get_by_info(post_id, catalog_id): recs = TabPost2Tag.select().where((TabPost2Tag.post_id == post_id) & (TabPost2Tag.tag_id == catalog_id)) if recs.count() == 1: return recs.get() elif recs.count() > 1: # return the first one, and delete others. idx = 0 out_rec = None for rec in recs: if idx == 0: out_rec = rec else: entry = TabPost2Tag.delete().where( TabPost2Tag.uid == rec.uid) entry.execute() idx += idx return out_rec.get() else: return None
def remove_relation(post_id, tag_id): entry = TabPost2Tag.delete().where((TabPost2Tag.post_id == post_id) & (TabPost2Tag.tag_id == tag_id)) entry.execute()