def update_category(self, uid, **kwargs): ''' Update the category of the post. :param uid: The ID of the post. Extra info would get by requests. :return: ''' catid = kwargs['catid'] if ('catid' in kwargs and MCategory.get_by_uid( kwargs['catid'])) else None post_data = self.get_post_data() current_infos = MPost2Catalog.query_by_entity_uid(uid, kind='').naive() new_category_arr = [] # Used to update post2category, to keep order. def_cate_arr = ['gcat{0}'.format(x) for x in range(10)] # for old page. def_cate_arr.append('def_cat_uid') # Used to update post extinfo. cat_dic = {} for key in def_cate_arr: if key not in post_data: continue if post_data[key] == '' or post_data[key] == '0': continue # 有可能选重复了。保留前面的 if post_data[key] in new_category_arr: continue new_category_arr.append(post_data[key] + ' ' * (4 - len(post_data[key]))) cat_dic[key] = post_data[key] + ' ' * (4 - len(post_data[key])) if catid: def_cat_id = catid elif new_category_arr: def_cat_id = new_category_arr[0] else: def_cat_id = None if def_cat_id: cat_dic['def_cat_uid'] = def_cat_id cat_dic['def_cat_pid'] = MCategory.get_by_uid(def_cat_id).pid # Add the category logger.info('Update category: {0}'.format(new_category_arr)) logger.info('Update category: {0}'.format(cat_dic)) MPost.update_jsonb(uid, cat_dic) for index, catid in enumerate(new_category_arr): MPost2Catalog.add_record(uid, catid, index) # Delete the old category if not in post requests. for cur_info in current_infos: if cur_info.tag_id not in new_category_arr: MPost2Catalog.remove_relation(uid, cur_info.tag_id)
def tearDown(self): MCategory.delete(self.tag_id) MPost.delete(self.post_id2) MPost.delete(self.post_id) MPost2Catalog.remove_relation(self.post_id, self.tag_id) MRelation.delete(self.uid)
def tearDown(self): print("function teardown") MCategory.delete(self.tag_id) MPost.delete(self.postid) MPost2Catalog.remove_relation(self.postid, self.tag_id)
def update_category(uid, postdata, kwargs): ''' Update the category of the post. ''' catid = kwargs['catid'] if ( 'catid' in kwargs and MCategory.get_by_uid(kwargs['catid'])) else None post_data = postdata current_infos = MPost2Catalog.query_by_entity_uid(uid, kind='').objects() new_category_arr = [] # Used to update post2category, to keep order. def_cate_arr = ['gcat{0}'.format(x) for x in range(10)] # for old page. def_cate_arr.append('def_cat_uid') # Used to update post extinfo. cat_dic = {} for key in def_cate_arr: if key not in post_data: continue if post_data[key] == '' or post_data[key] == '0': continue # 有可能选重复了。保留前面的 if post_data[key] in new_category_arr: continue new_category_arr.append(post_data[key] + ' ' * (4 - len(post_data[key]))) cat_dic[key] = post_data[key] + ' ' * (4 - len(post_data[key])) if catid: def_cat_id = catid elif new_category_arr: def_cat_id = new_category_arr[0] else: def_cat_id = None if def_cat_id: cat_dic['def_cat_uid'] = def_cat_id cat_dic['def_cat_pid'] = MCategory.get_by_uid(def_cat_id).pid print('=' * 40) print(uid) print(cat_dic) MPost.update_jsonb(uid, cat_dic) for index, catid in enumerate(new_category_arr): MPost2Catalog.add_record(uid, catid, index) # Delete the old category if not in post requests. for cur_info in current_infos: if cur_info.tag_id not in new_category_arr: MPost2Catalog.remove_relation(uid, cur_info.tag_id)
def tearDown(self): print("function teardown") tt = MCategory.get_by_uid(self.uid) if tt: MCategory.delete(self.uid) tt = MPost.get_by_uid(self.postid) if tt: MPost.delete(self.postid) MPost2Catalog.remove_relation(self.postid, self.uid)
def tearDown(self): print("function teardown") self.uu.delete(self.uid) MCategory.delete(self.tag_id) self.uu.delete(self.post_id2) self.uu.delete(self.post_id) MPost2Catalog.remove_relation(self.post_id, self.tag_id) tt = MLabel.get_by_slug(self.slug) if tt: MLabel.delete(tt.uid)
def tearDown(self): print("function teardown") tt = self.uu.get_by_uid(self.postid) if tt: MCategory.delete(self.tag_id) MPost.delete(self.postid) MPost2Catalog.remove_relation(self.postid, self.tag_id) print('545456365635653')
def test_remove_relation(self): self.add_message() MPost2Catalog.add_record(self.post_id, self.tag_id) MPost2Catalog.remove_relation(self.post_id, self.tag_id) a = MPost2Catalog.query_all() TF = True for i in a: if i.post_id == self.post_id: TF = False assert TF self.tearDown()
def tearDown(self): print("function teardown") tt = self.uu.get_by_uid(self.app_f) if tt: MPost2Catalog.remove_relation(self.app_t, self.tag_id) MPost2Catalog.remove_relation(self.app_f, self.tag_id) MCategory.delete(self.tag_id) MPost.delete(self.app_f) MPost.delete(self.app_t) MRelation.delete(self.uid) tt = MLabel.get_by_slug(self.slug) if tt: MLabel.delete(tt.uid)
def delete_by_id(self, del_id): ''' Delete by id. ''' print("-" * 50) print(del_id) if self.check_post_role()['DELETE']: pass else: return False post_resc = MPost2Catalog.query_postinfo_by_cat(del_id) for post in post_resc: MPost2Catalog.remove_relation(post.uid, del_id) if MCategory.delete(del_id): output = {'del_link': 1} else: output = {'del_link': 0} return json.dump(output, self)
def tearDown(self): print("function teardown") tt = MCategory.get_by_uid(self.tag_id) if tt: MCategory.delete(self.tag_id) tt = MPost.get_by_uid(self.post_id) if tt: MPost.delete(self.post_id) MPost2Catalog.remove_relation(self.post_id, self.tag_id) tt = MPost.get_by_uid(self.post_id2) if tt: MPost.delete(self.post_id2) MPost2Catalog.remove_relation(self.post_id2, self.tag_id) tt = MLabel.get_by_slug(self.slug) if tt: print('8888888888') MLabel.delete(self.slug)
def tearDown(self): print("function teardown") tt = self.uu.get_by_uid(self.uid) if tt: print('翻翻翻翻翻翻翻翻翻翻翻翻翻翻翻翻翻翻3') self.uu.delete(self.uid) tt = MCategory.get_by_uid(self.tag_id) if tt: MCategory.delete(self.tag_id) tt = self.uu.get_by_uid(self.post_id) if tt: MCategory.delete(self.tag_id) MPost.delete(self.post_id2) MPost.delete(self.post_id) MPost2Catalog.remove_relation(self.post_id, self.tag_id) print('545456365635653') tt = MLabel.get_by_slug(self.slug) if tt: print('8888888888') MLabel.delete(tt.uid)
def update_category(uid, post_data): ''' Update the category of the post. :param uid: The ID of the post. Extra info would get by requests. ''' # deprecated # catid = kwargs['catid'] if MCategory.get_by_uid(kwargs.get('catid')) else None # post_data = self.get_post_data() if 'gcat0' in post_data: pass else: return False # Used to update MPost2Category, to keep order. the_cats_arr = [] # Used to update post extinfo. the_cats_dict = {} # for old page. deprecated # def_cate_arr.append('def_cat_uid') def_cate_arr = ['gcat{0}'.format(x) for x in range(10)] for key in def_cate_arr: if key not in post_data: continue if post_data[key] == '' or post_data[key] == '0': continue # 有可能选重复了。保留前面的 if post_data[key] in the_cats_arr: continue the_cats_arr.append(post_data[key] + ' ' * (4 - len(post_data[key]))) the_cats_dict[key] = post_data[key] + ' ' * (4 - len(post_data[key])) # if catid: # def_cat_id = catid if the_cats_arr: def_cat_id = the_cats_arr[0] else: def_cat_id = None if def_cat_id: the_cats_dict['gcat0'] = def_cat_id the_cats_dict['def_cat_uid'] = def_cat_id the_cats_dict['def_cat_pid'] = MCategory.get_by_uid(def_cat_id).pid # Add the category logger.info('Update category: {0}'.format(the_cats_arr)) logger.info('Update category: {0}'.format(the_cats_dict)) MPost.update_jsonb(uid, the_cats_dict) for index, idx_catid in enumerate(the_cats_arr): MPost2Catalog.add_record(uid, idx_catid, index) # Delete the old category if not in post requests. current_infos = MPost2Catalog.query_by_entity_uid(uid, kind='').objects() for cur_info in current_infos: if cur_info.tag_id not in the_cats_arr: MPost2Catalog.remove_relation(uid, cur_info.tag_id)
def test_remove_relation(self): MPost2Catalog.remove_relation(self.post_id, self.tag_id) assert True