@@ -7,16 +7,17 @@ def copy_card(self, source_card_name=None, source_card_id=None,
77 """
88 Copy the card with the given name/id to the given destination collection.
99
10- Keyword arguments:
11- source_card_name -- name of the card to copy (default None)
12- source_card_id -- id of the card to copy (default None)
13- source_collection_name -- name of the collection the source card is located in (default None)
14- source_collection_id -- id of the collection the source card is located in (default None)
15- destination_card_name -- name used for the card in destination (default None).
10+ Parameters
11+ ----------
12+ source_card_name : name of the card to copy (default None)
13+ source_card_id : id of the card to copy (default None)
14+ source_collection_name : name of the collection the source card is located in (default None)
15+ source_collection_id : id of the collection the source card is located in (default None)
16+ destination_card_name : name used for the card in destination (default None).
1617 If None, it will use the name of the source card + postfix.
17- destination_collection_name -- name of the collection to copy the card to (default None)
18- destination_collection_id -- id of the collection to copy the card to (default None)
19- postfix -- if destination_card_name is None, adds this string to the end of source_card_name
18+ destination_collection_name : name of the collection to copy the card to (default None)
19+ destination_collection_id : id of the collection to copy the card to (default None)
20+ postfix : if destination_card_name is None, adds this string to the end of source_card_name
2021 to make destination_card_name
2122 """
2223 ### Making sure we have the data that we need
@@ -66,16 +67,17 @@ def copy_pulse(self, source_pulse_name=None, source_pulse_id=None,
6667 """
6768 Copy the pulse with the given name/id to the given destination collection.
6869
69- Keyword arguments:
70- source_pulse_name -- name of the pulse to copy (default None)
71- source_pulse_id -- id of the pulse to copy (default None)
72- source_collection_name -- name of the collection the source card is located in (default None)
73- source_collection_id -- id of the collection the source card is located in (default None)
74- destination_pulse_name -- name used for the pulse in destination (default None).
70+ Parameters
71+ ----------
72+ source_pulse_name : name of the pulse to copy (default None)
73+ source_pulse_id : id of the pulse to copy (default None)
74+ source_collection_name : name of the collection the source card is located in (default None)
75+ source_collection_id : id of the collection the source card is located in (default None)
76+ destination_pulse_name : name used for the pulse in destination (default None).
7577 If None, it will use the name of the source pulse + postfix.
76- destination_collection_name -- name of the collection to copy the pulse to (default None)
77- destination_collection_id -- id of the collection to copy the pulse to (default None)
78- postfix -- if destination_pulse_name is None, adds this string to the end of source_pulse_name
78+ destination_collection_name : name of the collection to copy the pulse to (default None)
79+ destination_collection_id : id of the collection to copy the pulse to (default None)
80+ postfix : if destination_pulse_name is None, adds this string to the end of source_pulse_name
7981 to make destination_pulse_name
8082 """
8183 ### Making sure we have the data that we need
@@ -115,24 +117,23 @@ def copy_dashboard(self, source_dashboard_name=None, source_dashboard_id=None,
115117 source_collection_name = None , source_collection_id = None ,
116118 destination_dashboard_name = None ,
117119 destination_collection_name = None , destination_collection_id = None ,
118- deepcopy = False , postfix = '' ):
120+ deepcopy = False , postfix = '' , collection_position = 1 , description = '' ):
119121 """
120122 Copy the dashboard with the given name/id to the given destination collection.
121123
122- Keyword arguments:
123- source_dashboard_name -- name of the dashboard to copy (default None)
124- source_dashboard_id -- id of the dashboard to copy (default None)
125- source_collection_name -- name of the collection the source dashboard is located in (default None)
126- source_collection_id -- id of the collection the source dashboard is located in (default None)
127- destination_dashboard_name -- name used for the dashboard in destination (default None).
128- If None, it will use the name of the source dashboard + postfix.
129- destination_collection_name -- name of the collection to copy the dashboard to (default None)
130- destination_collection_id -- id of the collection to copy the dashboard to (default None)
131- deepcopy -- whether to duplicate the cards inside the dashboard (default False).
132- If True, puts the duplicated cards in a collection called "[dashboard_name]'s cards"
133- in the same path as the duplicated dashboard.
134- postfix -- if destination_dashboard_name is None, adds this string to the end of source_dashboard_name
135- to make destination_dashboard_name
124+ Parameters
125+ ----------
126+ source_dashboard_name : name of the dashboard to copy (default None)
127+ source_dashboard_id : id of the dashboard to copy (default None)
128+ source_collection_name : name of the collection the source dashboard is located in (default None)
129+ source_collection_id : id of the collection the source dashboard is located in (default None)
130+ destination_dashboard_name : name used for the dashboard in destination (default None).
131+ If None, it will use the name of the source dashboard + postfix.
132+ destination_collection_name : name of the collection to copy the dashboard to (default None)
133+ destination_collection_id : id of the collection to copy the dashboard to (default None)
134+ deepcopy : whether to duplicate the cards inside the dashboard (default False).
135+ postfix : if destination_dashboard_name is None, adds this string to the end of source_dashboard_name
136+ to make destination_dashboard_name
136137 """
137138 ### making sure we have the data that we need
138139 if not source_dashboard_id :
@@ -154,52 +155,16 @@ def copy_dashboard(self, source_dashboard_name=None, source_dashboard_id=None,
154155 source_dashboard_name = self .get_item_name (item_type = 'dashboard' , item_id = source_dashboard_id )
155156 destination_dashboard_name = source_dashboard_name + postfix
156157
157- ### shallow-copy
158- shallow_copy_json = {'collection_id' :destination_collection_id , 'name' :destination_dashboard_name }
159- res = self .post ('/api/dashboard/{}/copy' .format (source_dashboard_id ), json = shallow_copy_json )
158+ parameters = {
159+ 'collection_id' :destination_collection_id ,
160+ 'name' :destination_dashboard_name ,
161+ 'is_deep_copy' :deepcopy ,
162+ 'collection_position' : collection_position ,
163+ 'description' : description
164+ }
165+ res = self .post ('/api/dashboard/{}/copy' .format (source_dashboard_id ), json = parameters )
160166 dup_dashboard_id = res ['id' ]
161167
162- ### deepcopy
163- if deepcopy :
164- # get the source dashboard info
165- source_dashboard = self .get ('/api/dashboard/{}' .format (source_dashboard_id ))
166-
167- # create an empty collection to copy the cards into it
168- res = self .post ('/api/collection/' ,
169- json = {'name' :destination_dashboard_name + "'s cards" ,
170- 'color' :'#509EE3' ,
171- 'parent_id' :destination_collection_id })
172- cards_collection_id = res ['id' ]
173-
174- # duplicate cards and put them in the created collection and make a card_id mapping
175- source_dashboard_card_IDs = [ i ['card_id' ] for i in source_dashboard ['dashcards' ] if i ['card_id' ] is not None ]
176- card_id_mapping = {}
177- for card_id in source_dashboard_card_IDs :
178- dup_card_id = self .copy_card (source_card_id = card_id , destination_collection_id = cards_collection_id )
179- card_id_mapping [card_id ] = dup_card_id
180-
181- # replace cards in the duplicated dashboard with duplicated cards
182- dup_dashboard = self .get ('/api/dashboard/{}' .format (dup_dashboard_id ))
183- for card in dup_dashboard ['dashcards' ]:
184-
185- # ignore text boxes. These get copied in the shallow-copy stage.
186- if card ['card_id' ] is None :
187- continue
188-
189- # prepare a json to be used for replacing the cards in the duplicated dashboard
190- new_card_id = card_id_mapping [card ['card_id' ]]
191- card_json = {}
192- card_json ['cardId' ] = new_card_id
193- for prop in ['visualization_settings' , 'col' , 'row' , 'size_x' , 'size_y' , 'series' , 'parameter_mappings' ]:
194- card_json [prop ] = card [prop ]
195- for item in card_json ['parameter_mappings' ]:
196- item ['card_id' ] = new_card_id
197- # remove the card from the duplicated dashboard
198- dash_card_id = card ['id' ] # This is id of the card in the dashboard (different from id of the card itself)
199- self .delete ('/api/dashboard/{}/cards' .format (dup_dashboard_id ), params = {'dashcardId' :dash_card_id })
200- # add the new card to the duplicated dashboard
201- self .post ('/api/dashboard/{}/cards' .format (dup_dashboard_id ), json = card_json )
202-
203168 return dup_dashboard_id
204169
205170
@@ -211,22 +176,23 @@ def copy_collection(self, source_collection_name=None, source_collection_id=None
211176 """
212177 Copy the collection with the given name/id into the given destination parent collection.
213178
214- Keyword arguments:
215- source_collection_name -- name of the collection to copy (default None)
216- source_collection_id -- id of the collection to copy (default None)
217- destination_collection_name -- the name to be used for the collection in the destination (default None).
179+ Parameters
180+ ----------
181+ source_collection_name : name of the collection to copy (default None)
182+ source_collection_id : id of the collection to copy (default None)
183+ destination_collection_name : the name to be used for the collection in the destination (default None).
218184 If None, it will use the name of the source collection + postfix.
219- destination_parent_collection_name -- name of the destination parent collection (default None).
185+ destination_parent_collection_name : name of the destination parent collection (default None).
220186 This is the collection that would have the copied collection as a child.
221187 use 'Root' for the root collection.
222- destination_parent_collection_id -- id of the destination parent collection (default None).
188+ destination_parent_collection_id : id of the destination parent collection (default None).
223189 This is the collection that would have the copied collection as a child.
224- deepcopy_dashboards -- whether to duplicate the cards inside the dashboards (default False).
190+ deepcopy_dashboards : whether to duplicate the cards inside the dashboards (default False).
225191 If True, puts the duplicated cards in a collection called "[dashboard_name]'s duplicated cards"
226192 in the same path as the duplicated dashboard.
227- postfix -- if destination_collection_name is None, adds this string to the end of source_collection_name to make destination_collection_name.
228- child_items_postfix -- this string is added to the end of the child items' names, when saving them in the destination (default '').
229- verbose -- prints extra information (default False)
193+ postfix : if destination_collection_name is None, adds this string to the end of source_collection_name to make destination_collection_name.
194+ child_items_postfix : this string is added to the end of the child items' names, when saving them in the destination (default '').
195+ verbose : prints extra information (default False)
230196 """
231197 ### making sure we have the data that we need
232198 if not source_collection_id :
0 commit comments