Skip to content

Commit bef7da2

Browse files
committed
Add adjustments
1 parent ff73c6e commit bef7da2

3 files changed

Lines changed: 3769 additions & 37 deletions

File tree

atlassian/confluence/cloud/__init__.py

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
# coding=utf-8
22

3+
import logging
34
from .base import ConfluenceCloudBase
5+
from requests import HTTPError
6+
from atlassian.errors import (
7+
ApiError,
8+
)
9+
10+
log = logging.getLogger(__name__)
411

512

613
class Cloud(ConfluenceCloudBase):
@@ -68,6 +75,81 @@ def get_content_ancestors(self, content_id, **kwargs):
6875
"""Get ancestor content."""
6976
return self.get(f"content/{content_id}/ancestors", **kwargs)
7077

78+
def get_page_by_title(self, space_key, title, **kwargs):
79+
"""Get page by title and space key."""
80+
return self.get("content", params={"spaceKey": space_key, "title": title, "type": "page", **kwargs})
81+
82+
def page_exists(self, space_key, title, **kwargs):
83+
"""Check if page exists in Confluence Cloud."""
84+
result = self.get_page_by_title(space_key, title, **kwargs)
85+
return len(result.get("results", [])) > 0
86+
87+
def get_page_child_by_type(self, page_id, type="page", start=None, limit=None, expand=None):
88+
"""
89+
Provide content by type (page, blog, comment)
90+
:param page_id: A string containing the id of the type content container.
91+
:param type:
92+
:param start: OPTIONAL: The start point of the collection to return. Default: None (0).
93+
:param limit: OPTIONAL: how many items should be returned after the start index. Default: Site limit 200.
94+
:param expand: OPTIONAL: expand e.g. history
95+
:return:
96+
"""
97+
params = {}
98+
if start is not None:
99+
params["start"] = int(start)
100+
if limit is not None:
101+
params["limit"] = int(limit)
102+
if expand is not None:
103+
params["expand"] = expand
104+
105+
url = f"rest/api/content/{page_id}/child/{type}"
106+
log.info(url)
107+
108+
try:
109+
if not self.advanced_mode and start is None and limit is None:
110+
return self._get_paged(url, params=params)
111+
else:
112+
response = self.get(url, params=params)
113+
if self.advanced_mode:
114+
return response
115+
return response.get("results")
116+
except HTTPError as e:
117+
if e.response.status_code == 404:
118+
# Raise ApiError as the documented reason is ambiguous
119+
raise ApiError(
120+
"There is no content with the given id, "
121+
"or the calling user does not have permission to view the content",
122+
reason=e,
123+
)
124+
125+
raise
126+
127+
def get_child_title_list(self, page_id, type="page", start=None, limit=None):
128+
"""
129+
Find a list of Child title
130+
:param page_id: A string containing the id of the type content container.
131+
:param type:
132+
:param start: OPTIONAL: The start point of the collection to return. Default: None (0).
133+
:param limit: OPTIONAL: how many items should be returned after the start index. Default: Site limit 200.
134+
:return:
135+
"""
136+
child_page = self.get_page_child_by_type(page_id, type, start, limit)
137+
child_title_list = [child["title"] for child in child_page]
138+
return child_title_list
139+
140+
def get_child_id_list(self, page_id, type="page", start=None, limit=None):
141+
"""
142+
Find a list of Child id
143+
:param page_id: A string containing the id of the type content container.
144+
:param type:
145+
:param start: OPTIONAL: The start point of the collection to return. Default: None (0).
146+
:param limit: OPTIONAL: how many items should be returned after the start index. Default: Site limit 200.
147+
:return:
148+
"""
149+
child_page = self.get_page_child_by_type(page_id, type, start, limit)
150+
child_id_list = [child["id"] for child in child_page]
151+
return child_id_list
152+
71153
# Space Management
72154
def get_spaces(self, **kwargs):
73155
"""

0 commit comments

Comments
 (0)