mirror of
https://github.com/ONLYOFFICE/document-server-integration.git
synced 2026-04-07 14:06:11 +08:00
python: submit filled form
This commit is contained in:
@ -95,6 +95,23 @@ def createMeta(storagePath, req):
|
||||
|
||||
return
|
||||
|
||||
def createMetaData(filename, uid, uname, usAddr):
|
||||
histDir = getHistoryDir(docManager.getStoragePath(filename, usAddr))
|
||||
path = getMetaPath(histDir)
|
||||
|
||||
if not os.path.exists(histDir):
|
||||
os.makedirs(histDir)
|
||||
|
||||
obj = {
|
||||
'created': datetime.today().strftime('%Y-%m-%d %H:%M:%S'),
|
||||
'uid': uid,
|
||||
'uname': uname
|
||||
}
|
||||
|
||||
writeFile(path, json.dumps(obj))
|
||||
|
||||
return
|
||||
|
||||
def writeFile(path, content):
|
||||
with io.open(path, 'w') as out:
|
||||
out.write(content)
|
||||
|
||||
@ -50,7 +50,7 @@ def readBody(request):
|
||||
body = body['payload']
|
||||
return body
|
||||
|
||||
def processSave(body, filename, usAddr, request):
|
||||
def processSave(body, filename, usAddr):
|
||||
download = body.get('url')
|
||||
changesUri = body.get('changesurl')
|
||||
newFilename = filename
|
||||
@ -62,11 +62,11 @@ def processSave(body, filename, usAddr, request):
|
||||
try:
|
||||
newUri = serviceConverter.getConverterUri(download, downloadExt, curExt, docManager.generateRevisionId(download), False)
|
||||
if not newUri:
|
||||
newFilename = docManager.getCorrectName(fileUtils.getFileNameWithoutExt(filename) + downloadExt, request)
|
||||
newFilename = docManager.getCorrectName(fileUtils.getFileNameWithoutExt(filename) + downloadExt, usAddr)
|
||||
else:
|
||||
download = newUri
|
||||
except Exception:
|
||||
newFilename = docManager.getCorrectName(fileUtils.getFileNameWithoutExt(filename) + downloadExt, request)
|
||||
newFilename = docManager.getCorrectName(fileUtils.getFileNameWithoutExt(filename) + downloadExt, usAddr)
|
||||
|
||||
path = docManager.getStoragePath(newFilename, usAddr)
|
||||
|
||||
@ -89,34 +89,45 @@ def processSave(body, filename, usAddr, request):
|
||||
|
||||
historyManager.writeFile(historyManager.getKeyPath(versionDir), body.get('key'))
|
||||
|
||||
forcesavePath = docManager.getForcesavePath(newFilename, request, False)
|
||||
forcesavePath = docManager.getForcesavePath(newFilename, usAddr, False)
|
||||
if (forcesavePath != ""):
|
||||
os.remove(forcesavePath)
|
||||
|
||||
return
|
||||
|
||||
def processForceSave(body, filename, usAddr, request):
|
||||
def processForceSave(body, filename, usAddr):
|
||||
download = body.get('url')
|
||||
|
||||
curExt = fileUtils.getFileExt(filename)
|
||||
downloadExt = fileUtils.getFileExt(download)
|
||||
newFilename = filename
|
||||
|
||||
if (curExt != downloadExt):
|
||||
try:
|
||||
newUri = serviceConverter.getConverterUri(download, downloadExt, curExt, docManager.generateRevisionId(download), False)
|
||||
if not newUri:
|
||||
filename = docManager.getCorrectName(fileUtils.getFileNameWithoutExt(filename) + downloadExt, request)
|
||||
newFilename = docManager.getCorrectName(fileUtils.getFileNameWithoutExt(filename) + downloadExt, usAddr)
|
||||
else:
|
||||
download = newUri
|
||||
except Exception:
|
||||
filename = docManager.getCorrectName(fileUtils.getFileNameWithoutExt(filename) + downloadExt, request)
|
||||
newFilename = docManager.getCorrectName(fileUtils.getFileNameWithoutExt(filename) + downloadExt, usAddr)
|
||||
|
||||
forcesavePath = docManager.getForcesavePath(filename, request, False)
|
||||
if (forcesavePath == ""):
|
||||
forcesavePath = docManager.getForcesavePath(filename, request, True)
|
||||
isSubmitForm = body.get('forcesavetype') == 3
|
||||
|
||||
if(isSubmitForm):
|
||||
if (newFilename == filename):
|
||||
newFilename = docManager.getCorrectName(filename, usAddr)
|
||||
forcesavePath = docManager.getStoragePath(newFilename, usAddr)
|
||||
else:
|
||||
forcesavePath = docManager.getForcesavePath(newFilename, usAddr, False)
|
||||
if (forcesavePath == ""):
|
||||
forcesavePath = docManager.getForcesavePath(newFilename, usAddr, True)
|
||||
|
||||
docManager.saveFileFromUri(download, forcesavePath)
|
||||
|
||||
if(isSubmitForm):
|
||||
uid = body['actions'][0]['userid']
|
||||
historyManager.createMetaData(newFilename, uid, "Filling Form", usAddr)
|
||||
return
|
||||
|
||||
def commandRequest(method, key):
|
||||
|
||||
@ -130,6 +130,7 @@ def edit(request):
|
||||
|
||||
edMode = request.GET.get('mode') if request.GET.get('mode') else 'edit'
|
||||
canEdit = docManager.isCanEdit(ext)
|
||||
submitForm = canEdit & ((edMode == 'edit') | (edMode == 'fillForms'))
|
||||
mode = 'edit' if canEdit & (edMode != 'view') else 'view'
|
||||
|
||||
edType = request.GET.get('type') if request.GET.get('type') else 'desktop'
|
||||
@ -192,7 +193,8 @@ def edit(request):
|
||||
'customization': {
|
||||
'about': True,
|
||||
'feedback': True,
|
||||
'forcesave': False,
|
||||
'forcesave': True,
|
||||
'submitForm': submitForm,
|
||||
'goback': {
|
||||
'url': docManager.getServerUrl(False, request)
|
||||
}
|
||||
@ -252,9 +254,9 @@ def track(request):
|
||||
usAddr = request.GET['userAddress']
|
||||
|
||||
if (status == 2) | (status == 3): # mustsave, corrupted
|
||||
trackManager.processSave(body, filename, usAddr, request)
|
||||
trackManager.processSave(body, filename, usAddr)
|
||||
if (status == 6) | (status == 7): # mustforcesave, corruptedforcesave
|
||||
trackManager.processForceSave(body, filename, usAddr, request)
|
||||
trackManager.processForceSave(body, filename, usAddr)
|
||||
|
||||
except Exception as e:
|
||||
response.setdefault('error', 1)
|
||||
|
||||
Reference in New Issue
Block a user