Skip to content

Commit 13983e9

Browse files
authored
[Confluence] Add new move page methods #326 (#436)
* [Confluence] Evaluate the move page method
1 parent 35999de commit 13983e9

File tree

3 files changed

+35
-12
lines changed

3 files changed

+35
-12
lines changed

atlassian/confluence.py

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,23 @@ def create_page(self, space, title, body, parent_id=None, type='page',
416416
data['ancestors'] = [{'type': type, 'id': parent_id}]
417417
return self.post(url, data=data)
418418

419+
def move_page(self, space_key, page_id, target_title, position="append"):
420+
"""
421+
Move page method
422+
:param space_key:
423+
:param page_id:
424+
:param target_title:
425+
:param position: topLevel or append
426+
:return:
427+
"""
428+
url = "/pages/movepage.action"
429+
params = {"spaceKey": space_key, "pageId": page_id}
430+
if target_title:
431+
params["targetTitle"] = target_title
432+
if position:
433+
params["position"] = position
434+
return self.get(url, params=params, headers=self.no_check_headers)
435+
419436
def get_all_spaces(self, start=0, limit=500, expand=None):
420437
"""
421438
Get all spaces with provided limit
@@ -714,12 +731,12 @@ def is_page_content_is_already_updated(self, page_id, body, title=None):
714731
"""
715732
if self.advanced_mode:
716733
confluence_content = (((self.get_page_by_id(page_id, expand='body.storage').json() or {})
717-
.get('body') or {})
718-
.get('storage') or {})
734+
.get('body') or {})
735+
.get('storage') or {})
719736
else:
720737
confluence_content = (((self.get_page_by_id(page_id, expand='body.storage') or {})
721-
.get('body') or {})
722-
.get('storage') or {})
738+
.get('body') or {})
739+
.get('storage') or {})
723740

724741
if title:
725742
current_title = confluence_content.get('title', None)
@@ -793,8 +810,9 @@ def update_page(self, page_id, title, body, parent_id=None, type='page', represe
793810

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

796-
def _insert_to_existing_page(self, page_id, title, insert_body, parent_id=None, type='page', representation='storage',
797-
minor_edit=False, top_of_page=False):
813+
def _insert_to_existing_page(self, page_id, title, insert_body, parent_id=None, type='page',
814+
representation='storage',
815+
minor_edit=False, top_of_page=False):
798816
"""
799817
Insert body to a page if already exist
800818
:param parent_id:
@@ -849,11 +867,12 @@ def append_page(self, page_id, title, append_body, parent_id=None, type='page',
849867
"""
850868
log.info('Updating {type} "{title}"'.format(title=title, type=type))
851869

852-
return self._insert_to_existing_page(page_id, title, append_body, parent_id=parent_id, type=type, representation=representation,
853-
minor_edit=minor_edit, top_of_page=False)
870+
return self._insert_to_existing_page(page_id, title, append_body, parent_id=parent_id, type=type,
871+
representation=representation,
872+
minor_edit=minor_edit, top_of_page=False)
854873

855874
def prepend_page(self, page_id, title, prepend_body, parent_id=None, type='page', representation='storage',
856-
minor_edit=False):
875+
minor_edit=False):
857876
"""
858877
Append body to page if already exist
859878
:param parent_id:
@@ -868,8 +887,9 @@ def prepend_page(self, page_id, title, prepend_body, parent_id=None, type='page'
868887
"""
869888
log.info('Updating {type} "{title}"'.format(title=title, type=type))
870889

871-
return self._insert_to_existing_page(page_id, title, prepend_body, parent_id=parent_id, type=type, representation=representation,
872-
minor_edit=minor_edit, top_of_page=True)
890+
return self._insert_to_existing_page(page_id, title, prepend_body, parent_id=parent_id, type=type,
891+
representation=representation,
892+
minor_edit=minor_edit, top_of_page=True)
873893

874894
def update_or_create(self, parent_id, title, body, representation='storage', minor_edit=False):
875895
"""

atlassian/rest_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class AtlassianRestAPI(object):
1818
'X-ExperimentalApi': 'opt-in'}
1919
form_token_headers = {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
2020
'X-Atlassian-Token': 'no-check'}
21-
21+
no_check_headers = {'X-Atlassian-Token': 'no-check'}
2222
response = None
2323

2424
def __init__(self, url, username=None, password=None, timeout=60, api_root='rest/api', api_version='latest',

docs/confluence.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ Page actions
9999
# Delete the page (content) property e.g. delete key of hash
100100
confluence.delete_page_property(page_id, page_property)
101101
102+
# Move page
103+
confluence.move_page(space_key, page_id, target_title, position="append")
104+
102105
# Get the page (content) property e.g. get key of hash
103106
confluence.get_page_property(page_id, page_property_key)
104107

0 commit comments

Comments
 (0)