pygeobox 1.0.3__py3-none-any.whl → 1.0.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
pygeobox/dashboard.py CHANGED
@@ -1,316 +1,316 @@
1
- from typing import List, Dict, Optional, TYPE_CHECKING, Union
2
- from urllib.parse import urljoin
3
-
4
- from .base import Base
5
-
6
- if TYPE_CHECKING:
7
- from . import GeoboxClient
8
- from .user import User
9
-
10
- class Dashboard(Base):
11
-
12
- BASE_ENDPOINT = 'dashboards/'
13
-
14
- def __init__(self,
15
- api: 'GeoboxClient',
16
- uuid: str,
17
- data: Optional[Dict] = {}):
18
- """
19
- Initialize a Dashboard instance.
20
-
21
- Args:
22
- api (GeoboxClient): The GeoboxClient instance for making requests.
23
- uuid (str): The unique identifier for the Dashboard.
24
- data (Dict, optional): The data of the Dashboard.
25
- """
26
- super().__init__(api, uuid=uuid, data=data)
27
-
28
-
29
- @classmethod
30
- def get_dashboards(cls, api: 'GeoboxClient', **kwargs) -> Union[List['Dashboard'], int]:
31
- """
32
- Get list of Dashboards
33
-
34
- Args:
35
- api (GeoboxClient): The GeoboxClient instance for making requests.
36
-
37
- Keyword Args:
38
- q (str): query filter based on OGC CQL standard. e.g. "field1 LIKE '%GIS%' AND created_at > '2021-01-01'"
39
- search (str): search term for keyword-based searching among search_fields or all textual fields if search_fields does not have value. NOTE: if q param is defined this param will be ignored.
40
- search_fields (str): comma separated list of fields for searching.
41
- order_by (str): comma separated list of fields for sorting results [field1 A|D, field2 A|D, …]. e.g. name A, type D. NOTE: "A" denotes ascending order and "D" denotes descending order.
42
- return_count (bool): Whether to return total count. default is False.
43
- skip (int): Number of items to skip. default is 0.
44
- limit (int): Number of items to return. default is 10.
45
- user_id (int): Specific user. privileges required.
46
- shared (bool): Whether to return shared Dashboards. default is False.
47
-
48
- Returns:
49
- List[Dashboard] | int: A list of Dashboard instances or the total number of Dashboards.
50
-
51
- Example:
52
- >>> from geobox import GeoboxClient
53
- >>> from geobox.dashboard import Dashboard
54
- >>> client = GeoboxClient()
55
- >>> dashboards = Dashboard.get_dashboards(client)
56
- or
57
- >>> dashboards = client.get_dashboards()
58
- """
59
- params = {
60
- 'f': 'json',
61
- 'q': kwargs.get('q'),
62
- 'search': kwargs.get('search'),
63
- 'search_fields': kwargs.get('search_fields'),
64
- 'order_by': kwargs.get('order_by'),
65
- 'return_count': kwargs.get('return_count', False),
66
- 'skip': kwargs.get('skip', 0),
67
- 'limit': kwargs.get('limit', 10),
68
- 'user_id': kwargs.get('user_id'),
69
- 'shared': kwargs.get('shared', False)
70
- }
71
- return super()._get_list(api, cls.BASE_ENDPOINT, params, factory_func=lambda api, item: Dashboard(api, item['uuid'], item))
72
-
73
-
74
- @classmethod
75
- def create_dashboard(cls,
76
- api: 'GeoboxClient',
77
- name: str,
78
- display_name: str = None,
79
- description: str = None,
80
- settings: Dict = {},
81
- thumbnail: str = None,
82
- user_id: int = None) -> 'Dashboard':
83
- """
84
- Create a new Dashboard.
85
-
86
- Args:
87
- api (GeoboxClient): The GeoboxClient instance for making requests.
88
- name (str): The name of the Dashboard.
89
- display_name (str, optional): The display name of the Dashboard.
90
- description (str, optional): The description of the Dashboard.
91
- settings (Dict, optional): The settings of the sceDashboarde.
92
- thumbnail (str, optional): The thumbnail of the Dashboard.
93
- user_id (int, optional): Specific user. privileges required.
94
-
95
- Returns:
96
- Dashboard: The newly created Dashboard instance.
97
-
98
- Raises:
99
- ValidationError: If the Dashboard data is invalid.
100
-
101
- Example:
102
- >>> from geobox import GeoboxClient
103
- >>> from geobox.dashboard import Dashboard
104
- >>> client = GeoboxClient()
105
- >>> dashboard = Dashboard.create_dashboard(client, name="my_dashboard")
106
- or
107
- >>> dashboard = client.create_dashboard(name="my_dashboard")
108
- """
109
- data = {
110
- "name": name,
111
- "display_name": display_name,
112
- "description": description,
113
- "settings": settings,
114
- "thumbnail": thumbnail,
115
- "user_id": user_id,
116
- }
117
- return super()._create(api, cls.BASE_ENDPOINT, data, factory_func=lambda api, item: Dashboard(api, item['uuid'], item))
118
-
119
-
120
- @classmethod
121
- def get_dashboard(cls, api: 'GeoboxClient', uuid: str, user_id: int = None) -> 'Dashboard':
122
- """
123
- Get a Dashboard by its UUID.
124
-
125
- Args:
126
- api (GeoboxClient): The GeoboxClient instance for making requests.
127
- uuid (str): The UUID of the Dashboard to get.
128
- user_id (int, optional): Specific user. privileges required.
129
-
130
- Returns:
131
- Dashboard: The dashboard object.
132
-
133
- Raises:
134
- NotFoundError: If the Dashboard with the specified UUID is not found.
135
-
136
- Example:
137
- >>> from geobox import GeoboxClient
138
- >>> from geobox.dashboard import Dashboard
139
- >>> client = GeoboxClient()
140
- >>> dashboard = Dashboard.get_dashboard(client, uuid="12345678-1234-5678-1234-567812345678")
141
- or
142
- >>> dashboard = client.get_dashboard(uuid="12345678-1234-5678-1234-567812345678")
143
- """
144
- params = {
145
- 'f': 'json',
146
- 'user_id': user_id,
147
- }
148
- return super()._get_detail(api, cls.BASE_ENDPOINT, uuid, params, factory_func=lambda api, item: Dashboard(api, item['uuid'], item))
149
-
150
-
151
- @classmethod
152
- def get_dashboard_by_name(cls, api: 'GeoboxClient', name: str, user_id: int = None) -> Union['Dashboard', None]:
153
- """
154
- Get a dashboard by name
155
-
156
- Args:
157
- api (GeoboxClient): The GeoboxClient instance for making requests.
158
- name (str): the name of the dashboard to get
159
- user_id (int, optional): specific user. privileges required.
160
-
161
- Returns:
162
- Dashboard | None: returns the dashboard if a dashboard matches the given name, else None
163
-
164
- Example:
165
- >>> from geobox import GeoboxClient
166
- >>> from geobox.dashboard import Dashboard
167
- >>> client = GeoboxClient()
168
- >>> dashboard = Dashboard.get_dashboard_by_name(client, name='test')
169
- or
170
- >>> dashboard = client.get_dashboard_by_name(name='test')
171
- """
172
- dashboards = cls.get_dashboards(api, q=f"name = '{name}'", user_id=user_id)
173
- if dashboards and dashboards[0].name == name:
174
- return dashboards[0]
175
- else:
176
- return None
177
-
178
-
179
- def update(self, **kwargs) -> Dict:
180
- """
181
- Update the Dashboard
182
-
183
- Keyword Args:
184
- name (str): The name of the Dashboard.
185
- display_name (str): The display name of the Dashboard.
186
- description (str): The description of the Dashboard.
187
- settings (Dict): The settings of the Dashboard.
188
- thumbnail (str): The thumbnail of the Dashboard.
189
-
190
- Returns:
191
- Dict: The updated Dashboard data.
192
-
193
- Raises:
194
- ValidationError: If the Dashboard data is invalid.
195
-
196
- Example:
197
- >>> from geobox import GeoboxClient
198
- >>> from geobox.dashboard import Dashboard
199
- >>> client = GeoboxClient()
200
- >>> dashboard = Dashboard.get_dashboard(client, uuid="12345678-1234-5678-1234-567812345678")
201
- >>> dashboard.update(display_name="New Display Name")
202
- """
203
- data = {
204
- "name": kwargs.get('name'),
205
- "display_name": kwargs.get('display_name'),
206
- "description": kwargs.get('description'),
207
- "settings": kwargs.get('settings'),
208
- "thumbnail": kwargs.get('thumbnail')
209
- }
210
- return super()._update(self.endpoint, data)
211
-
212
-
213
- def delete(self) -> None:
214
- """
215
- Delete the dashboard.
216
-
217
- Returns:
218
- None
219
-
220
- Example:
221
- >>> from geobox import GeoboxClient
222
- >>> from geobox.dashboard import Dashboard
223
- >>> client = GeoboxClient()
224
- >>> dashboard = Dashboard.get_dashboard(client, uuid="12345678-1234-5678-1234-567812345678")
225
- >>> dashboard.delete()
226
- """
227
- super().delete(self.endpoint)
228
-
229
-
230
- @property
231
- def thumbnail(self) -> str:
232
- """
233
- Get the thumbnail URL of the dashboard.
234
-
235
- Returns:
236
- str: The thumbnail of the dashboard.
237
-
238
- Example:
239
- >>> from geobox import GeoboxClient
240
- >>> from geobox.dashboard import Dashboard
241
- >>> client = GeoboxClient()
242
- >>> dashboard = Dashboard.get_dashboard(client, uuid="12345678-1234-5678-1234-567812345678")
243
- >>> dashboard.thumbnail
244
- 'https://example.com/thumbnail.png'
245
- """
246
- endpoint = urljoin(self.api.base_url, f'{self.endpoint}thumbnail.png')
247
- return endpoint
248
-
249
-
250
- def share(self, users: List['User']) -> None:
251
- """
252
- Shares the Dashboard with specified users.
253
-
254
- Args:
255
- users (List[User]): The list of user objects to share the Dashboard with.
256
-
257
- Returns:
258
- None
259
-
260
- Example:
261
- >>> from geobox import GeoboxClient
262
- >>> from geobox.dashboard import Dashboard
263
- >>> client = GeoboxClient()
264
- >>> dashboard = Dashboard.get_dashboard(client, uuid="12345678-1234-5678-1234-567812345678")
265
- >>> users = client.search_users(search='John')
266
- >>> dashboard.share(users=users)
267
- """
268
- super()._share(self.endpoint, users)
269
-
270
-
271
- def unshare(self, users: List['User']) -> None:
272
- """
273
- Unshares the Dashboard with specified users.
274
-
275
- Args:
276
- users (List[User]): The list of user objects to unshare the Dashboard with.
277
-
278
- Returns:
279
- None
280
-
281
- Example:
282
- >>> from geobox import GeoboxClient
283
- >>> from geobox.dashboard import Dashboard
284
- >>> client = GeoboxClient()
285
- >>> dashboard = Dashboard.get_dashboard(client, uuid="12345678-1234-5678-1234-567812345678")
286
- >>> users = client.search_users(search='John')
287
- >>> dashboard.unshare(users=users)
288
- """
289
- super()._unshare(self.endpoint, users)
290
-
291
-
292
- def get_shared_users(self, search: str = None, skip: int = 0, limit: int = 10) -> List['User']:
293
- """
294
- Retrieves the list of users the dashboard is shared with.
295
-
296
- Args:
297
- search (str, optional): The search query.
298
- skip (int, optional): The number of users to skip.
299
- limit (int, optional): The maximum number of users to retrieve.
300
-
301
- Returns:
302
- List[User]: The list of shared users.
303
-
304
- Example:
305
- >>> from geobox import GeoboxClient
306
- >>> from geobox.dashboard import Dashboard
307
- >>> client = GeoboxClient()
308
- >>> dashboard = Dashboard.get_dashboard(client, uuid="12345678-1234-5678-1234-567812345678")
309
- >>> dashboard.get_shared_users(search='John', skip=0, limit=10)
310
- """
311
- params = {
312
- 'search': search,
313
- 'skip': skip,
314
- 'limit': limit
315
- }
316
- return super()._get_shared_users(self.endpoint, params)
1
+ from typing import List, Dict, Optional, TYPE_CHECKING, Union
2
+ from urllib.parse import urljoin
3
+
4
+ from .base import Base
5
+
6
+ if TYPE_CHECKING:
7
+ from . import GeoboxClient
8
+ from .user import User
9
+
10
+ class Dashboard(Base):
11
+
12
+ BASE_ENDPOINT = 'dashboards/'
13
+
14
+ def __init__(self,
15
+ api: 'GeoboxClient',
16
+ uuid: str,
17
+ data: Optional[Dict] = {}):
18
+ """
19
+ Initialize a Dashboard instance.
20
+
21
+ Args:
22
+ api (GeoboxClient): The GeoboxClient instance for making requests.
23
+ uuid (str): The unique identifier for the Dashboard.
24
+ data (Dict, optional): The data of the Dashboard.
25
+ """
26
+ super().__init__(api, uuid=uuid, data=data)
27
+
28
+
29
+ @classmethod
30
+ def get_dashboards(cls, api: 'GeoboxClient', **kwargs) -> Union[List['Dashboard'], int]:
31
+ """
32
+ Get list of Dashboards
33
+
34
+ Args:
35
+ api (GeoboxClient): The GeoboxClient instance for making requests.
36
+
37
+ Keyword Args:
38
+ q (str): query filter based on OGC CQL standard. e.g. "field1 LIKE '%GIS%' AND created_at > '2021-01-01'"
39
+ search (str): search term for keyword-based searching among search_fields or all textual fields if search_fields does not have value. NOTE: if q param is defined this param will be ignored.
40
+ search_fields (str): comma separated list of fields for searching.
41
+ order_by (str): comma separated list of fields for sorting results [field1 A|D, field2 A|D, …]. e.g. name A, type D. NOTE: "A" denotes ascending order and "D" denotes descending order.
42
+ return_count (bool): Whether to return total count. default is False.
43
+ skip (int): Number of items to skip. default is 0.
44
+ limit (int): Number of items to return. default is 10.
45
+ user_id (int): Specific user. privileges required.
46
+ shared (bool): Whether to return shared Dashboards. default is False.
47
+
48
+ Returns:
49
+ List[Dashboard] | int: A list of Dashboard instances or the total number of Dashboards.
50
+
51
+ Example:
52
+ >>> from geobox import GeoboxClient
53
+ >>> from geobox.dashboard import Dashboard
54
+ >>> client = GeoboxClient()
55
+ >>> dashboards = Dashboard.get_dashboards(client)
56
+ or
57
+ >>> dashboards = client.get_dashboards()
58
+ """
59
+ params = {
60
+ 'f': 'json',
61
+ 'q': kwargs.get('q'),
62
+ 'search': kwargs.get('search'),
63
+ 'search_fields': kwargs.get('search_fields'),
64
+ 'order_by': kwargs.get('order_by'),
65
+ 'return_count': kwargs.get('return_count', False),
66
+ 'skip': kwargs.get('skip', 0),
67
+ 'limit': kwargs.get('limit', 10),
68
+ 'user_id': kwargs.get('user_id'),
69
+ 'shared': kwargs.get('shared', False)
70
+ }
71
+ return super()._get_list(api, cls.BASE_ENDPOINT, params, factory_func=lambda api, item: Dashboard(api, item['uuid'], item))
72
+
73
+
74
+ @classmethod
75
+ def create_dashboard(cls,
76
+ api: 'GeoboxClient',
77
+ name: str,
78
+ display_name: str = None,
79
+ description: str = None,
80
+ settings: Dict = {},
81
+ thumbnail: str = None,
82
+ user_id: int = None) -> 'Dashboard':
83
+ """
84
+ Create a new Dashboard.
85
+
86
+ Args:
87
+ api (GeoboxClient): The GeoboxClient instance for making requests.
88
+ name (str): The name of the Dashboard.
89
+ display_name (str, optional): The display name of the Dashboard.
90
+ description (str, optional): The description of the Dashboard.
91
+ settings (Dict, optional): The settings of the sceDashboarde.
92
+ thumbnail (str, optional): The thumbnail of the Dashboard.
93
+ user_id (int, optional): Specific user. privileges required.
94
+
95
+ Returns:
96
+ Dashboard: The newly created Dashboard instance.
97
+
98
+ Raises:
99
+ ValidationError: If the Dashboard data is invalid.
100
+
101
+ Example:
102
+ >>> from geobox import GeoboxClient
103
+ >>> from geobox.dashboard import Dashboard
104
+ >>> client = GeoboxClient()
105
+ >>> dashboard = Dashboard.create_dashboard(client, name="my_dashboard")
106
+ or
107
+ >>> dashboard = client.create_dashboard(name="my_dashboard")
108
+ """
109
+ data = {
110
+ "name": name,
111
+ "display_name": display_name,
112
+ "description": description,
113
+ "settings": settings,
114
+ "thumbnail": thumbnail,
115
+ "user_id": user_id,
116
+ }
117
+ return super()._create(api, cls.BASE_ENDPOINT, data, factory_func=lambda api, item: Dashboard(api, item['uuid'], item))
118
+
119
+
120
+ @classmethod
121
+ def get_dashboard(cls, api: 'GeoboxClient', uuid: str, user_id: int = None) -> 'Dashboard':
122
+ """
123
+ Get a Dashboard by its UUID.
124
+
125
+ Args:
126
+ api (GeoboxClient): The GeoboxClient instance for making requests.
127
+ uuid (str): The UUID of the Dashboard to get.
128
+ user_id (int, optional): Specific user. privileges required.
129
+
130
+ Returns:
131
+ Dashboard: The dashboard object.
132
+
133
+ Raises:
134
+ NotFoundError: If the Dashboard with the specified UUID is not found.
135
+
136
+ Example:
137
+ >>> from geobox import GeoboxClient
138
+ >>> from geobox.dashboard import Dashboard
139
+ >>> client = GeoboxClient()
140
+ >>> dashboard = Dashboard.get_dashboard(client, uuid="12345678-1234-5678-1234-567812345678")
141
+ or
142
+ >>> dashboard = client.get_dashboard(uuid="12345678-1234-5678-1234-567812345678")
143
+ """
144
+ params = {
145
+ 'f': 'json',
146
+ 'user_id': user_id,
147
+ }
148
+ return super()._get_detail(api, cls.BASE_ENDPOINT, uuid, params, factory_func=lambda api, item: Dashboard(api, item['uuid'], item))
149
+
150
+
151
+ @classmethod
152
+ def get_dashboard_by_name(cls, api: 'GeoboxClient', name: str, user_id: int = None) -> Union['Dashboard', None]:
153
+ """
154
+ Get a dashboard by name
155
+
156
+ Args:
157
+ api (GeoboxClient): The GeoboxClient instance for making requests.
158
+ name (str): the name of the dashboard to get
159
+ user_id (int, optional): specific user. privileges required.
160
+
161
+ Returns:
162
+ Dashboard | None: returns the dashboard if a dashboard matches the given name, else None
163
+
164
+ Example:
165
+ >>> from geobox import GeoboxClient
166
+ >>> from geobox.dashboard import Dashboard
167
+ >>> client = GeoboxClient()
168
+ >>> dashboard = Dashboard.get_dashboard_by_name(client, name='test')
169
+ or
170
+ >>> dashboard = client.get_dashboard_by_name(name='test')
171
+ """
172
+ dashboards = cls.get_dashboards(api, q=f"name = '{name}'", user_id=user_id)
173
+ if dashboards and dashboards[0].name == name:
174
+ return dashboards[0]
175
+ else:
176
+ return None
177
+
178
+
179
+ def update(self, **kwargs) -> Dict:
180
+ """
181
+ Update the Dashboard
182
+
183
+ Keyword Args:
184
+ name (str): The name of the Dashboard.
185
+ display_name (str): The display name of the Dashboard.
186
+ description (str): The description of the Dashboard.
187
+ settings (Dict): The settings of the Dashboard.
188
+ thumbnail (str): The thumbnail of the Dashboard.
189
+
190
+ Returns:
191
+ Dict: The updated Dashboard data.
192
+
193
+ Raises:
194
+ ValidationError: If the Dashboard data is invalid.
195
+
196
+ Example:
197
+ >>> from geobox import GeoboxClient
198
+ >>> from geobox.dashboard import Dashboard
199
+ >>> client = GeoboxClient()
200
+ >>> dashboard = Dashboard.get_dashboard(client, uuid="12345678-1234-5678-1234-567812345678")
201
+ >>> dashboard.update(display_name="New Display Name")
202
+ """
203
+ data = {
204
+ "name": kwargs.get('name'),
205
+ "display_name": kwargs.get('display_name'),
206
+ "description": kwargs.get('description'),
207
+ "settings": kwargs.get('settings'),
208
+ "thumbnail": kwargs.get('thumbnail')
209
+ }
210
+ return super()._update(self.endpoint, data)
211
+
212
+
213
+ def delete(self) -> None:
214
+ """
215
+ Delete the dashboard.
216
+
217
+ Returns:
218
+ None
219
+
220
+ Example:
221
+ >>> from geobox import GeoboxClient
222
+ >>> from geobox.dashboard import Dashboard
223
+ >>> client = GeoboxClient()
224
+ >>> dashboard = Dashboard.get_dashboard(client, uuid="12345678-1234-5678-1234-567812345678")
225
+ >>> dashboard.delete()
226
+ """
227
+ super().delete(self.endpoint)
228
+
229
+
230
+ @property
231
+ def thumbnail(self) -> str:
232
+ """
233
+ Get the thumbnail URL of the dashboard.
234
+
235
+ Returns:
236
+ str: The thumbnail of the dashboard.
237
+
238
+ Example:
239
+ >>> from geobox import GeoboxClient
240
+ >>> from geobox.dashboard import Dashboard
241
+ >>> client = GeoboxClient()
242
+ >>> dashboard = Dashboard.get_dashboard(client, uuid="12345678-1234-5678-1234-567812345678")
243
+ >>> dashboard.thumbnail
244
+ 'https://example.com/thumbnail.png'
245
+ """
246
+ endpoint = urljoin(self.api.base_url, f'{self.endpoint}thumbnail.png')
247
+ return endpoint
248
+
249
+
250
+ def share(self, users: List['User']) -> None:
251
+ """
252
+ Shares the Dashboard with specified users.
253
+
254
+ Args:
255
+ users (List[User]): The list of user objects to share the Dashboard with.
256
+
257
+ Returns:
258
+ None
259
+
260
+ Example:
261
+ >>> from geobox import GeoboxClient
262
+ >>> from geobox.dashboard import Dashboard
263
+ >>> client = GeoboxClient()
264
+ >>> dashboard = Dashboard.get_dashboard(client, uuid="12345678-1234-5678-1234-567812345678")
265
+ >>> users = client.search_users(search='John')
266
+ >>> dashboard.share(users=users)
267
+ """
268
+ super()._share(self.endpoint, users)
269
+
270
+
271
+ def unshare(self, users: List['User']) -> None:
272
+ """
273
+ Unshares the Dashboard with specified users.
274
+
275
+ Args:
276
+ users (List[User]): The list of user objects to unshare the Dashboard with.
277
+
278
+ Returns:
279
+ None
280
+
281
+ Example:
282
+ >>> from geobox import GeoboxClient
283
+ >>> from geobox.dashboard import Dashboard
284
+ >>> client = GeoboxClient()
285
+ >>> dashboard = Dashboard.get_dashboard(client, uuid="12345678-1234-5678-1234-567812345678")
286
+ >>> users = client.search_users(search='John')
287
+ >>> dashboard.unshare(users=users)
288
+ """
289
+ super()._unshare(self.endpoint, users)
290
+
291
+
292
+ def get_shared_users(self, search: str = None, skip: int = 0, limit: int = 10) -> List['User']:
293
+ """
294
+ Retrieves the list of users the dashboard is shared with.
295
+
296
+ Args:
297
+ search (str, optional): The search query.
298
+ skip (int, optional): The number of users to skip.
299
+ limit (int, optional): The maximum number of users to retrieve.
300
+
301
+ Returns:
302
+ List[User]: The list of shared users.
303
+
304
+ Example:
305
+ >>> from geobox import GeoboxClient
306
+ >>> from geobox.dashboard import Dashboard
307
+ >>> client = GeoboxClient()
308
+ >>> dashboard = Dashboard.get_dashboard(client, uuid="12345678-1234-5678-1234-567812345678")
309
+ >>> dashboard.get_shared_users(search='John', skip=0, limit=10)
310
+ """
311
+ params = {
312
+ 'search': search,
313
+ 'skip': skip,
314
+ 'limit': limit
315
+ }
316
+ return super()._get_shared_users(self.endpoint, params)