Skip to content

Commit b6533ab

Browse files
Ryukamusagonchik
authored andcommitted
Add append option to the begining of the page (#424)
* Add append option to the begining of the page * Refactor to have prepend and append method using the same with different value for top_of_page flag
1 parent cb3e423 commit b6533ab

File tree

1 file changed

+45
-6
lines changed

1 file changed

+45
-6
lines changed

atlassian/confluence.py

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -785,31 +785,32 @@ def update_page(self, page_id, title, body, parent_id=None, type='page', represe
785785

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

788-
def append_page(self, page_id, title, append_body, parent_id=None, type='page', representation='storage',
789-
minor_edit=False):
788+
def _insert_to_existing_page(self, page_id, title, insert_body, parent_id=None, type='page', representation='storage',
789+
minor_edit=False, top_of_page=False):
790790
"""
791-
Append body to page if already exist
791+
Insert body to a page if already exist
792792
:param parent_id:
793793
:param page_id:
794794
:param title:
795-
:param append_body:
795+
:param insert_body:
796796
:param type:
797797
:param representation: OPTIONAL: either Confluence 'storage' or 'wiki' markup format
798798
:param minor_edit: Indicates whether to notify watchers about changes.
799799
If False then notifications will be sent.
800+
:param top_of_page: Option to add the content to the end of page body
800801
:return:
801802
"""
802803
log.info('Updating {type} "{title}"'.format(title=title, type=type))
803804

804-
if self.is_page_content_is_already_updated(page_id, append_body, title):
805+
if self.is_page_content_is_already_updated(page_id, insert_body, title):
805806
return self.get_page_by_id(page_id)
806807
else:
807808
version = self.history(page_id)['lastUpdated']['number'] + 1
808809
previous_body = (self.get_page_by_id(page_id, expand='body.storage').get('body') or {}).get(
809810
'storage').get(
810811
'value')
811812
previous_body = previous_body.replace('ó', u'ó')
812-
body = previous_body + append_body
813+
body = insert_body + previous_body if top_of_page else previous_body + insert_body
813814
data = {
814815
'id': page_id,
815816
'type': type,
@@ -824,6 +825,44 @@ def append_page(self, page_id, title, append_body, parent_id=None, type='page',
824825

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

828+
def append_page(self, page_id, title, append_body, parent_id=None, type='page', representation='storage',
829+
minor_edit=False):
830+
"""
831+
Append body to page if already exist
832+
:param parent_id:
833+
:param page_id:
834+
:param title:
835+
:param append_body:
836+
:param type:
837+
:param representation: OPTIONAL: either Confluence 'storage' or 'wiki' markup format
838+
:param minor_edit: Indicates whether to notify watchers about changes.
839+
If False then notifications will be sent.
840+
:return:
841+
"""
842+
log.info('Updating {type} "{title}"'.format(title=title, type=type))
843+
844+
return self._insert_to_existing_page(page_id, title, append_body, parent_id=parent_id, type=type, representation=representation,
845+
minor_edit=minor_edit, top_of_page=False)
846+
847+
def prepend_page(self, page_id, title, prepend_body, parent_id=None, type='page', representation='storage',
848+
minor_edit=False):
849+
"""
850+
Append body to page if already exist
851+
:param parent_id:
852+
:param page_id:
853+
:param title:
854+
:param prepend_body:
855+
:param type:
856+
:param representation: OPTIONAL: either Confluence 'storage' or 'wiki' markup format
857+
:param minor_edit: Indicates whether to notify watchers about changes.
858+
If False then notifications will be sent.
859+
:return:
860+
"""
861+
log.info('Updating {type} "{title}"'.format(title=title, type=type))
862+
863+
return self._insert_to_existing_page(page_id, title, prepend_body, parent_id=parent_id, type=type, representation=representation,
864+
minor_edit=minor_edit, top_of_page=True)
865+
827866
def update_or_create(self, parent_id, title, body, representation='storage', minor_edit=False):
828867
"""
829868
Update page or create a page if it is not exists

0 commit comments

Comments
 (0)