From f1f7fa887ed6873568a8d6a2eb388b45f168c2fc Mon Sep 17 00:00:00 2001 From: vanyauhalin Date: Fri, 28 Jul 2023 12:03:16 +0400 Subject: [PATCH] python: replace the previous implementation of formats --- .../python/src/configuration/configuration.py | 72 ------------------- .../python/src/utils/docManager.py | 10 +-- .../python/src/utils/fileUtils.py | 8 ++- .../python/src/views/index.py | 8 ++- 4 files changed, 16 insertions(+), 82 deletions(-) diff --git a/web/documentserver-example/python/src/configuration/configuration.py b/web/documentserver-example/python/src/configuration/configuration.py index 0334d35ef..a0e1d5965 100644 --- a/web/documentserver-example/python/src/configuration/configuration.py +++ b/web/documentserver-example/python/src/configuration/configuration.py @@ -111,78 +111,6 @@ def conversion_timeout(self) -> int: return int(timeout) return 120 * 1000 - def fillable_file_extensions(self) -> list[str]: - return [ - '.docx', - '.oform' - ] - - def viewable_file_extensions(self) -> list[str]: - return [ - '.djvu', - '.oxps', - '.pdf', - '.xps' - ] - - def editable_file_extensions(self) -> list[str]: - return [ - '.csv', '.docm', '.docx', - '.docxf', '.dotm', '.dotx', - '.epub', '.fb2', '.html', - '.odp', '.ods', '.odt', - '.otp', '.ots', '.ott', - '.potm', '.potx', '.ppsm', - '.ppsx', '.pptm', '.pptx', - '.rtf', '.txt', '.xlsm', - '.xlsx', '.xltm', '.xltx' - ] - - def convertible_file_extensions(self) -> list[str]: - return [ - '.doc', '.dot', '.dps', '.dpt', - '.epub', '.et', '.ett', '.fb2', - '.fodp', '.fods', '.fodt', '.htm', - '.html', '.mht', '.mhtml', '.odp', - '.ods', '.odt', '.otp', '.ots', - '.ott', '.pot', '.pps', '.ppt', - '.rtf', '.stw', '.sxc', '.sxi', - '.sxw', '.wps', '.wpt', '.xls', - '.xlsb', '.xlt', '.xml' - ] - - def spreadsheet_file_extensions(self) -> list[str]: - return [ - '.xls', '.xlsx', - '.xlsm', '.xlsb', - '.xlt', '.xltx', - '.xltm', '.ods', - '.fods', '.ots', - '.csv' - ] - - def presentation_file_extensions(self) -> list[str]: - return [ - '.pps', '.ppsx', - '.ppsm', '.ppt', - '.pptx', '.pptm', - '.pot', '.potx', - '.potm', '.odp', - '.fodp', '.otp' - ] - - def document_file_extensions(self) -> list[str]: - return [ - '.doc', '.docx', '.docm', - '.dot', '.dotx', '.dotm', - '.odt', '.fodt', '.ott', - '.rtf', '.txt', '.html', - '.htm', '.mht', '.xml', - '.pdf', '.djvu', '.fb2', - '.epub', '.xps', '.oxps', - '.oform' - ] - def languages(self) -> dict[str, str]: return { 'en': 'English', diff --git a/web/documentserver-example/python/src/utils/docManager.py b/web/documentserver-example/python/src/utils/docManager.py index 2e6e8214e..2a8dd5004 100755 --- a/web/documentserver-example/python/src/utils/docManager.py +++ b/web/documentserver-example/python/src/utils/docManager.py @@ -29,24 +29,26 @@ from django.conf import settings from django.http import HttpResponse, HttpResponseRedirect, FileResponse from src.configuration import ConfigurationManager +from src.format import FormatManager from . import fileUtils, historyManager config_manager = ConfigurationManager() +format_manager = FormatManager() def isCanFillForms(ext): - return ext in config_manager.fillable_file_extensions() + return ext in format_manager.fillable_extensions() # check if the file extension can be viewed def isCanView(ext): - return ext in config_manager.viewable_file_extensions() + return ext in format_manager.viewable_extensions() # check if the file extension can be edited def isCanEdit(ext): - return ext in config_manager.editable_file_extensions() + return ext in format_manager.editable_extensions() # check if the file extension can be converted def isCanConvert(ext): - return ext in config_manager.convertible_file_extensions() + return ext in format_manager.convertible_extensions() # check if the file extension is supported by the editor (it can be viewed or edited or converted) def isSupportedExt(ext): diff --git a/web/documentserver-example/python/src/utils/fileUtils.py b/web/documentserver-example/python/src/utils/fileUtils.py index ac231e8b0..cd8279c14 100644 --- a/web/documentserver-example/python/src/utils/fileUtils.py +++ b/web/documentserver-example/python/src/utils/fileUtils.py @@ -17,8 +17,10 @@ """ from src.configuration import ConfigurationManager +from src.format import FormatManager config_manager = ConfigurationManager() +format_manager = FormatManager() # get file name from the document url def getFileName(str): @@ -40,11 +42,11 @@ def getFileExt(str): # get file type def getFileType(str): ext = getFileExt(str) - if ext in config_manager.document_file_extensions(): + if ext in format_manager.document_extensions(): return 'word' - if ext in config_manager.spreadsheet_file_extensions(): + if ext in format_manager.spreadsheet_extensions(): return 'cell' - if ext in config_manager.presentation_file_extensions(): + if ext in format_manager.presentation_extensions(): return 'slide' return 'word' # default file type is word \ No newline at end of file diff --git a/web/documentserver-example/python/src/views/index.py b/web/documentserver-example/python/src/views/index.py index 369bee67a..3d69d088c 100755 --- a/web/documentserver-example/python/src/views/index.py +++ b/web/documentserver-example/python/src/views/index.py @@ -23,10 +23,12 @@ from django.shortcuts import render from src.configuration import ConfigurationManager +from src.format import FormatManager from src.utils import users from src.utils import docManager config_manager = ConfigurationManager() +format_manager = FormatManager() def getDirectUrlParam(request): if ('directUrl' in request.GET): @@ -39,10 +41,10 @@ def default(request): # default parameters that will be passed to the template 'users': users.USERS, 'languages': config_manager.languages(), 'preloadurl': config_manager.document_server_preloader_url().geturl(), - 'editExt': json.dumps(config_manager.editable_file_extensions()), # file extensions that can be edited - 'convExt': json.dumps(config_manager.convertible_file_extensions()), # file extensions that can be converted + 'editExt': json.dumps(format_manager.editable_extensions()), # file extensions that can be edited + 'convExt': json.dumps(format_manager.convertible_extensions()), # file extensions that can be converted 'files': docManager.getStoredFiles(request), # information about stored files - 'fillExt': json.dumps(config_manager.fillable_file_extensions()), + 'fillExt': json.dumps(format_manager.fillable_extensions()), 'directUrl': str(getDirectUrlParam(request)).lower } return render(request, 'index.html', context) # execute the "index.html" template with context data and return http response in json format \ No newline at end of file