Пример #1
0
def appCreateCatalog():
    "创建目录"
    curTimestamp = unit.getTimeInt()
    result = checkApiParam(True, [
        {"name": "parentId", "checkfunc": unit.checkParamForInt},
        {"name": "name", "checkfunc": lambda v: v if len(v) >= 1 and len(v) < 100 else None},
        {"name": "createTime", "checkfunc": unit.checkParamForTimestamp, "default": curTimestamp},
        {"name": "lastModifyTime", "checkfunc": unit.checkParamForTimestamp, "default": curTimestamp},
        {"name": "memo", "default": None},
        {"name": "helpInt", "default": None},
        {"name": "helpText", "default": None}])
    if not result[kParamForResult]:
        return result[kParamForErrorResponse]

    loginInfo = result[kParamForLoginInfo]
    param = result[kParamForRequestParams]

    #查询数据
    db = _getDbManager()
    parentItem = db.getCatalogByIdAndRootIds(param["parentId"], loginInfo.rootIdsString)
    if not parentItem:
        return responseHelp.buildErrorResponseData(responseHelp.kCmdUserError_CatalogIdInValid)

    #创建路径
    strPath = unit.makeUserCreateCatalogPath(parentItem[dataManager.kCatalogFieldPath], param["name"])
    if not strPath:
        return responseHelp.buildErrorResponseData(responseHelp.kCmdServerError_DbDataError)
    param["path"] = strPath

    item = db.makeCatalog(param)
    return responseHelp.buildSuccessResponseData(dataManager.buildCatalogInfo(item, db))
Пример #2
0
def appUploadFileInfo():
    "上传文件信息"
    funcCheckStatus = lambda v: int(v) if int(v) in (defines.kFileStatusFromLocal, defines.kFileStatusFromUploading) else defines.kFileStatusFromLocal
    curTimestamp = unit.getTimeInt()
    result = checkApiParam(True, (
        {"name": "cid", "checkfunc": unit.checkParamForInt},
        {"name": "name", "checkfunc": lambda v: v if len(v) > 0 and len(v) <= 100 else None},
        {"name": "size", "checkfunc": unit.checkParamForInt},
        {"name": "type", "checkfunc": unit.checkParamForFileType},
        {"name": "ext", "checkfunc": lambda v: v if len(v) <= 10 else None},
        {"name": "statusForThumb", "checkfunc": funcCheckStatus, "default": defines.kFileStatusFromLocal},
        {"name": "statusForScreen", "checkfunc": funcCheckStatus, "default": defines.kFileStatusFromLocal},
        {"name": "createTime", "checkfunc": unit.checkParamForTimestamp, "default": curTimestamp},
        {"name": "importTime", "checkfunc": unit.checkParamForTimestamp, "default": curTimestamp},
        {"name": "lastModifyTime", "checkfunc": unit.checkParamForTimestamp, "default": curTimestamp},
        {"name": "duration", "checkfunc": lambda v: float(v), "default": None},
        {"name": "width", "checkfunc": unit.checkParamForInt, "default": None},
        {"name": "height", "checkfunc": unit.checkParamForInt, "default": None},
        {"name": "orientation", "checkfunc": unit.checkParamForInt, "default": None},
        {"name": "longitude", "checkfunc": unit.checkParamForDouble, "default": None},
        {"name": "latitude", "checkfunc": unit.checkParamForDouble, "default": None},
        {"name": "memo", "checkfunc": unit.checkParamForLess1024, "default": None},
        {"name": "helpInt", "checkfunc": unit.checkParamForInt, "default": None},
        {"name": "helpText", "default": None},))

    if not result[kParamForResult]:
        return result[kParamForErrorResponse]

    loginInfo = result[kParamForLoginInfo]
    param = result[kParamForRequestParams]
    nCatalogId = param.pop("cid")
    #目录信息
    db = _getDbManager()
    catalogRow = db.getCatalogByIdAndRootIds(nCatalogId, loginInfo.rootIdsString)
    if not catalogRow:
        return responseHelp.buildErrorResponseData(responseHelp.kCmdUserError_Param)

    strFileName = unit.buildOriginFileName(catalogRow[dataManager.kCatalogFieldPath], param["ext"])
    param["uploadUserId"] = loginInfo.userId
    param["fileName"] = strFileName
    param["statusForOrigin"] = defines.kFileStatusFromUploading
    param["uploadTime"] = unit.getTimeInt()
    nNewFileId = db.addFile(catalogRow[dataManager.kCatalogFieldRootId], nCatalogId, param)
    fileRow = db.getFileByIdAndRootIds(nNewFileId, None)
    funcForIdRelatePath = lambda : db.getCatalogIdRelatePathInfo(nCatalogId)
    return responseHelp.buildSuccessResponseData(dataManager.buildFileInfo(fileRow, funcForIdRelatePath))
Пример #3
0
 def setHelpInfo(self,
                 aTableType,
                 aRecordId,
                 aHelpInt,
                 aHelpText,
                 aStrRootIds=None):
     "设置不同表记录的HelpInfo信息"
     strTableName, where = self._buildHelpQueryInfo(aTableType, aRecordId,
                                                    aStrRootIds)
     self.update(strTableName, where, {
         "helpInt": aHelpInt,
         "helpText": aHelpText
     }, {"lastModifyTime": unit.getTimeInt()})
Пример #4
0
    def getUser(self, aUserName, aPassword):
        "根据用户跟密码查询,若成功,则更新登陆时间"
        row = self.select(_kUserTableName, {
            "name": aUserName,
            "password": aPassword
        })
        if row is None:
            #查询不到直接退出
            return None

        #更新最后登陆时间
        self.update(_kUserTableName, {"id": row[kUserFieldId]},
                    {"lastLoginDate": unit.getTimeInt()})
        return row
Пример #5
0
 def addFile(self, aRootId, aRealCatalogId, aFileInfo):
     """添加文件信息
         直接添加,调用者必须确保键值的正确性
     """
     curTime = unit.getTimeInt()
     aFileInfo["rootCatalogId"] = aRootId
     aFileInfo["realCatalogId"] = aRealCatalogId
     makeValue(aFileInfo, "catalogId", aRealCatalogId)
     makeValue(aFileInfo, "createTime", curTime)
     makeValue(aFileInfo, "importTime", curTime)
     makeValue(aFileInfo, "lastModifyTime", curTime)
     makeValue(aFileInfo, "statusForThumb", defines.kFileStatusFromLocal)
     makeValue(aFileInfo, "statusForScreen", defines.kFileStatusFromLocal)
     makeValue(aFileInfo, "statusForOrigin", defines.kFileStatusFromLocal)
     return self.insert(_kFileTableName, aFileInfo)
Пример #6
0
    def updateCatalog(self, aId, aCatalogInfo, aLimitStrRootIds):
        "更新目录信息, 若需要修改 parentId, 则可能需要修改rootId和所对应的File的rootCatalogId"
        bUpdateFileTable = False
        nNewRootId = None
        if aLimitStrRootIds != None:
            # 只有传递 rootids 信息时,才进行修改(客户端才需要传递)
            nNewParentId = aCatalogInfo.get("parentId")
            if nNewParentId != None and nNewParentId > 0:
                sql = """select a.rootId as newRootId, b.rootId as curRootid, b.parentId
                    from {table} a, {table} b
                    where a.id = ? and a.rootid in ({limitIds}) and
                        b.id = ? and b.rootid in ({limitIds})
                """.format(table=_kCatalogTableName, limitIds=aLimitStrRootIds)
                # print(sql)
                row = self.fetch(sql, (nNewParentId, aId))
                if not row:
                    return False

                # 判断是否更新
                if nNewParentId == row[2]:
                    aCatalogInfo.pop("parentId")
                elif row[0] != row[1]:
                    bUpdateFileTable = True
                    nNewRootId = row[0]
                    aCatalogInfo["rootId"] = nNewRootId
            else:
                aCatalogInfo.pop("parentId", None)
        else:
            # 若没有rootIds,则不对parentId进行处理
            aCatalogInfo.pop("parentId", None)

        #更新Catalog表
        afv = None
        if not aCatalogInfo.get("lastModifyTime"):
            afv = {"lastModifyTime": unit.getTimeInt()}
        bOK = self.update(_kCatalogTableName, {
            "id": aId,
            formatInField("rootId", aLimitStrRootIds): None
        }, aCatalogInfo, afv)

        #更新File表
        if bOK and bUpdateFileTable:
            bOK = self.update(_kFileTableName, {"realCatalogId": aId},
                              {"rootCatalogId": nNewRootId})
        return bOK
Пример #7
0
    def makeCatalog(self, aCatalogInfo):
        """创建目录,aCatalogInfo["path"] 必须存在
        若已存在目录,只则更新更新
        若需要插入数据时:
            rootId与parentId存在,则直接插入.此时外部必须确定提供的数据有效
            否则,先查询其父目录,再根据情况插入
        :returns: 指定目录的信息

        """
        strPath = aCatalogInfo["path"]
        row = self.getCatalogByPath(strPath)
        nId = None
        if row:
            nId = row[kCatalogFieldId]
            aCatalogInfo.pop("path")
            aCatalogInfo.pop("rootId", None)
            aCatalogInfo.pop("parentId", None)
            self.updateCatalog(nId, aCatalogInfo, None)
        else:
            strPath = os.path.abspath(strPath)
            aCatalogInfo["path"] = strPath
            nParentId = aCatalogInfo.get("parentId")
            nRootId = aCatalogInfo.get("rootId")
            if nParentId == None or nRootId == None:
                pci = None
                if nParentId == None:
                    parentPath = os.path.dirname(strPath)
                    pci = self.getCatalogByPath(parentPath)
                else:
                    pci = self.getCatalogById(nParentId)
                aCatalogInfo["parentId"] = pci[kCatalogFieldId] if pci else -1
                aCatalogInfo[
                    "rootId"] = pci[kCatalogFieldRootId] if pci else -1

            aCatalogInfo["lastModifyTime"] = unit.getTimeInt()
            nId = self.insert(_kCatalogTableName, aCatalogInfo)
        # end if
        result = self.select(_kCatalogTableName, {"id": nId})
        if result and result[kCatalogFieldRootId] == -1:
            result = list(result)
            result[kCatalogFieldRootId] = nId
            self.update(_kCatalogTableName, {"id": nId}, {"rootId": nId})
        return result
Пример #8
0
    def updateFile(self, aFileId, aFileInfo, aLimitStrRootIds):
        """更新文件信息
            若存在aLimitStrRootIds和aFileInfo["catalogId"]有效时, 只修改数据信息,不会真正移动文件
        """
        if aLimitStrRootIds != None and aFileInfo.get("catalogId") != None:
            #新位置是否有效s
            nNewCatalogId = aFileInfo["catalogId"]
            sql = """select a.rootId        as newRootId, 
                            b.catalogId     as curCatalogId, 
                            b.rootCatalogId as curRootId
                from {catalogTable} a, {fileTable} b 
                where a.id = ? and a.rootId in ({limitIds}) 
                    and b.id = ? and b.rootCatalogid in ({limitIds})
            """.format(catalogTable=_kCatalogTableName,
                       fileTable=_kFileTableName,
                       limitIds=aLimitStrRootIds)
            row = self.fetch(sql, (nNewCatalogId, aFileId))
            if not row:
                return False

            #是否要修改 catalogId
            nNewRootId = row[0]
            nCurCatalogId = row[1]
            nCurRootId = row[2]
            if nNewRootId != nCurRootId:
                aFileInfo["rootCatalogId"] = nNewRootId
            if nNewCatalogId == nCurCatalogId:
                aFileInfo.pop("catalogId")

        # 更新数据
        afv = None
        if aFileInfo.get("lastModifyTime") == None:
            afv = {"lastModifyTime": unit.getTimeInt()}
        return self.update(
            _kFileTableName, {
                "id": aFileId,
                formatInField("rootCatalogId", aLimitStrRootIds): None
            }, aFileInfo, afv)
Пример #9
0
 def makeUser(self, aUserName, aPassword):
     "若插入不成功,则判断修改密码,返回ID"
     curTime = unit.getTimeInt()
     fieldValues = {
         "name": aUserName,
         "password": aPassword,
         "createTime": curTime,
         "lastLoginDate": curTime,
         "lastModifyTime": curTime
     }
     nId = self.insert(_kUserTableName, fieldValues)
     if nId is None:
         #插入不成功,正常情况是数据已经存在
         row = self.select(_kUserTableName, {"name": aUserName})
         if row is None:
             log.logObject().log(logging.ERROR, "无法创建用户 %s" % aUserName)
             return None
         nId = row[kUserFieldId]
         if aPassword and len(
                 aPassword) > 0 and row[kUserFieldPassword] != aPassword:
             self.update(_kUserTableName, {"id": nId},
                         {"password": aPassword})
     return nId