def buildCatalogInfo(aCatalogRow, aDbObject): "根据数据库查询到的信息生成发送给客户端的catalogInfo" strName = aCatalogRow[kCatalogFieldName] if strName is None: strName = aCatalogRow[kCatalogFieldPath] strName = os.path.basename(strName) cid = aCatalogRow[kCatalogFieldId] catalogInfo = { "id": cid, "rootId": aCatalogRow[kCatalogFieldRootId], "parentId": aCatalogRow[kCatalogFieldParentId], "name": strName, "createTime": aCatalogRow[kCatalogFieldCreateTime], "lastModifyTime": aCatalogRow[kCatalogFieldLastModifyTime], "memo": aCatalogRow[kCatalogFieldMemo], "helpInt": aCatalogRow[kCatalogFieldHelpInt], "helpText": aCatalogRow[kCatalogFieldHelpText] } if aDbObject: subStates = aDbObject.getCatalogState(cid) if subStates and len(subStates) > 1: catalogInfo["subCatalogCount"] = subStates[0] catalogInfo["fileCount"] = subStates[1] unit.filterNullValue(catalogInfo) return catalogInfo
def appUpdateCatalog(): result = checkApiParam(True, [ {"name": "id", "checkfunc": unit.checkParamForInt}, {"name": "parentId", "checkfunc": unit.checkParamForInt, "default": None}, {"name": "name", "checkfunc": lambda v: v if len(v) >= 1 and len(v) < 100 else None, "default": None}, {"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] nId = param.pop("id") unit.filterNullValue(param) bOK = False if len(param) > 0: db = _getDbManager() bOK = db.updateCatalog(nId, param, loginInfo.rootIdsString) if bOK: item = db.getCatalogById(nId) return responseHelp.buildSuccessResponseData(dataManager.buildCatalogInfo(item, db)) return responseHelp.buildErrorResponseData(responseHelp.kCmdUserError_NotModify)
def appGetHelpInfo(): "获取指定记录的辅助信息" # 参数判断 result = checkApiParam(True, [ {"name": "type", "checkfunc": unit.checkParamForInt}, {"name": "id", "checkfunc": unit.checkParamForInt, "default": -1}]) if not result[kParamForResult]: return result[kParamForErrorResponse] userLoginInfo = result[kParamForLoginInfo] param = result[kParamForRequestParams] nType = param["type"] nId = userLoginInfo.userId if nType == 0 else param["id"] if nType not in (0, 1, 2) or nId <= 0: return responseHelp.buildErrorResponseData(responseHelp.kCmdUserError_Param) # 查询并返回数据 db = _getDbManager() hi = db.getHelpInfo(nType, nId, userLoginInfo.rootIdsString) nLen = len(hi) if hi else 0 ltData = {"helpInt": hi[0] if nLen > 0 else None, "helpText": hi[1] if nLen > 1 else None, "lastModifyTime": hi[2] if nLen > 2 else None} unit.filterNullValue(ltData) return responseHelp.buildSuccessResponseData(ltData)
def buildFileInfo(aFileRow, aFuncForPaths): """组建单个fileInfo信息, aFuncForPaths: 是一个函数,返回 {catalogId: path} 对象 或者直接就是一个 {catalogId: path} 对象 """ strName = aFileRow[kFileFieldName] if strName is None: strName = aFileRow[kFileFieldFileName] fileInfo = { "id": aFileRow[kFileFieldId], "uploadUserId": aFileRow[kFileFieldUploadUserId], "catalogId": aFileRow[kFileFieldCatalogId], "name": strName, "ext": aFileRow[kFileFieldExt], "createTime": aFileRow[kFileFieldCreateTime], "uploadTime": aFileRow[kFileFieldUploadTime], "importTime": aFileRow[kFileFieldImportTime], "lastModifyTime": aFileRow[kFileFieldLastModifyTime], "size": aFileRow[kFileFieldSize], "type": aFileRow[kFileFieldType], "duration": aFileRow[kFileFieldDuration], "width": aFileRow[kFileFieldWidth], "height": aFileRow[kFileFieldHeight], "orientation": aFileRow[kFileFieldOrientation], "memo": aFileRow[kFileFieldMemo], "helpInt": aFileRow[kFileFieldHelpInt], "helpText": aFileRow[kFileFieldHelpText] } def _addUploading(aFullFileName, aUpSizeName): nSize = os.stat(aFullFileName).st_size if os.path.isfile( aFullFileName) else 0 fileInfo[aUpSizeName] = nSize if aFileRow[kFileFieldStatusForOrigin] == defines.kFileStatusFromUploading: #原始文件上传信息 cp = aFuncForPaths() if callable(aFuncForPaths) else aFuncForPaths fn = os.path.join(cp[aFileRow[kFileFieldRealCatalogId]], aFileRow[kFileFieldFileName]) _addUploading(fn, "uploadingOriginSize") if aFileRow[kFileFieldStatusForThumb] == defines.kFileStatusFromUploading: #小缩略图上传信息 fn = unit.getFileThumbFullFileName(aFileRow[kFileFieldRealCatalogId], aFileRow[kFileFieldId], 0) _addUploading(fn, "uploadingThumbSize") if aFileRow[kFileFieldStatusForScreen] == defines.kFileStatusFromUploading: #大缩略图上传信息 fn = unit.getFileThumbFullFileName(aFileRow[kFileFieldRealCatalogId], aFileRow[kFileFieldId], 1) _addUploading(fn, "uploadingScreenSize") unit.filterNullValue(fileInfo) return fileInfo
def buildUserInfo(aUserRow): "根据用户表信息生成发送给客户端的userInfo" userInfo = { "id": aUserRow[kUserFieldId], "name": aUserRow[kUserFieldName], "createTime": aUserRow[kUserFieldCreateTime], "lastLoginDate": aUserRow[kUserFieldLastLoginDate], "lastModifyTime": aUserRow[kUserFieldLastModifyTime], "helpInt": aUserRow[kUserFieldHelpInt], "helpText": aUserRow[kUserFieldHelpText] } unit.filterNullValue(userInfo) return userInfo
def appUpdateFile(): "上传文件信息" funcCheckStatus = lambda v: int(v) if int(v) in (defines.kFileStatusFromLocal, defines.kFileStatusFromUploading) else defines.kFileStatusFromLocal result = checkApiParam(True, ( {"name": "id", "checkfunc": unit.checkParamForInt}, {"name": "catalogId", "checkfunc": unit.checkParamForInt, "default": None}, {"name": "name", "checkfunc": lambda v: v if len(v) > 0 and len(v) <= 100 else None, "default": None}, {"name": "ext", "checkfunc": lambda v: v if len(v) <= 10 else None, "default": None}, {"name": "size", "checkfunc": unit.checkParamForInt, "default": None}, {"name": "type", "checkfunc": unit.checkParamForFileType, "default": None}, {"name": "statusForThumb", "checkfunc": funcCheckStatus, "default": None}, {"name": "statusForScreen", "checkfunc": funcCheckStatus, "default": None}, {"name": "createTime", "checkfunc": unit.checkParamForTimestamp, "default": None}, {"name": "importTime", "checkfunc": unit.checkParamForTimestamp, "default": None}, {"name": "lastModifyTime", "checkfunc": unit.checkParamForTimestamp, "default": None}, {"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] nFileId = param.pop("id") #目录信息 unit.filterNullValue(param) bOK = False if len(param) > 0: db = _getDbManager() bOK = db.updateFile(nFileId, param, loginInfo.rootIdsString) if bOK: fileRow = db.getFileByIdAndRootIds(nFileId, loginInfo.rootIdsString) funcForIdRelatePath = lambda : db.getCatalogIdRelatePathInfo(fileRow[dataManager.kFileFieldRealCatalogId]) fileInfo = dataManager.buildFileInfo(fileRow, funcForIdRelatePath) return responseHelp.buildSuccessResponseData(fileInfo) return responseHelp.buildErrorResponseData(responseHelp.kCmdUserError_NotModify)