Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
imwhatiam committed Dec 20, 2023
1 parent 0a336bf commit e4f17b3
Showing 1 changed file with 28 additions and 29 deletions.
57 changes: 28 additions & 29 deletions seahub/api2/endpoints/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,7 @@ def search_sdoc_node_recursively(children_list, type_sq=[], top_type=''):

if sdoc_type == 'code_block':

docx_paragraph = document.add_paragraph()
docx_paragraph.style = 'No Spacing'
docx_paragraph = document.add_paragraph(style="No Spacing")
docx_paragraph.paragraph_format.left_indent = Inches(0.2)

for text_dict in content:
Expand Down Expand Up @@ -427,6 +426,32 @@ def search_sdoc_node_recursively(children_list, type_sq=[], top_type=''):
docx_paragraph = document.add_paragraph()
add_hyperlink(docx_paragraph, link_href, link_title, "0000FF")

elif sdoc_type == 'paragraph' and \
any(item.get('type') in ('sdoc_link', 'file_link') for item in content):

# add sdoc/file link to docx

# ['paragraph',
# [{'id': 'D8omdcCLR4eLB3o4f0yOxw', 'text': ' '},
# {'children': [{'id': 'KFM5z7zvTaOcZyaT1zBhHQ', 'text': '987.sdoc'}],
# 'display_type': 'icon_link',
# 'doc_uuid': '45b266e4-17a5-475d-b601-10aa8001ea80',
# 'id': 'bIwxx0mMQVKRFo3LlYwf6A',
# 'title': '987.sdoc',
# 'type': 'sdoc_link'},
# {'id': 'G5WmlQ4tSpO4IH5CDFCdUA', 'text': ' '}]],

doc_uuid = ''
doc_title = ''
for item in content:
if 'doc_uuid' in item:
doc_uuid = item['doc_uuid']
if 'title' in item:
doc_title = item['title']
doc_url = get_service_url() + reverse('seadoc_file_view', args=[doc_uuid])
docx_paragraph = document.add_paragraph()
add_hyperlink(docx_paragraph, doc_url, doc_title, "0000FF")

elif sdoc_type in ('paragraph', 'image_block') and \
any(item.get('type') == 'image' for item in content):

Expand Down Expand Up @@ -459,32 +484,6 @@ def search_sdoc_node_recursively(children_list, type_sq=[], top_type=''):
image_content = resp.content
document.add_picture(io.BytesIO(image_content), width=Inches(5))

elif sdoc_type == 'paragraph' and \
any(item.get('type') in ('sdoc_link', 'file_link') for item in content):

# add sdoc/file link to docx

# ['paragraph',
# [{'id': 'D8omdcCLR4eLB3o4f0yOxw', 'text': ' '},
# {'children': [{'id': 'KFM5z7zvTaOcZyaT1zBhHQ', 'text': '987.sdoc'}],
# 'display_type': 'icon_link',
# 'doc_uuid': '45b266e4-17a5-475d-b601-10aa8001ea80',
# 'id': 'bIwxx0mMQVKRFo3LlYwf6A',
# 'title': '987.sdoc',
# 'type': 'sdoc_link'},
# {'id': 'G5WmlQ4tSpO4IH5CDFCdUA', 'text': ' '}]],

doc_uuid = ''
doc_title = ''
for item in content:
if 'doc_uuid' in item:
doc_uuid = item['doc_uuid']
if 'title' in item:
doc_title = item['title']
doc_url = get_service_url() + reverse('seadoc_file_view', args=[doc_uuid])
docx_paragraph = document.add_paragraph()
add_hyperlink(docx_paragraph, doc_url, doc_title, "0000FF")

elif sdoc_type == 'table':

# add table to docx
Expand Down Expand Up @@ -512,7 +511,7 @@ def fulfill_table(table, content):

for text_dict in content:

text = text_dict.get('text', '')
text = text_dict.get('text', '') or text_dict.get('href', '')
run = docx_paragraph.add_run(text)

bold = text_dict.get('bold', False)
Expand Down

0 comments on commit e4f17b3

Please sign in to comment.