999cc0f5c5
- правки onlyoffice.py/views.py/webdav_service.py под callback/контент и ключи; - blank_office перенесён в nextcloud_connector (генерация пустых Word/Excel); - documents.js + обновление шаблонов браузера/редактора/карточки документов; - тесты коннектора расширены. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
45 lines
1.8 KiB
Python
45 lines
1.8 KiB
Python
"""Пустые Word/Excel, которые открывает OnlyOffice / Word."""
|
|
from __future__ import annotations
|
|
|
|
from io import BytesIO
|
|
import zipfile
|
|
|
|
|
|
def empty_xlsx() -> bytes:
|
|
from openpyxl import Workbook
|
|
|
|
buf = BytesIO()
|
|
Workbook().save(buf)
|
|
return buf.getvalue()
|
|
|
|
|
|
def empty_docx() -> bytes:
|
|
"""Минимальный OOXML, который открывает OnlyOffice / Word."""
|
|
files = {
|
|
'[Content_Types].xml': (
|
|
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'
|
|
'<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">'
|
|
'<Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>'
|
|
'<Default Extension="xml" ContentType="application/xml"/>'
|
|
'<Override PartName="/word/document.xml" '
|
|
'ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"/>'
|
|
'</Types>'
|
|
),
|
|
'_rels/.rels': (
|
|
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'
|
|
'<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">'
|
|
'<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="word/document.xml"/>'
|
|
'</Relationships>'
|
|
),
|
|
'word/document.xml': (
|
|
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'
|
|
'<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">'
|
|
'<w:body><w:p><w:r><w:t></w:t></w:r></w:p></w:body></w:document>'
|
|
),
|
|
}
|
|
buf = BytesIO()
|
|
with zipfile.ZipFile(buf, 'w', zipfile.ZIP_DEFLATED) as zf:
|
|
for name, data in files.items():
|
|
zf.writestr(name, data)
|
|
return buf.getvalue()
|