Skip to content

Commit

Permalink
Added edit_page functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Muddytm committed Apr 7, 2016
1 parent 7af89d0 commit 2515537
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
24 changes: 24 additions & 0 deletions pyconfluence/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,30 @@ def create_page(name, parent_id, space, content):
return _api.rest("/", "POST", _json.dumps(data))


def edit_page(id, name, space, content):
"""Update a page in Confluence.
Parameters:
- id: ID of the page you wish to edit.
- name: name you would like to give to the page (usually the same name).
- space: space where the page lives.
- content: XHTML content to be written to the page.
Notes: it is required to try an initial update to find the page version.
"""
data = {}
data["id"] = str(id)
data["type"] = "page"
data["title"] = name
data["space"] = {"key": space}
data["body"] = {"storage": {"value": content, "representation": "storage"}}
data["version"] = {"number": 1}

response = _api.rest("/" + str(id), "PUT", _json.dumps(data))
new_version = int(_json.loads(response)["message"].split()[-1]) + 1
data["version"]["number"] = new_version

return _api.rest("/" + str(id), "PUT", _json.dumps(data))


def delete_page(id):
"""Delete a page from Confluence.
Parameters:
Expand Down
3 changes: 2 additions & 1 deletion pyconfluence/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def _rest(req, url, data=None):
return body
else:
print("Oops! Error: status: %s\n%s\n" % (status, body))
return body


def _api_action(cmd, url, data=None):
Expand All @@ -75,7 +76,7 @@ def _api_action(cmd, url, data=None):
response = requests.get(url, headers=requisite_headers, auth=auth)
elif cmd == "PUT":
response = requests.put(url, headers=requisite_headers, auth=auth,
params=data)
data=data)
elif cmd == "POST":
response = requests.post(url, headers=requisite_headers, auth=auth,
data=data)
Expand Down

0 comments on commit 2515537

Please sign in to comment.