Skip to content

Commit

Permalink
Merge pull request #393 from hkad98/trivial
Browse files Browse the repository at this point in the history
TRIVIAL: fix workspace setting

Reviewed-by: Jan Soubusta
             https://github.com/jaceksan
  • Loading branch information
gdgate authored Oct 23, 2023
2 parents 7fc08f4 + 0551348 commit 7fb6acc
Show file tree
Hide file tree
Showing 9 changed files with 2,546 additions and 148 deletions.
3 changes: 2 additions & 1 deletion gooddata-sdk/gooddata_sdk/catalog/setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@

from gooddata_api_client.model.declarative_custom_application_setting import DeclarativeCustomApplicationSetting
from gooddata_api_client.model.declarative_setting import DeclarativeSetting
from gooddata_sdk.catalog.base import Base
from gooddata_sdk.catalog.base import Base, value_in_allowed


@attr.s(auto_attribs=True, kw_only=True)
class CatalogDeclarativeSetting(Base):
id: str
type: str = attr.field(validator=value_in_allowed)
content: Optional[Dict[str, Any]] = None

@staticmethod
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# (C) 2023 GoodData Corporation
from __future__ import annotations

from typing import Type, Union
import functools
from typing import Any, Dict, Type, Union

import attr

Expand All @@ -13,26 +14,29 @@
from gooddata_api_client.model.json_api_workspace_setting_post_optional_id_document import (
JsonApiWorkspaceSettingPostOptionalIdDocument,
)
from gooddata_sdk.catalog.entity import AttrCatalogEntity
from gooddata_sdk.catalog.base import Base, value_in_allowed
from gooddata_sdk.utils import safeget


@attr.s(auto_attribs=True, kw_only=True)
class CatalogWorkspaceSetting(AttrCatalogEntity):
class CatalogWorkspaceSetting(Base):
id: str = attr.field(default=None)

@staticmethod
def client_class() -> Type[JsonApiWorkspaceSettingOut]:
return JsonApiWorkspaceSettingOut

setting_type: str = attr.field(
validator=functools.partial(value_in_allowed, client_class=JsonApiOrganizationSettingInAttributes)
)
content: dict = attr.field(
repr=False,
default=attr.Factory(lambda self: safeget(self.json_api_entity.attributes, ["content"]), takes_self=True),
)

@staticmethod
def client_class() -> Type[JsonApiWorkspaceSettingOut]:
return JsonApiWorkspaceSettingOut

def _attributes(self) -> JsonApiOrganizationSettingInAttributes:
return JsonApiOrganizationSettingInAttributes(
content=self.content,
type=self.setting_type,
)

def to_api(
Expand All @@ -50,3 +54,11 @@ def to_api(
return JsonApiWorkspaceSettingInDocument(
data=JsonApiWorkspaceSettingIn(id=self.id, attributes=self._attributes())
)

@classmethod
def from_api(cls, entity: Dict[str, Any]) -> CatalogWorkspaceSetting:
return cls(
id=entity["id"],
setting_type=entity["attributes"]["type"],
content=entity["attributes"]["content"],
)
5 changes: 3 additions & 2 deletions gooddata-sdk/gooddata_sdk/catalog/workspace/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,10 +595,11 @@ def provision_workspace_with_locales(
self.delete_workspace_setting(new_workspace.id, "formatLocale")
# Create/update locale settings to target language
self.create_or_update_workspace_setting(
new_workspace.id, CatalogWorkspaceSetting(id="locale", content={"value": to_locale})
new_workspace.id, CatalogWorkspaceSetting(id="locale", content={"value": to_locale}, setting_type="LOCALE")
)
self.create_or_update_workspace_setting(
new_workspace.id, CatalogWorkspaceSetting(id="formatLocale", content={"value": to_locale})
new_workspace.id,
CatalogWorkspaceSetting(id="formatLocale", content={"value": to_locale}, setting_type="FORMAT_LOCALE"),
)

def translate_if_requested(
Expand Down
Loading

0 comments on commit 7fb6acc

Please sign in to comment.