def saveZipFile(self,data): try: db = DBService(Pic,Pic.__tablename__) file_name =data.get('filename') name,path =self.makedir("zip-"+file_name) #存入CACHE_PATH文件夹中 with open(os.path.join(CACHE_PATH,file_name),"wb") as fp: fp.write(data.get('body')) zipfileData = zipfile.ZipFile(os.path.join(CACHE_PATH,file_name)) files = [] for each in zipfileData.filelist: name = str(zipfileData.extract(each,path)) if os.path.splitext(name)[1]: files.append(name.split(str(os.path.normpath(PIC_PATH)))[1]) for each_file in files: db.addRecord(Pic(name=each_file.replace('\\','-') ,path=each_file)) for each_file_a in files: children_list = [] parent_id = db.searchRecord(Pic.path==each_file_a).id for each_file_b in files: if os.path.split(each_file_b)[0]==os.path.splitext(each_file_a)[0]: children_list.append(db.searchRecord(Pic.path==each_file_b).id) db.updateRecord(Pic.path==each_file_b,Pic.parent,parent_id) db.updateRecord(Pic.path==each_file_a,Pic.children,str(children_list)) except Exception as e: _result = -1,"Error\nexception message :"+e.message
def initPicTree(self,page_num): final_tag=0 db = DBService(Pic,Pic.__tablename__) root_list = self.getRootPics() #总长度 allpage_num = len(root_list) num = 0 if page_num< 1: num =0 elif page_num < allpage_num: num = page_num-1 else: num = allpage_num-1 final_tag = 1 if root_list: tree_id_list = [root_list[num]] data_list = [] while tree_id_list: pic = tree_id_list[0] tree_id_list=tree_id_list[1:] data = db.searchRecord(Pic.id==pic) tags = eval(data.tag_list) tagnames = [] tgService = DBService(Tag,Tag.__tablename__) for each in tags: tagnames.append(tgService.searchRecord(Tag.id==each).name) parent_name = '' if not data.parent==-1: parent_name = db.searchRecord(Pic.id==data.parent).name data_list.append({'name':data.name,'path':("pictures\\"+data.path).replace('\\','\\\\'),'parent_name':parent_name,'description':data.description,'taglist':tagnames}) tree_id_list+=eval(data.children) return data_list,final_tag,num+1 else: return [],final_tag,num
def CheckOutUser(self, name, psw): """ :param name: 需要检查的名字 :param psw: 输入的密码 :return:检查结果 code:-1为无用户,0为密码错误,1为正确返回 """ code = 1 service = DBService(User, User.__tablename__) result = service.searchRecord(User.name == name) if result: if result.password == psw: return code, True else: return code - 1, False else: code = -1 return code, None