-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathdashboard.py
210 lines (156 loc) · 5.3 KB
/
dashboard.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
import json
import sys
from .utils import DSSTaggableObjectListItem, DSSTaggableObjectSettings
if sys.version_info >= (3,0):
import urllib.parse
dku_quote_fn = urllib.parse.quote
else:
import urllib
dku_quote_fn = urllib.quote
DASHBOARDS_URI_FORMAT = "/projects/%s/dashboards/"
DASHBOARD_URI_FORMAT = DASHBOARDS_URI_FORMAT + "%s/"
class DSSDashboard(object):
"""
A handle to interact with a dashboard on the DSS instance.
.. important::
Do not instantiate directly, use :meth:`dataikuapi.dss.DSSProject.get_dashboard` instead
"""
def __init__(self, client, project_key, dashboard_id):
self.client = client
self.project_key = project_key
self.dashboard_id = dashboard_id
def delete(self):
"""
Delete the dashboard
"""
return self.client._perform_empty("DELETE", DASHBOARD_URI_FORMAT % (self.project_key, self.dashboard_id))
def get_settings(self):
"""
Get the dashboard's definition
:return: a handle to inspect the dashboard definition
:rtype: :class:`dataikuapi.dss.dashboard.DSSDashboardSettings`
"""
return DSSDashboardSettings(self.client, self.client._perform_json("GET", DASHBOARD_URI_FORMAT % (self.project_key, self.dashboard_id)))
class DSSDashboardListItem(DSSTaggableObjectListItem):
"""
An item in a list of dashboards.
.. important::
Do not instantiate this class, use :meth:`dataikuapi.dss.project.DSSProject.list_dashboards`
"""
def __init__(self, client, data):
super(DSSDashboardListItem, self).__init__(data)
self.client = client
def to_dashboard(self):
"""
Get a handle to interact with this dashboard
:return: a handle on the dashboard
:rtype: :class:`dataikuapi.dss.dashboard.DSSDashboard`
"""
return DSSDashboard(self.client, self._data["projectKey"], self._data["id"])
@property
def id(self):
"""
Get the identifier of the dashboard
.. note::
The id is generated by DSS upon creation and random.
:rtype: string
"""
return self._data["id"]
@property
def name(self):
"""
Get the name of the dashboard
.. note::
The name is user-provided and not necessarily unique.
:rtype: str
"""
return self._data['name']
@property
def listed(self):
"""
Get the boolean indicating whether the dashboard is private or public (i.e. promoted)
:rtype: bool
"""
return self._data['listed']
@property
def owner(self):
"""
Get the login of the owner of the dashboard
:rtype: str
"""
return self._data['owner']
@property
def num_pages(self):
"""
Get the number of pages (i.e. slides) in the dashboard
:rtype: int
"""
return self._data['numPages']
@property
def num_tiles(self):
"""
Get the number of tiles in the dashboard
:rtype: int
"""
return self._data['numTiles']
class DSSDashboardSettings(DSSTaggableObjectSettings):
"""
Settings for a dashboard
.. important::
Do not instantiate directly, use :meth:`dataikuapi.dss.dashboard.DSSDashboard.get_settings` instead
"""
def __init__(self, client, settings):
super(DSSDashboardSettings, self).__init__(settings)
self.client = client
self.project_key = settings['projectKey']
self.settings = settings
def get_raw(self):
"""
Gets all settings as a raw dictionary.
:return: the settings, as a dict. Fields are:
* **projectKey** and **id** : identify the dashboard
* **name** : name (label) of the dashboard
* **owner** : login of the owner of the dashboard
* **listed** : boolean indicating whether the dashboard is private or public (i.e. promoted)
* **pages** : definition of the different slides
* **versionTag**, **creationTag**, **checklists**, **tags**, **customFields** : common fields on DSS objects
:rtype: dict
"""
return self.settings
def save(self):
"""
Save the settings to the dashboard
"""
return self.client._perform_json("PUT", DASHBOARD_URI_FORMAT % (self.project_key, self.id), body = self.settings)
@property
def id(self):
"""
Get the identifier of the dashboard
.. note::
The id is generated by DSS upon creation and random.
:rtype: string
"""
return self.settings["id"]
@property
def name(self):
"""
Get the name of the dashboard
.. note::
The name is user-provided and not necessarily unique.
:rtype: str
"""
return self.settings['name']
@property
def listed(self):
"""
Get the boolean indicating whether the dashboard is private or public (i.e. promoted)
:rtype: bool
"""
return self.settings['listed']
@property
def owner(self):
"""
Get the login of the owner of the dashboard
:rtype: str
"""
return self.settings['owner']