Skip to content

Commit

Permalink
python: replace the previous implementation of formats
Browse files Browse the repository at this point in the history
  • Loading branch information
vanyauhalin committed Aug 16, 2023
1 parent 7b569a1 commit f1f7fa8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
10 changes: 6 additions & 4 deletions web/documentserver-example/python/src/utils/docManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
8 changes: 5 additions & 3 deletions web/documentserver-example/python/src/utils/fileUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
8 changes: 5 additions & 3 deletions web/documentserver-example/python/src/views/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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

0 comments on commit f1f7fa8

Please sign in to comment.