我有一个带有表格的Confluence页面,我通过Python代码更新它,有一个单元格,我需要在其中放置文件链接。
首先,我使用
将此单元格放入没有链接的带下划线的行中'<td>
<div class="content-wrapper">
<p>
<ac:link>
<ri:attachment ri:filename="File_name.docx">
<ri:page ri:content-title="Title_name" />
</ri:attachment>
</ac:link>
</p>
</div>
</td>'.
其次,我使用
将文件上传到整个 Confluence 页面conf.attach_file(location, name=None, content_type=None, page_id=00000000, title="Check", space=None, comment="None")
第三,我通过Confluence中的宏Attachment检查文件是否已附加到页面。但是,当我更新页面时,没有任何变化。因此,那些带下划线的灰色行仍然是灰色的,它们不会变成蓝色作为链接,尽管文件名当然是相同的。
你能帮我一下吗?可能有什么问题?
谢谢!
所以我测试了您帖子中的 confluence xhtml 代码,它肯定不起作用。不过,我对您尝试使用该代码执行的操作感到困惑,您不需要
将附件上传到 confluence,就像使用 python 一样。 然后你必须获取附件的 URL:
all_attachments = confluence.get_attachments_from_content(page_id, start=0, limit=50, expand=None, filename=None, media_type=None)
这将打印出一个大的 JSON 字符串。 那里的某个地方(对不起,我没有时间找出索引)是链接。 链接如下所示:其中(页面 id 是页面的 id),filename.txt 是您的文件名
http://wiki:8090/download/attachments/page_id/filename.txt?version=1&modificationDate=1679673853281&api=v2
您将看到,如果您更新页面上的附件,链接将更改为:
http://wiki:8090/download/attachments/page_id/filename.txt?version=2&modificationDate=1679674473211&api=v2
因此,如果您使用 version=1 的旧链接,您将获得旧版本。
要解决此问题:您可以将 URL 更改为:
http://wiki:8090/download/attachments/page_id/filename.txt
自己创建 URL 可能会更容易(根据我的经验,这没有问题):
url = f"http://wiki:8090/download/attachments/{page_id}/{filename}"
现在您已经有了链接,您可以将其附加到 confluence 中 我不确定您实际上对这些文件做了什么,所以这里是一个例子:
html_link = f'<a href={url}>Press here to go to file.txt</a>'
然后将代码放在 bs4 的 confluence 页面中的某个位置:
#Lets say you have a td with class "file_goes_here" already in your XHTML
cell = (soup.find("td", {"class": "file_goes_here"})
#html_link is the link we created earlier above
cell.replace_with(html_link)
然后用新内容更新 Confluence 页面:
confluence.update_page(page_id, title, body, parent_id=None, type='page', representation='storage', minor_edit=False, full_width=False)