|
| 1 | +import warnings |
| 2 | + |
| 3 | +from ..model import UserOrganizationPreferences |
1 | 4 | from .base import Base
|
2 | 5 |
|
3 | 6 |
|
@@ -180,25 +183,68 @@ def organization_preference_get(self):
|
180 | 183 | """
|
181 | 184 | :return:
|
182 | 185 | """
|
183 |
| - update_preference = "/org/preferences" |
184 |
| - r = self.client.GET(update_preference) |
185 |
| - return r |
| 186 | + warnings.warn("Deprecated, please use `organization_preferences_get`", DeprecationWarning) |
| 187 | + return self.organization_preferences_get() |
186 | 188 |
|
187 | 189 | def organization_preference_update(self, theme="", home_dashboard_id=0, timezone="utc"):
|
188 | 190 | """
|
189 | 191 |
|
190 | 192 | :param theme:
|
191 | 193 | :param home_dashboard_id:
|
192 | 194 | :param timezone:
|
| 195 | + :return: |
| 196 | + """ |
| 197 | + warnings.warn("Deprecated, please use `organization_preferences_update`", DeprecationWarning) |
| 198 | + preferences = UserOrganizationPreferences(theme=theme, homeDashboardId=home_dashboard_id, timezone=timezone) |
| 199 | + return self.organization_preferences_update(preferences) |
| 200 | + |
| 201 | + def organization_preferences_get(self): |
| 202 | + """ |
| 203 | + Retrieve preferences of current organization. |
| 204 | +
|
193 | 205 | :return:
|
194 | 206 | """
|
195 | 207 | update_preference = "/org/preferences"
|
| 208 | + r = self.client.GET(update_preference) |
| 209 | + return r |
| 210 | + |
| 211 | + def organization_preferences_update(self, preferences: UserOrganizationPreferences): |
| 212 | + """ |
| 213 | + Update preferences of current organization as a whole. |
| 214 | +
|
| 215 | + From the `preferences` instance, only attributes with values `not None` will be submitted. |
| 216 | + However, Grafana will reset all undefined attributes to its internal defaults. |
| 217 | +
|
| 218 | + If you want to update specific preference attributes, without touching the others, |
| 219 | + please use the `organization_preferences_patch` method. |
| 220 | +
|
| 221 | + :param preferences: |
| 222 | + :return: |
| 223 | + """ |
| 224 | + update_preference = "/org/preferences" |
| 225 | + data = preferences.asdict(filter_none=True) |
| 226 | + |
196 | 227 | r = self.client.PUT(
|
197 | 228 | update_preference,
|
198 |
| - json={ |
199 |
| - "theme": theme, |
200 |
| - "homeDashboardId": home_dashboard_id, |
201 |
| - "timezone": timezone, |
202 |
| - }, |
| 229 | + json=data, |
| 230 | + ) |
| 231 | + return r |
| 232 | + |
| 233 | + def organization_preferences_patch(self, preferences: UserOrganizationPreferences): |
| 234 | + """ |
| 235 | + Update specific preferences of current organization. |
| 236 | +
|
| 237 | + From the `preferences` instance, only attributes with values `not None` will be submitted |
| 238 | + and updated. |
| 239 | +
|
| 240 | + :param preferences: |
| 241 | + :return: |
| 242 | + """ |
| 243 | + update_preference = "/org/preferences" |
| 244 | + data = preferences.asdict(filter_none=True) |
| 245 | + |
| 246 | + r = self.client.PATCH( |
| 247 | + update_preference, |
| 248 | + json=data, |
203 | 249 | )
|
204 | 250 | return r
|
0 commit comments