Skip to content

Commit

Permalink
create office file with new template (#5891)
Browse files Browse the repository at this point in the history
  • Loading branch information
imwhatiam authored Jan 12, 2024
1 parent 34615f2 commit 18346c5
Show file tree
Hide file tree
Showing 78 changed files with 32 additions and 9 deletions.
Binary file added media/office-template/empty.docxf
Binary file not shown.
Binary file added media/office-template/new/cs-CZ/new.docx
Binary file not shown.
Binary file added media/office-template/new/cs-CZ/new.docxf
Binary file not shown.
Binary file added media/office-template/new/cs-CZ/new.pptx
Binary file not shown.
Binary file added media/office-template/new/cs-CZ/new.xlsx
Binary file not shown.
Binary file added media/office-template/new/de-DE/new.docx
Binary file not shown.
Binary file added media/office-template/new/de-DE/new.docxf
Binary file not shown.
Binary file added media/office-template/new/de-DE/new.pptx
Binary file not shown.
Binary file added media/office-template/new/de-DE/new.xlsx
Binary file not shown.
Binary file added media/office-template/new/el-GR/new.docx
Binary file not shown.
Binary file added media/office-template/new/el-GR/new.docxf
Binary file not shown.
Binary file added media/office-template/new/el-GR/new.pptx
Binary file not shown.
Binary file added media/office-template/new/el-GR/new.xlsx
Binary file not shown.
Binary file added media/office-template/new/en-US/new.docx
Binary file not shown.
Binary file added media/office-template/new/en-US/new.docxf
Binary file not shown.
Binary file added media/office-template/new/en-US/new.pptx
Binary file not shown.
Binary file added media/office-template/new/en-US/new.xlsx
Binary file not shown.
Binary file added media/office-template/new/es-ES/new.docx
Binary file not shown.
Binary file added media/office-template/new/es-ES/new.docxf
Binary file not shown.
Binary file added media/office-template/new/es-ES/new.pptx
Binary file not shown.
Binary file added media/office-template/new/es-ES/new.xlsx
Binary file not shown.
Binary file added media/office-template/new/fr-FR/new.docx
Binary file not shown.
Binary file added media/office-template/new/fr-FR/new.docxf
Binary file not shown.
Binary file added media/office-template/new/fr-FR/new.pptx
Binary file not shown.
Binary file added media/office-template/new/fr-FR/new.xlsx
Binary file not shown.
Binary file added media/office-template/new/it-IT/new.docx
Binary file not shown.
Binary file added media/office-template/new/it-IT/new.docxf
Binary file not shown.
Binary file added media/office-template/new/it-IT/new.pptx
Binary file not shown.
Binary file added media/office-template/new/it-IT/new.xlsx
Binary file not shown.
Binary file added media/office-template/new/ja-JP/new.docx
Binary file not shown.
Binary file added media/office-template/new/ja-JP/new.docxf
Binary file not shown.
Binary file added media/office-template/new/ja-JP/new.pptx
Binary file not shown.
Binary file added media/office-template/new/ja-JP/new.xlsx
Binary file not shown.
Binary file added media/office-template/new/ko-KR/new.docx
Binary file not shown.
Binary file added media/office-template/new/ko-KR/new.docxf
Binary file not shown.
Binary file added media/office-template/new/ko-KR/new.pptx
Binary file not shown.
Binary file added media/office-template/new/ko-KR/new.xlsx
Binary file not shown.
Binary file added media/office-template/new/lv-LV/new.docx
Binary file not shown.
Binary file added media/office-template/new/lv-LV/new.docxf
Binary file not shown.
Binary file added media/office-template/new/lv-LV/new.pptx
Binary file not shown.
Binary file added media/office-template/new/lv-LV/new.xlsx
Binary file not shown.
Binary file added media/office-template/new/nl-NL/new.docx
Binary file not shown.
Binary file added media/office-template/new/nl-NL/new.docxf
Binary file not shown.
Binary file added media/office-template/new/nl-NL/new.pptx
Binary file not shown.
Binary file added media/office-template/new/nl-NL/new.xlsx
Binary file not shown.
Binary file added media/office-template/new/pl-PL/new.docx
Binary file not shown.
Binary file added media/office-template/new/pl-PL/new.docxf
Binary file not shown.
Binary file added media/office-template/new/pl-PL/new.pptx
Binary file not shown.
Binary file added media/office-template/new/pl-PL/new.xlsx
Binary file not shown.
Binary file added media/office-template/new/pt-BR/new.docx
Binary file not shown.
Binary file added media/office-template/new/pt-BR/new.docxf
Binary file not shown.
Binary file added media/office-template/new/pt-BR/new.pptx
Binary file not shown.
Binary file added media/office-template/new/pt-BR/new.xlsx
Binary file not shown.
Binary file added media/office-template/new/ru-RU/new.docx
Binary file not shown.
Binary file added media/office-template/new/ru-RU/new.docxf
Binary file not shown.
Binary file added media/office-template/new/ru-RU/new.pptx
Binary file not shown.
Binary file added media/office-template/new/ru-RU/new.xlsx
Binary file not shown.
Binary file added media/office-template/new/sv-SE/new.docx
Binary file not shown.
Binary file added media/office-template/new/sv-SE/new.docxf
Binary file not shown.
Binary file added media/office-template/new/sv-SE/new.pptx
Binary file not shown.
Binary file added media/office-template/new/sv-SE/new.xlsx
Binary file not shown.
Binary file added media/office-template/new/uk-UA/new.docx
Binary file not shown.
Binary file added media/office-template/new/uk-UA/new.docxf
Binary file not shown.
Binary file added media/office-template/new/uk-UA/new.pptx
Binary file not shown.
Binary file added media/office-template/new/uk-UA/new.xlsx
Binary file not shown.
Binary file added media/office-template/new/vi-VN/new.docx
Binary file not shown.
Binary file added media/office-template/new/vi-VN/new.docxf
Binary file not shown.
Binary file added media/office-template/new/vi-VN/new.pptx
Binary file not shown.
Binary file added media/office-template/new/vi-VN/new.xlsx
Binary file not shown.
Binary file added media/office-template/new/zh-CN/new.docx
Binary file not shown.
Binary file added media/office-template/new/zh-CN/new.docxf
Binary file not shown.
Binary file added media/office-template/new/zh-CN/new.pptx
Binary file not shown.
Binary file added media/office-template/new/zh-CN/new.xlsx
Binary file not shown.
Binary file added media/office-template/new/zh-TW/new.docx
Binary file not shown.
Binary file added media/office-template/new/zh-TW/new.docxf
Binary file not shown.
Binary file added media/office-template/new/zh-TW/new.pptx
Binary file not shown.
Binary file added media/office-template/new/zh-TW/new.xlsx
Binary file not shown.
41 changes: 32 additions & 9 deletions seahub/api2/endpoints/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ def post(self, request, repo_id, format=None):
is_draft = request.POST.get('is_draft', '')

if operation == 'create':

# resource check
try:
parent_dir_id = seafile_api.get_dir_id_by_path(repo_id, parent_dir)
Expand Down Expand Up @@ -223,15 +224,37 @@ def post(self, request, repo_id, format=None):
if is_draft.lower() == 'true':
Draft.objects.add(username, repo, path, file_exist=False)

# update office file by template
if new_file_name.endswith('.xlsx'):
empty_file_path = os.path.join(OFFICE_TEMPLATE_ROOT, 'empty.xlsx')
elif new_file_name.endswith('.pptx'):
empty_file_path = os.path.join(OFFICE_TEMPLATE_ROOT, 'empty.pptx')
elif new_file_name.endswith('.docx'):
empty_file_path = os.path.join(OFFICE_TEMPLATE_ROOT, 'empty.docx')
else:
empty_file_path = ''
LANGUAGE_DICT = {
'cs': 'cs-CZ',
'de': 'de-DE',
'en': 'en-US',
'es': 'es-ES',
'fr': 'fr-FR',
'it': 'it-IT',
'lv': 'lv-LV',
'nl': 'nl-NL',
'pl': 'pl-PL',
'pt-br': 'pt-BR',
'ru': 'ru-RU',
'sv': 'sv-SE',
'vi': 'vi-VN',
'uk': 'uk-UA',
'el': 'el-GR',
'ko': 'ko-KR',
'ja': 'ja-JP',
'zh-cn': 'zh-CN',
'zh-tw': 'zh-TW'
}

empty_file_path = ''
not_used, file_extension = os.path.splitext(new_file_name)
if file_extension in ('.xlsx', '.pptx', '.docx', '.docxf'):
# update office file by template
empty_file_path = os.path.join(OFFICE_TEMPLATE_ROOT, f'empty{file_extension}')
language_code_path = LANGUAGE_DICT.get(request.LANGUAGE_CODE)
if language_code_path:
empty_file_path = os.path.join(OFFICE_TEMPLATE_ROOT, 'new',
language_code_path, f'new{file_extension}')

if empty_file_path:
# get file server update url
Expand Down

0 comments on commit 18346c5

Please sign in to comment.