Skip to content

Commit e745aeb

Browse files
author
Gonchik Tsymzhitov
committed
Confluence: make body parameter for update page
1 parent c409e92 commit e745aeb

File tree

1 file changed

+43
-43
lines changed

1 file changed

+43
-43
lines changed

atlassian/confluence.py

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,7 +1143,7 @@ def update_existing_page(self, page_id, title, body, type='page', representation
11431143
minor_edit=minor_edit,
11441144
version_comment=version_comment)
11451145

1146-
def update_page(self, page_id, title, body, parent_id=None, type='page', representation='storage',
1146+
def update_page(self, page_id, title, body=None, parent_id=None, type='page', representation='storage',
11471147
minor_edit=False, version_comment=None):
11481148
"""
11491149
Update page if already exist
@@ -1160,50 +1160,51 @@ def update_page(self, page_id, title, body, parent_id=None, type='page', represe
11601160
"""
11611161
log.info('Updating {type} "{title}"'.format(title=title, type=type))
11621162

1163-
if self.is_page_content_is_already_updated(page_id, body, title):
1163+
if body is not None and self.is_page_content_is_already_updated(page_id, body, title):
11641164
return self.get_page_by_id(page_id)
1165-
else:
1166-
try:
1167-
if self.advanced_mode:
1168-
version = self.history(page_id).json()['lastUpdated']['number'] + 1
1169-
else:
1170-
version = self.history(page_id)['lastUpdated']['number'] + 1
1171-
except (IndexError, TypeError) as e:
1172-
log.error("Can't find '{title}' {type}!".format(title=title, type=type))
1173-
log.debug(e)
1174-
return None
11751165

1176-
data = {
1177-
'id': page_id,
1178-
'type': type,
1179-
'title': title,
1180-
'body': self._create_body(body, representation),
1181-
'version': {'number': version,
1182-
'minorEdit': minor_edit}
1183-
}
1166+
try:
1167+
if self.advanced_mode:
1168+
version = self.history(page_id).json()['lastUpdated']['number'] + 1
1169+
else:
1170+
version = self.history(page_id)['lastUpdated']['number'] + 1
1171+
except (IndexError, TypeError) as e:
1172+
log.error("Can't find '{title}' {type}!".format(title=title, type=type))
1173+
log.debug(e)
1174+
return None
11841175

1185-
if parent_id:
1186-
data['ancestors'] = [{'type': 'page', 'id': parent_id}]
1187-
if version_comment:
1188-
data['version']['message'] = version_comment
1176+
data = {
1177+
'id': page_id,
1178+
'type': type,
1179+
'title': title,
1180+
'version': {'number': version,
1181+
'minorEdit': minor_edit}
1182+
}
1183+
if body is not None:
1184+
data['body'] = self._create_body(body, representation)
11891185

1190-
try:
1191-
response = self.put('rest/api/content/{0}'.format(page_id), data=data)
1192-
except HTTPError as e:
1193-
if e.response.status_code == 400:
1194-
raise ApiValueError(
1195-
"No space or no content type, or setup a wrong version "
1196-
"type set to content, or status param is not draft and "
1197-
"status content is current",
1198-
reason=e)
1199-
if e.response.status_code == 404:
1200-
raise ApiNotFoundError(
1201-
"Can not find draft with current content",
1202-
reason=e)
1186+
if parent_id:
1187+
data['ancestors'] = [{'type': 'page', 'id': parent_id}]
1188+
if version_comment:
1189+
data['version']['message'] = version_comment
12031190

1204-
raise
1191+
try:
1192+
response = self.put('rest/api/content/{0}'.format(page_id), data=data)
1193+
except HTTPError as e:
1194+
if e.response.status_code == 400:
1195+
raise ApiValueError(
1196+
"No space or no content type, or setup a wrong version "
1197+
"type set to content, or status param is not draft and "
1198+
"status content is current",
1199+
reason=e)
1200+
if e.response.status_code == 404:
1201+
raise ApiNotFoundError(
1202+
"Can not find draft with current content",
1203+
reason=e)
12051204

1206-
return response
1205+
raise
1206+
1207+
return response
12071208

12081209
def _insert_to_existing_page(self, page_id, title, insert_body, parent_id=None, type='page',
12091210
representation='storage',
@@ -1603,16 +1604,16 @@ def get_space(self, space_key, expand='description.plain,homepage'):
16031604
def get_space_content(self, space_key, depth="all", start=0, limit=500, content_type=None, expand="body.storage"):
16041605
"""
16051606
Get space content.
1606-
You can specify which type of content want to recieve, or get all content types.
1607+
You can specify which type of content want to recieve, or get all content types.
16071608
Use expand to get specific content properties or page
16081609
:param space_key: The unique space key name
16091610
:param depth: OPTIONAL: all|root
16101611
Gets all space pages or only root pages
16111612
:param start: OPTIONAL: The start point of the collection to return. Default: 0.
16121613
:param limit: OPTIONAL: The limit of the number of pages to return, this may be restricted by
16131614
fixed system limits. Default: 500
1614-
:param expand: OPTIONAL: by default expands page body in confluence storage format.
1615-
See atlassian documentation for more information.
1615+
:param expand: OPTIONAL: by default expands page body in confluence storage format.
1616+
See atlassian documentation for more information.
16161617
:return: Returns the space along with its ID
16171618
"""
16181619

@@ -2232,4 +2233,3 @@ def set_inline_tasks_checkbox(self, page_id, task_id, status):
22322233
"Param cannot be empty",
22332234
reason=e)
22342235
raise
2235-

0 commit comments

Comments
 (0)