Skip to content

Commit 43bb9a0

Browse files
committed
update tutorials
1 parent 082df85 commit 43bb9a0

File tree

2 files changed

+40
-29
lines changed

2 files changed

+40
-29
lines changed

docs/tutorials/python/tutorial_scripts/wiki.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
Tutorial script demonstrating the Synapse Wiki models functionality.
44
55
This script shows how to:
6-
1.
7-
2. Work with wiki headers and hierarchy
8-
3. Access wiki history
9-
4. Manage wiki order hints
10-
5. Handle attachments and markdown content
11-
6. Download wiki content and attachments
6+
1. Create, read, and update wiki pages
7+
2. Work with WikiPage Markdown
8+
3. Work with WikiPage Attachments
9+
4. Work with WikiHeader
10+
5. Work with WikiHistorySnapshot
11+
6. Work with WikiOrderHint
12+
7. Delete wiki pages
1213
"""
1314
import gzip
1415
import os
@@ -119,7 +120,7 @@ def hello_world():
119120
"""
120121

121122
# Create wiki page from markdown text
122-
markdown_wiki = WikiPage(
123+
markdown_wiki_1 = WikiPage(
123124
owner_id=my_test_project.id,
124125
parent_id=wiki_page_1.id,
125126
title="Sub Page 2 created from markdown text",
@@ -133,21 +134,21 @@ def hello_world():
133134
gz.write("This is a markdown file")
134135

135136
# Create wiki page from markdown file
136-
markdown_wiki = WikiPage(
137+
markdown_wiki_2 = WikiPage(
137138
owner_id=my_test_project.id,
138139
parent_id=wiki_page_1.id,
139140
title="Sub Page 3 created from markdown file",
140141
markdown=markdown_file_path,
141142
).store()
142143

143144
# Download the markdown file
144-
# delete the markdown file after downloading --> check if the file is downloaded
145+
# delete the markdown file after downloading
145146
os.remove(markdown_file_path)
146-
markdown_file = WikiPage(owner_id=my_test_project.id, id=markdown_wiki.id).get_markdown(
147-
download_file=True, download_location=".", download_file_name="markdown_file.md"
148-
)
147+
markdown_file_2 = WikiPage(
148+
owner_id=my_test_project.id, id=markdown_wiki_2.id
149+
).get_markdown(download_file=True, download_location=".")
149150

150-
print(f"Markdown file downloaded to: {markdown_file}")
151+
print(f"Markdown file downloaded to: {markdown_file_2}")
151152

152153
# Section 3: WikiPage with Attachments
153154
# Create a temporary file for the attachment

docs/tutorials/python/wiki.md

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,73 +12,83 @@ The Synapse Wiki models include:
1212
- **WikiHistorySnapshot**: Provides access to wiki version history
1313
- **WikiOrderHint**: Manages the order of wiki pages within an entity
1414

15+
This tutorial shows how to:
16+
1. Create, read, and update wiki pages
17+
2. Work with WikiPage Markdown
18+
3. Work with WikiPage Attachments
19+
4. Work with WikiHeader
20+
5. Work with WikiHistorySnapshot
21+
6. Work with WikiOrderHint
22+
7. Delete wiki pages
23+
1524
## Basic Setup
1625
```python
17-
{!docs/tutorials/python/tutorial_scripts/wiki.py!lines=13-28}
26+
{!docs/tutorials/python/tutorial_scripts/wiki.py!lines=14-29}
1827
```
1928

2029
## 1. Create, read, and update wiki pages
2130
### Create a new wiki page for the project with plain text markdown
2231
```python
23-
{!docs/tutorials/python/tutorial_scripts/wiki.py!lines=32-36}
32+
{!docs/tutorials/python/tutorial_scripts/wiki.py!lines=33-37}
2433
```
2534

2635
### OR you can create a wiki page with an existing markdown file
2736
```python
28-
{!docs/tutorials/python/tutorial_scripts/wiki.py!lines=39-44}
37+
{!docs/tutorials/python/tutorial_scripts/wiki.py!lines=40-45}
2938
```
3039

3140
### Create a new wiki page with updated content
3241
```python
33-
{!docs/tutorials/python/tutorial_scripts/wiki.py!lines=47-52}
42+
{!docs/tutorials/python/tutorial_scripts/wiki.py!lines=48-53}
3443
```
3544

3645
### Restore the wiki page to the original version
3746
```python
38-
{!docs/tutorials/python/tutorial_scripts/wiki.py!lines=55-63}
47+
{!docs/tutorials/python/tutorial_scripts/wiki.py!lines=56-64}
3948
```
4049

4150
### Create a sub-wiki page
4251
```python
43-
{!docs/tutorials/python/tutorial_scripts/wiki.py!lines=66-71}
52+
{!docs/tutorials/python/tutorial_scripts/wiki.py!lines=67-72}
4453
```
4554

4655
### Get an existing wiki page for the project, now you can see one root wiki page and one sub-wiki page
4756
```python
48-
{!docs/tutorials/python/tutorial_scripts/wiki.py!lines=74-75}
57+
{!docs/tutorials/python/tutorial_scripts/wiki.py!lines=75-76}
4958
```
5059

5160
### Retrieving a Wiki Page
5261
Note: You need to know the wiki page ID or wiki page title to retrieve it
5362
#### Retrieve a Wiki Page with wiki page ID
5463
```python
55-
{!docs/tutorials/python/tutorial_scripts/wiki.py!lines=78-79}
64+
{!docs/tutorials/python/tutorial_scripts/wiki.py!lines=79-80}
5665
```
5766

5867
#### Retrieve a Wiki Page with wiki page title
5968
```python
60-
{!docs/tutorials/python/tutorial_scripts/wiki.py!lines=82-83}
69+
{!docs/tutorials/python/tutorial_scripts/wiki.py!lines=83-84}
6170
```
6271

6372
#### Check if the retrieved wiki page is the same as the original wiki page
6473
```python
65-
{!docs/tutorials/python/tutorial_scripts/wiki.py!lines=86-91}
74+
{!docs/tutorials/python/tutorial_scripts/wiki.py!lines=87-92}
6675
```
6776

6877
## 2. WikiPage Markdown Operations
6978
### Create wiki page from markdown text
7079
```python
71-
{!docs/tutorials/python/tutorial_scripts/wiki.py!lines=95-118}
80+
{!docs/tutorials/python/tutorial_scripts/wiki.py!lines=96-119}
7281
```
7382

74-
### Create wiki page from a markdown file
83+
### Create wiki page from a markdown file
7584
```python
76-
{!docs/tutorials/python/tutorial_scripts/wiki.py!lines=122-132}
85+
{!docs/tutorials/python/tutorial_scripts/wiki.py!lines=123-133}
7786
```
7887

7988
### Download the markdown file
89+
Note: If the markdown is generated from plain text using the client, the downloaded file will be named wiki_markdown_<wiki_page_id>.md.gz. If it is generated from an existing markdown file, the downloaded file will retain the original filename with the .gz suffix appended.
8090
```python
81-
{!docs/tutorials/python/tutorial_scripts/wiki.py!lines=136-143}
91+
{!docs/tutorials/python/tutorial_scripts/wiki.py!lines=137-143}
8292
```
8393

8494
## 3. WikiPage Attachments Operations
@@ -92,7 +102,7 @@ Note: You need to know the wiki page ID or wiki page title to retrieve it
92102
```
93103
### Download an attachment
94104
```python
95-
{!docs/tutorials/python/tutorial_scripts/wiki.py!lines=168-175}
105+
{!docs/tutorials/python/tutorial_scripts/wiki.py!lines=167-175}
96106
```
97107

98108
### Get attachment URL without downloading
@@ -117,7 +127,7 @@ Note: You need to know the wiki page ID or wiki page title to retrieve it
117127

118128
### Accessing Wiki History
119129
```python
120-
{!docs/tutorials/python/tutorial_scripts/wiki.py!lines=203-207}
130+
{!docs/tutorials/python/tutorial_scripts/wiki.py!lines=204-208}
121131
```
122132

123133
## 6. WikiOrderHint - Managing Wiki Order

0 commit comments

Comments
 (0)