示例#1
0
    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
示例#2
0
 def getRootPics(self):
     db = DBService(Pic,Pic.__tablename__)
     root_list = []
     result = db.searchAll(Pic.parent==-1)
     if result:
         for each in result:
             root_list.append(each.id)
     return root_list
示例#3
0
 def signup(self,**kwargs):
     user= User(
         name=kwargs.get("username"),
         realname=kwargs.get("realname"),
         password = kwargs.get("password"),
         email=kwargs.get("email")
     )
     db = DBService(User,User.__tablename__)
     db.addRecord(user)
     pass
示例#4
0
    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
示例#5
0
 def savePic(self,data):
     _result = 1,"ok"
     try:
         file_name =data.get('filename')
         filename,realpath = self.makedir(file_name)
         with open(os.path.join(realpath,file_name),"wb") as fp:
             fp.write(data.get('body'))
         db = DBService(Pic,Pic.__tablename__)
         db.addRecord(Pic(name=file_name,path=os.path.join('\\',filename, file_name).replace('\\','\\\\')))
     except Exception as e:
         _result = -1,"Error\nexception message :"+e.message
     finally:
         return _result
示例#6
0
class BL:
    def __init__(self, host, port):
        self.db = DBService(host, port)

    def update_occupy(self, floor, cell, state):
        self.db.update_cell(floor, cell, state)

    def get_state(self, floor, cell):
        if floor is None:
            return self.db.get_all()
        if cell is None:
            return self.db.get_floor(floor)
        return self.db.get_cell(floor, cell)
示例#7
0
    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
示例#8
0
 def allTags(self):
     db = DBService(Tag,Tag.__tablename__)
     model_list = db.searchAll(Tag.id!=-1)
     return [(item.name,item.id) for item in model_list]
示例#9
0
 def __init__(self, host, port):
     self.db = DBService(host, port)