2
2
import logging
3
3
import os
4
4
import time
5
+ import json
5
6
6
7
from requests import HTTPError
7
8
from deprecated import deprecated
@@ -666,12 +667,69 @@ def move_page(self, space_key, page_id, target_id=None, target_title=None, posit
666
667
params ["position" ] = position
667
668
return self .post (url , params = params , headers = self .no_check_headers )
668
669
669
- def get_template_by_id (self , template_id ):
670
+ def create_or_update_template (
671
+ self , name , body , template_type = "page" , template_id = None , description = None , labels = None , space = None
672
+ ):
670
673
"""
671
- Get user template by id. Experimental API
672
- Use case is get template body and create page from that
674
+ Creates a new or updates an existing content template.
675
+
676
+ Note, blueprint templates cannot be created or updated via the REST API.
677
+
678
+ If you provide a ``template_id`` then this method will update the template with the provided settings.
679
+ If no ``template_id`` is provided, then this method assumes you are creating a new template.
680
+
681
+ :param str name: If creating, the name of the new template. If updating, the name to change
682
+ the template name to. Set to the current name if this field is not being updated.
683
+ :param dict body: This object is used when creating or updating content.
684
+ {
685
+ "storage": {
686
+ "value": "<string>",
687
+ "representation": "view"
688
+ }
689
+ }
690
+ :param str template_type: OPTIONAL: The type of the new template. Default: "page".
691
+ :param str template_id: OPTIONAL: The ID of the template being updated. REQUIRED if updating a template.
692
+ :param str description: OPTIONAL: A description of the new template. Max length 255.
693
+ :param list labels: OPTIONAL: Labels for the new template. An array like:
694
+ [
695
+ {
696
+ "prefix": "<string>",
697
+ "name": "<string>",
698
+ "id": "<string>",
699
+ "label": "<string>",
700
+ }
701
+ ]
702
+ :param dict space: OPTIONAL: The key for the space of the new template. Only applies to space templates.
703
+ If not specified, the template will be created as a global template.
704
+ :return:
705
+ """
706
+ data = {"name" : name , "templateType" : template_type , "body" : body }
707
+
708
+ if description :
709
+ data ["description" ] = description
710
+
711
+ if labels :
712
+ data ["labels" ] = labels
713
+
714
+ if space :
715
+ data ["space" ] = {"key" : space }
716
+
717
+ if template_id :
718
+ data ["templateId" ] = template_id
719
+ return self .put ("wiki/rest/api/template" , data = json .dumps (data ))
720
+
721
+ return self .post ("wiki/rest/api/template" , json = data )
722
+
723
+ def get_content_template (self , template_id ):
724
+ """
725
+ Get a content template.
726
+
727
+ This includes information about the template, like the name, the space or blueprint
728
+ that the template is in, the body of the template, and more.
729
+ :param str template_id: The ID of the content template to be returned
730
+ :return:
673
731
"""
674
- url = "rest/experimental /template/{template_id}" .format (template_id = template_id )
732
+ url = "wiki/ rest/api /template/{template_id}" .format (template_id = template_id )
675
733
676
734
try :
677
735
response = self .get (url )
@@ -688,17 +746,19 @@ def get_template_by_id(self, template_id):
688
746
689
747
return response
690
748
691
- def get_all_blueprints_from_space (self , space , start = 0 , limit = 20 , expand = None ):
749
+ def get_blueprint_templates (self , space = None , start = 0 , limit = None , expand = None ):
692
750
"""
693
- Get all users blue prints from space. Experimental API
694
- :param space: Space Key
695
- :param start: OPTIONAL: The start point of the collection to return. Default: None (0).
696
- :param limit: OPTIONAL: The limit of the number of pages to return, this may be restricted by
697
- fixed system limits. Default: 20
698
- :param expand: OPTIONAL: expand e.g. body
751
+ Gets all templates provided by blueprints.
699
752
753
+ Use this method to retrieve all global blueprint templates or all blueprint templates in a space.
754
+ :param space: OPTIONAL: The key of the space to be queried for templates. If ``space`` is not
755
+ specified, global blueprint templates will be returned.
756
+ :param start: OPTIONAL: The starting index of the returned templates. Default: None (0).
757
+ :param limit: OPTIONAL: The limit of the number of pages to return, this may be restricted by
758
+ fixed system limits. Default: 25
759
+ :param expand: OPTIONAL: A multi-value parameter indicating which properties of the template to expand.
700
760
"""
701
- url = "rest/experimental /template/blueprint"
761
+ url = "wiki/ rest/api /template/blueprint"
702
762
params = {}
703
763
if space :
704
764
params ["spaceKey" ] = space
@@ -722,19 +782,19 @@ def get_all_blueprints_from_space(self, space, start=0, limit=20, expand=None):
722
782
723
783
return response .get ("results" ) or []
724
784
725
- def get_all_templates_from_space (self , space , start = 0 , limit = 20 , expand = None ):
785
+ def get_content_templates (self , space = None , start = 0 , limit = None , expand = None ):
726
786
"""
727
- Get all users templates from space. Experimental API
728
- ref: https://docs.atlassian.com/atlassian-confluence/1000.73.0/com/atlassian/confluence/plugins/restapi \
729
- /resources/TemplateResource.html
730
- :param space: Space Key
787
+ Get all content templates.
788
+ Use this method to retrieve all global content templates or all content templates in a space.
789
+ :param space: OPTIONAL: The key of the space to be queried for templates. If ``space`` is not
790
+ specified, global templates will be returned.
731
791
:param start: OPTIONAL: The start point of the collection to return. Default: None (0).
732
792
:param limit: OPTIONAL: The limit of the number of pages to return, this may be restricted by
733
- fixed system limits. Default: 20
734
- :param expand: OPTIONAL: expand e.g. body
735
-
793
+ fixed system limits. Default: 25
794
+ :param expand: OPTIONAL: A multi-value parameter indicating which properties of the template to expand.
795
+ e.g. ``body``
736
796
"""
737
- url = "rest/experimental /template/page"
797
+ url = "wiki/ rest/api /template/page"
738
798
params = {}
739
799
if space :
740
800
params ["spaceKey" ] = space
@@ -758,6 +818,23 @@ def get_all_templates_from_space(self, space, start=0, limit=20, expand=None):
758
818
759
819
return response .get ("results" ) or []
760
820
821
+ def remove_template (self , template_id ):
822
+ """
823
+ Deletes a template.
824
+
825
+ This results in different actions depending on the type of template:
826
+ * If the template is a content template, it is deleted.
827
+ * If the template is a modified space-level blueprint template, it reverts to the template
828
+ inherited from the global-level blueprint template.
829
+ * If the template is a modified global-level blueprint template, it reverts to the default
830
+ global-level blueprint template.
831
+ Note: Unmodified blueprint templates cannot be deleted.
832
+
833
+ :param str template_id: The ID of the template to be deleted.
834
+ :return:
835
+ """
836
+ return self .delete ("wiki/rest/api/template/{}" .format (template_id ))
837
+
761
838
def get_all_spaces (self , start = 0 , limit = 500 , expand = None , space_type = None , space_status = None ):
762
839
"""
763
840
Get all spaces with provided limit
0 commit comments