def del_project(name): # firstly del project p_id = Project.get(Project.p_name == name).p_id query = Project.delete().where(Project.p_name == name) query.execute() # secondly del p_id in admin_pro users = User.select() for user in users: admin_pro = user.admin_pro u_id = user.u_id if admin_pro: if admin_pro == str(p_id): admin_pro = None else: pids = admin_pro.split(',') if str(p_id) in pids: pids.remove(str(p_id)) splits = ',' admin_pro = splits.join(pids) query = User.update(admin_pro = admin_pro).where(User.u_id == u_id) query.execute() # thirdly del item if p_id in item items = Item.select() items_id = [] for item in items: if item.project_id == p_id: items_id.append(item.it_id) query = Item.delete().where(Item.project_id == p_id) query.execute() # fourly del reply if it_id in items_id for item_id in items_id: query = Reply.delete().where(Reply.item_id == item_id) query.execute()
def add_item(it_type,user_id,project_id,deal,content,it_time,picture): if it_type == None: it_type = 1 # use advice as default if user_id == None: user_id = 1 # 若无法获得userid,则默认为管理员admin提出的意见,即匿名意见 if project_id ==None: project_id = 1 # user 1 as default project id if deal == None : deal = 0 # set no deal as default if it_time == None : it_time = time.strftime( '%Y-%m-%d %X', time.localtime() ) #set current time as default Item.create(it_type= it_type ,user_id=user_id,project_id = project_id,deal= deal,it_content = content,it_time = it_time,picture= picture ) newItem = Item.get(Item.it_type == it_type ,Item.user_id == user_id, Item.project_id == project_id, Item.deal == deal, Item.it_content == content, Item.it_time == it_time, Item.picture == picture) return newItem
def del_item(it_id_list): # firstly del item for it_id_1 in it_id_list: query = Item.delete().where(Item.it_id == int(it_id_1)) query.execute() # secondly del reply if it_id in Reply.item_id # 一个条目只对应一条回复信息 for it_id_2 in it_id_list: query = Reply.delete().where(Reply.item_id == int(it_id_2)) query.execute()
def set_multiitem_dealed(it_id_list): for it_id in it_id_list: query = Item.update(deal = 1).where(Item.it_id == it_id) query.execute()
def set_item_dealed(it_id): query = Item.update(deal = 1).where(Item.it_id == it_id) query.execute()