Skip to content

Commit 50dbf16

Browse files
authored
Merge pull request #218 from gonchik/master
Confluence: Append body into page
2 parents 4af5206 + 1b875e8 commit 50dbf16

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

atlassian/VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.12.19
1+
1.12.20

atlassian/confluence.py

+40
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,46 @@ def update_page(self, parent_id, page_id, title, body, type='page',
491491

492492
return self.put('rest/api/content/{0}'.format(page_id), data=data)
493493

494+
def append_page(self, parent_id, page_id, title, append_body, type='page',
495+
minor_edit=False):
496+
"""
497+
Append body to page if already exist
498+
:param parent_id:
499+
:param page_id:
500+
:param title:
501+
:param append_body:
502+
:param type:
503+
:param minor_edit: Indicates whether to notify watchers about changes.
504+
If False then notifications will be sent.
505+
:return:
506+
"""
507+
log.info('Updating {type} "{title}"'.format(title=title, type=type))
508+
509+
if self.is_page_content_is_already_updated(page_id, append_body):
510+
return self.get_page_by_id(page_id)
511+
else:
512+
version = self.history(page_id)['lastUpdated']['number'] + 1
513+
previous_body = (self.get_page_by_id(page_id, expand='body.storage').get('body') or {}).get(
514+
'storage').get(
515+
'value')
516+
previous_body = previous_body.replace('ó', u'ó')
517+
body = previous_body + append_body
518+
data = {
519+
'id': page_id,
520+
'type': type,
521+
'title': title,
522+
'body': {'storage': {
523+
'value': body,
524+
'representation': 'storage'}},
525+
'version': {'number': version,
526+
'minorEdit': minor_edit}
527+
}
528+
529+
if parent_id:
530+
data['ancestors'] = [{'type': 'page', 'id': parent_id}]
531+
532+
return self.put('rest/api/content/{0}'.format(page_id), data=data)
533+
494534
def update_or_create(self, parent_id, title, body):
495535
"""
496536
Update page or create a page if it is not exists

0 commit comments

Comments
 (0)